Bug 1559975 - fix python2 and python3 linter errors for client.py draft
authorpulselistener
Fri, 02 Aug 2019 23:52:46 +0000
changeset 2193678 d6122c5e5c9f735abb00d7c4821820d7812a6497
parent 2193677 a6a3e33069b487079a8d02dc60bc11ecdf859c65
child 2193679 daf31b5d62644f573795ceb585e89310f8ff4229
push id400058
push userreviewbot
push dateFri, 02 Aug 2019 23:53:25 +0000
treeherdertry@daf31b5d6264 [default view] [failures only]
bugs1559975
milestone70.0a1
Bug 1559975 - fix python2 and python3 linter errors for client.py Differential Revision: https://phabricator.services.mozilla.com/D40523 Differential Diff: PHID-DIFF-6jjgxvphqxiv32qgq2b4
client.py
tools/lint/py2.yml
tools/lint/py3.yml
--- a/client.py
+++ b/client.py
@@ -1,13 +1,14 @@
 #!/usr/bin/python
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
+from __future__ import absolute_import, print_function
 
 LIBFFI_DIRS = (('js/ctypes/libffi', 'libffi'),)
 HG_EXCLUSIONS = ['.hg', '.hgignore', '.hgtags']
 
 CVSROOT_LIBFFI = ':pserver:anoncvs@sources.redhat.com:/cvs/libffi'
 
 import os
 import sys
@@ -17,17 +18,17 @@ import glob
 from optparse import OptionParser
 from subprocess import check_call
 
 topsrcdir = os.path.dirname(__file__)
 if topsrcdir == '':
     topsrcdir = '.'
 
 def check_call_noisy(cmd, *args, **kwargs):
-    print "Executing command:", cmd
+    print("Executing command:", cmd)
     check_call(cmd, *args, **kwargs)
 
 def do_hg_pull(dir, repository, hg):
     fulldir = os.path.join(topsrcdir, dir)
     # clone if the dir doesn't exist, pull if it does
     if not os.path.exists(fulldir):
         check_call_noisy([hg, 'clone', repository, fulldir])
     else:
@@ -62,90 +63,91 @@ def do_cvs_export(modules, tag, cvsroot,
     modules is a list of directories to check out and the corresponding
     cvs module, e.g. (('js/ctypes/libffi', 'libffi'),)
     """
     for module_tuple in modules:
         module = module_tuple[0]
         cvs_module = module_tuple[1]
         fullpath = os.path.join(topsrcdir, module)
         if os.path.exists(fullpath):
-            print "Removing '%s'" % fullpath
+            print("Removing '%s'" % fullpath)
             shutil.rmtree(fullpath)
 
         (parent, leaf) = os.path.split(module)
-        print "CVS export begin: " + datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S UTC")
+        print("CVS export begin: " + datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S UTC"))
         check_call_noisy([cvs, '-d', cvsroot,
                           'export', '-r', tag, '-d', leaf, cvs_module],
                          cwd=os.path.join(topsrcdir, parent))
-        print "CVS export end: " + datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S UTC")
+        print("CVS export end: " + datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S UTC"))
 
 def toggle_trailing_blank_line(depname):
   """If the trailing line is empty, then we'll delete it.
   Otherwise we'll add a blank line."""
   lines = open(depname, "r").readlines()
   if not lines:
-      print >>sys.stderr, "unexpected short file"
+      sys.stderr.write("unexpected short file")
       return
 
   if not lines[-1].strip():
       # trailing line is blank, removing it
       open(depname, "wb").writelines(lines[:-1])
   else:
       # adding blank line
       open(depname, "ab").write("\n")
 
 def get_trailing_blank_line_state(depname):
   lines = open(depname, "r").readlines()
   if not lines:
-      print >>sys.stderr, "unexpected short file"
+      sys.stderr.write("unexpected short file")
       return "no blank line"
 
   if not lines[-1].strip():
       return "has blank line"
   else:
       return "no blank line"
 
 def update_nspr_or_nss(tag, depfile, destination, hgpath):
   destination = destination.rstrip('/')
   permanent_patch_dir = destination + '/patches'
   temporary_patch_dir = destination + '.patches'
   if os.path.exists(temporary_patch_dir):
-    print "please clean up leftover directory " + temporary_patch_dir
+    print("please clean up leftover directory " + temporary_patch_dir)
     sys.exit(2)
   warn_if_patch_exists(permanent_patch_dir)
   # protect patch directory from being removed by do_hg_replace
   if os.path.exists(permanent_patch_dir):
     shutil.move(permanent_patch_dir, temporary_patch_dir)
   # now update the destination
-  print "reverting to HG version of %s to get its blank line state" % depfile
+  print("reverting to HG version of %s to get its blank line state" % depfile)
   check_call_noisy([options.hg, 'revert', depfile])
   old_state = get_trailing_blank_line_state(depfile)
-  print "old state of %s is: %s" % (depfile, old_state)
+  print("old state of %s is: %s" % (depfile, old_state))
   do_hg_replace(destination, hgpath, tag, HG_EXCLUSIONS, options.hg)
   new_state = get_trailing_blank_line_state(depfile)
-  print "new state of %s is: %s" % (depfile, new_state)
+  print("new state of %s is: %s" % (depfile, new_state))
   if old_state == new_state:
-    print "toggling blank line in: ", depfile
+    print("toggling blank line in: ", depfile)
     toggle_trailing_blank_line(depfile)
   tag_file = destination + "/TAG-INFO"
-  print >>file(tag_file, "w"), tag
+  with open(tag_file, 'w') as f:
+    f.write(tag)
   # move patch directory back to a subdirectory
   if os.path.exists(temporary_patch_dir):
     shutil.move(temporary_patch_dir, permanent_patch_dir)
 
 def warn_if_patch_exists(path):
   # If the given patch directory exists and contains at least one file,
   # then print warning and wait for the user to acknowledge.
   if os.path.isdir(path) and os.listdir(path):
-    print "========================================"
-    print "WARNING: At least one patch file exists"
-    print "in directory: " + path
-    print "You must manually re-apply all patches"
-    print "after this script has completed!"
-    print "========================================"
+    print("========================================")
+    print("WARNING: At least one patch file exists")
+    print("in directory: " + path)
+    print("You must manually re-apply all patches")
+    print("after this script has completed!")
+    print("========================================")
     raw_input("Press Enter to continue...")
     return
 
 o = OptionParser(usage="client.py [options] update_nspr tagname | update_nss tagname | update_libffi tagname")
 o.add_option("--skip-mozilla", dest="skip_mozilla",
              action="store_true", default=False,
              help="Obsolete")
 
--- a/tools/lint/py2.yml
+++ b/tools/lint/py2.yml
@@ -1,15 +1,14 @@
 ---
 py2:
     description: Python 2 compatibility check
     include: ['.']
     exclude:
         - build
-        - client.py
         - dom
         - editor
         - gfx
         - ipc
         - js/src
         - js/xpconnect
         - layout
         - media
--- a/tools/lint/py3.yml
+++ b/tools/lint/py3.yml
@@ -1,16 +1,15 @@
 ---
 py3:
     description: Python 3 compatibility check
     include: ['.']
     exclude:
         - browser/app
         - build
-        - client.py
         - dom/bindings
         - dom/canvas/test
         - dom/media/test
         - gfx
         - ipc/ipdl
         - layout/reftests
         - layout/style
         - layout/tools/reftest