[PATCH] pwclient: basic python3 support

Brian Norris computersforpeace at gmail.com
Thu May 21 17:06:41 AEST 2015


Hi Mike,

On Wed, May 06, 2015 at 12:15:35AM -0400, Mike Frysinger wrote:
> From: Mike Frysinger <vapier at chromium.org>
> 
> This fixes a few random issues to make the script work at least somewhat
> under python 3:
> - set the default encoding to utf-8
> - handle xmlrpclib/xmlrpc.client module renames
> - handle ConfigParser/configparser module renames
> - add a unicode() stub for python 3
> - fix old style class definition w/Filter
> - use list comprehension instead of map()
> - drop the unused version= keyword w/argparse

This last point is duplicated in my patch that I wrote a few months ago
but just submitted:

http://patchwork.ozlabs.org/patch/474810/

but anyway, after merging these and testing your changes on my system I
still see some major problems. I don't know much about Python 3, but you
haven't converted 'print' statements to 'print()' functions, nor have
you handled the one 'except <exception>, <var>:' statement.

> 
> The code still runs under python 2 the same as before, and now works for
> the most part under python 3 -- the handling of encoded content still needs
> some work, but that'll require more surgery, and is best left to another
> commit after this.
> 
> Signed-off-by: Mike Frysinger <vapier at chromium.org>

Reviewed-by: Brian Norris <computersforpeace at gmail.com>

With the following extra patch, this works OK for a few different
commands.

Signed-off-by: Brian Norris <computersforpeace at gmail.com>
---
 apps/patchwork/bin/pwclient | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/apps/patchwork/bin/pwclient b/apps/patchwork/bin/pwclient
index faef0dd06354..37cbb8343325 100755
--- a/apps/patchwork/bin/pwclient
+++ b/apps/patchwork/bin/pwclient
@@ -186,9 +186,9 @@ def action_list(rpc, filter, submitter_str, delegate_str, format_str=None):
         else:
             for id in ids:
                 person = rpc.person_get(id)
-                print "Patches submitted by %s <%s>:" % \
+                print("Patches submitted by %s <%s>:" % \
                         (unicode(person['name']).encode("utf-8"), \
-                         unicode(person['email']).encode("utf-8"))
+                         unicode(person['email']).encode("utf-8")))
                 f = filter
                 f.add("submitter_id", id)
                 patches = rpc.patch_list(f.d)
@@ -203,8 +203,8 @@ def action_list(rpc, filter, submitter_str, delegate_str, format_str=None):
         else:
             for id in ids:
                 person = rpc.person_get(id)
-                print "Patches delegated to %s <%s>:" % \
-                        (person['name'], person['email'])
+                print("Patches delegated to %s <%s>:" % \
+                        (person['name'], person['email']))
                 f = filter
                 f.add("delegate_id", id)
                 patches = rpc.patch_list(f.d)
@@ -235,7 +235,7 @@ def action_info(rpc, patch_id):
     s = "Information for patch id %d" % (patch_id)
     print(s)
     print('-' * len(s))
-    for key, value in sorted(patch.iteritems()):
+    for key, value in sorted(patch.items()):
         print("- %- 14s: %s" % (key, unicode(value).encode("utf-8")))
 
 def action_get(rpc, patch_id):
@@ -261,7 +261,7 @@ def action_get(rpc, patch_id):
     try:
         f.write(unicode(s).encode("utf-8"))
         f.close()
-        print "Saved patch to %s" % fname
+        print("Saved patch to %s" % fname)
     except:
         sys.stderr.write("Failed to write to %s\n" % fname)
         sys.exit(1)
@@ -274,13 +274,13 @@ def action_apply(rpc, patch_id, apply_cmd=None):
         sys.exit(1)
 
     if apply_cmd is None:
-      print "Applying patch #%d to current directory" % patch_id
+      print("Applying patch #%d to current directory" % patch_id)
       apply_cmd = ['patch', '-p1']
     else:
-      print "Applying patch #%d using %s" % (
-          patch_id, repr(' '.join(apply_cmd)))
+      print("Applying patch #%d using %s" % (
+          patch_id, repr(' '.join(apply_cmd))))
 
-    print "Description: %s" % patch['name']
+    print("Description: %s" % patch['name'])
     s = rpc.patch_get_mbox(patch_id)
     if len(s) > 0:
         proc = subprocess.Popen(apply_cmd, stdin = subprocess.PIPE)
@@ -315,7 +315,7 @@ def action_update_patch(rpc, patch_id, state = None, archived = None, commit = N
     success = False
     try:
         success = rpc.patch_set(patch_id, params)
-    except xmlrpclib.Fault, f:
+    except xmlrpclib.Fault as f:
         sys.stderr.write("Error updating patch: %s\n" % f.faultString)
 
     if not success:
@@ -672,7 +672,7 @@ def main():
             for patch_id in non_empty(h, patch_ids):
                 s = rpc.patch_get_mbox(patch_id)
                 if len(s) > 0:
-                    print unicode(s).encode("utf-8")
+                    print(unicode(s).encode("utf-8"))
 
     elif action == 'info':
         for patch_id in non_empty(h, patch_ids):
-- 
2.4.1



More information about the Patchwork mailing list