[systemd-devel] [PATCH] analyze: Python 3 compatibility

Dave Reisner d at falconindy.com
Mon Jul 9 20:40:05 PDT 2012


On Thu, Jun 14, 2012 at 03:08:19PM -0700, Shawn Landden wrote:
> Plot verb doesn't currently work b/c Cairo bug sending to stdout in python 3.
> ---

After this patch, plot still doesn't seem to work with py3k, throwing a rather
useless backtrace:

Traceback (most recent call last):
  File "/usr/bin/systemd-analyze", line 309, in <module>
    verb.get(args[0], unknown_verb)()
  File "/usr/bin/systemd-analyze", line 277, in plot
    surface.finish()
TypeError: must be str, not bytes

>  src/analyze/systemd-analyze |   16 ++++++++--------
>  1 file changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/src/analyze/systemd-analyze b/src/analyze/systemd-analyze
> index 5d451c3..76eceee 100755
> --- a/src/analyze/systemd-analyze
> +++ b/src/analyze/systemd-analyze
> @@ -91,16 +91,16 @@ def time():
>          initrd_time, start_time, finish_time = acquire_start_time()
>  
>          if initrd_time > 0:
> -                print "Startup finished in %lums (kernel) + %lums (initramfs) + %lums (userspace) = %lums" % ( \
> +                sys.stdout.write("Startup finished in %lums (kernel) + %lums (initramfs) + %lums (userspace) = %lums\n" % ( \
>                          initrd_time/1000, \
>                          (start_time - initrd_time)/1000, \
>                          (finish_time - start_time)/1000, \
> -                        finish_time/1000)
> +                        finish_time/1000))
>          else:
> -                print "Startup finished in %lums (kernel) + %lums (userspace) = %lums" % ( \
> +                sys.stdout.write("Startup finished in %lums (kernel) + %lums (userspace) = %lums\n" % ( \
>                          start_time/1000, \
>                          (finish_time - start_time)/1000, \
> -                        finish_time/1000)
> +                        finish_time/1000))
>  
>  
>  def blame():
> @@ -161,7 +161,7 @@ def plot():
>          context.set_line_width(1)
>          context.set_source_rgb(0.7, 0.7, 0.7)
>  
> -        for x in range(0, finish_time/10000 + 100, 100):
> +        for x in range(0, int(finish_time/10000) + 100, 100):
>                  context.move_to(x, 0)
>                  context.line_to(x, height-border*2)
>  
> @@ -185,7 +185,7 @@ def plot():
>          banner = "{} {} ({} {}) {}".format(osrel, *(os.uname()[1:5]))
>          draw_text(context, 0, -15, banner, hcenter = 0, vcenter = 1)
>  
> -        for x in range(0, finish_time/10000 + 100, 100):
> +        for x in range(0, int(finish_time/10000) + 100, 100):
>                  draw_text(context, x, -5, "%lus" % (x/100), vcenter = 0, hcenter = 0)
>  
>          y = 0
> @@ -285,8 +285,8 @@ bus = dbus.SystemBus()
>  
>  try:
>          opts, args = getopt.gnu_getopt(sys.argv[1:], "h", ["help", "user"])
> -except getopt.GetoptError, err:
> -        print str(err)
> +except getopt.GetoptError as err:
> +        sys.stdout.write(str(err) + "\n")
>          usage()
>          sys.exit(2)
>  for o, a in opts:
> -- 
> 1.7.9.5
> 
> _______________________________________________
> systemd-devel mailing list
> systemd-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/systemd-devel


More information about the systemd-devel mailing list