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

Shawn Landden shawnlandden at gmail.com
Thu Jun 14 15:08:19 PDT 2012


Plot verb doesn't currently work b/c Cairo bug sending to stdout in python 3.
---
 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



More information about the systemd-devel mailing list