diff mbox

[2/3] pwclient: use print_function for better py3 compatibility

Message ID 1445030131-24566-2-git-send-email-vapier@gentoo.org
State Accepted
Headers show

Commit Message

Mike Frysinger Oct. 16, 2015, 9:15 p.m. UTC
From: Mike Frysinger <vapier@chromium.org>

The script already tries to use print like a function in many places but
is really passing a parenthesized string.  Import the print_function from
the future module so that it actually works as intended.

We also need to fix up a few latent print statements to make it work.

Signed-off-by: Mike Frysinger <vapier@chromium.org>
---
 patchwork/bin/pwclient | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

Comments

Stephen Finucane Oct. 16, 2015, 10:15 p.m. UTC | #1
> From: Mike Frysinger <vapier@chromium.org>

> 

> The script already tries to use print like a function in many places but

> is really passing a parenthesized string.  Import the print_function from

> the future module so that it actually works as intended.

> 

> We also need to fix up a few latent print statements to make it work.

> 

> Signed-off-by: Mike Frysinger <vapier@chromium.org>


Lovely work.

Reviewed-by: Stephen Finucane <stephen.finucane@intel.com>
Stephen Finucane Oct. 16, 2015, 10:24 p.m. UTC | #2
> > From: Mike Frysinger <vapier@chromium.org>

> >

> > The script already tries to use print like a function in many places but

> > is really passing a parenthesized string.  Import the print_function from

> > the future module so that it actually works as intended.

> >

> > We also need to fix up a few latent print statements to make it work.

> >

> > Signed-off-by: Mike Frysinger <vapier@chromium.org>

> 

> Lovely work.

> 

> Reviewed-by: Stephen Finucane <stephen.finucane@intel.com>


Merged.
Brian Norris Oct. 16, 2015, 10:38 p.m. UTC | #3
On Fri, Oct 16, 2015 at 05:15:30PM -0400, Mike Frysinger wrote:
> From: Mike Frysinger <vapier@chromium.org>
> 
> The script already tries to use print like a function in many places but
> is really passing a parenthesized string.  Import the print_function from
> the future module so that it actually works as intended.
> 
> We also need to fix up a few latent print statements to make it work.
> 
> Signed-off-by: Mike Frysinger <vapier@chromium.org>

I've been running with a patch very similar to this for a while.

Acked-by: Brian Norris <computersforpeace@gmail.com>

Though a trivial comment below...

> ---
>  patchwork/bin/pwclient | 26 ++++++++++++++------------
>  1 file changed, 14 insertions(+), 12 deletions(-)
> 
> diff --git a/patchwork/bin/pwclient b/patchwork/bin/pwclient
> index 46d11fb..d096f83 100755
> --- a/patchwork/bin/pwclient
> +++ b/patchwork/bin/pwclient
> @@ -19,6 +19,8 @@
>  # along with Patchwork; if not, write to the Free Software
>  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
>  
> +from __future__ import print_function
> +
>  import os
>  import sys
>  import xmlrpclib
> @@ -170,9 +172,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>:" % \
> -                        (unicode(person['name']).encode("utf-8"), \
> -                         unicode(person['email']).encode("utf-8"))
> +                print('Patches submitted by %s <%s>:' %
> +                      (unicode(person['name']).encode('utf-8'),
> +                       unicode(person['email']).encode('utf-8')))
>                  f = filter
>                  f.add("submitter_id", id)
>                  patches = rpc.patch_list(f.d)
> @@ -187,8 +189,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)
> @@ -245,7 +247,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)
> @@ -258,13 +260,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)
> @@ -299,7 +301,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:

^^^ this change is not documented in the commit message. Not that it
really matters much.

>          sys.stderr.write("Error updating patch: %s\n" % f.faultString)
>  
>      if not success:
> @@ -702,7 +704,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):

Brian
Mike Frysinger Oct. 16, 2015, 10:49 p.m. UTC | #4
On 16 Oct 2015 15:38, Brian Norris wrote:
> On Fri, Oct 16, 2015 at 05:15:30PM -0400, Mike Frysinger wrote:
> > -    except xmlrpclib.Fault, f:
> > +    except xmlrpclib.Fault as f:
> 
> ^^^ this change is not documented in the commit message. Not that it
> really matters much.

this was supposed to be in the other commit:
	pwclient: basic python3 support

i split out the other one, but i guess i missed extracting this one
-mike
diff mbox

Patch

diff --git a/patchwork/bin/pwclient b/patchwork/bin/pwclient
index 46d11fb..d096f83 100755
--- a/patchwork/bin/pwclient
+++ b/patchwork/bin/pwclient
@@ -19,6 +19,8 @@ 
 # along with Patchwork; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
+from __future__ import print_function
+
 import os
 import sys
 import xmlrpclib
@@ -170,9 +172,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>:" % \
-                        (unicode(person['name']).encode("utf-8"), \
-                         unicode(person['email']).encode("utf-8"))
+                print('Patches submitted by %s <%s>:' %
+                      (unicode(person['name']).encode('utf-8'),
+                       unicode(person['email']).encode('utf-8')))
                 f = filter
                 f.add("submitter_id", id)
                 patches = rpc.patch_list(f.d)
@@ -187,8 +189,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)
@@ -245,7 +247,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)
@@ -258,13 +260,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)
@@ -299,7 +301,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:
@@ -702,7 +704,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):