Bug 1468273 - Fix flake8/pep8 issue by hand in intl/ draft
authorSylvestre Ledru <sledru@mozilla.com>
Sun, 10 Jun 2018 14:25:47 +0200
changeset 806820 5bb2207a3863b4e17a72e396cfdd2cd55faeddc5
parent 806819 655bdabff7fda74b39875daff953573fc6c34043
child 806821 bcd9878b8e6208ff9453d710c1b5484e06bd39ba
push id112964
push usersledru@mozilla.com
push dateTue, 12 Jun 2018 00:58:13 +0000
bugs1468273
milestone62.0a1
Bug 1468273 - Fix flake8/pep8 issue by hand in intl/ MozReview-Commit-ID: IDqjd7nBRS
intl/icu/source/tools/icu-svnprops-check.py
intl/icu_sources_data.py
intl/locale/props2arrays.py
--- a/intl/icu/source/tools/icu-svnprops-check.py
+++ b/intl/icu/source/tools/icu-svnprops-check.py
@@ -43,17 +43,17 @@ file_types = list()
 def parse_auto_props():
     aprops = svn_auto_props.splitlines()
     for propline in aprops:
         if re.match("\s*(#.*)?$", propline):         # Match comment and blank lines
             continue
         if re.match("\s*\[auto-props\]", propline):  # Match the [auto-props] line.
             continue
         if not re.match("\s*[^\s]+\s*=", propline):  # minimal syntax check for <file-type> =
-            print "Bad line from autoprops definitions: " + propline
+            print("Bad line from autoprops definitions: " + propline)
             continue
         file_type, string_proplist = propline.split("=", 1)
 
         # transform the file type expression from autoprops into a normal regular expression.
         #  e.g.  "*.cpp"  ==>  ".*\.cpp$"
         file_type = file_type.strip()
         file_type = file_type.replace(".", "\.")
         file_type = file_type.replace("*", ".*")
@@ -96,17 +96,17 @@ def runCommand(cmd):
         sys.exit(exit_status)
     return output_text
 
 
 svn_auto_props = runCommand("svn propget svn:auto-props http://source.icu-project.org/repos/icu")
 
 
 def usage():
-    print "usage: " + sys.argv[0] + " [-f | --fix] [-h | --help]"
+    print("usage: " + sys.argv[0] + " [-f | --fix] [-h | --help]")
 
 
 #
 #  UTF-8 file check.   For text files with svn:mime-type=text/anything, check the specified charset
 #    file_name:        name of a text file.
 #    base_mime_type:   svn:mime-type property from the auto-props settings for this file type.
 #    actual_mime_type: existing svn:mime-type property value for the file.
 #    return:           The correct svn:mime-type property value,
@@ -119,75 +119,78 @@ def check_utf8(file_name, base_mime_type
     f.close()
     file_is_utf8 = True
     try:
         bytes.decode("UTF-8")
     except UnicodeDecodeError:
         file_is_utf8 = False
 
     if not file_is_utf8 and actual_mime_type.find("utf-8") >= 0:
-        print "Error: %s is not valid utf-8, but has a utf-8 mime type." % file_name
+        print("Error: %s is not valid utf-8, but has a utf-8 mime type." % file_name)
         return actual_mime_type
 
-    if file_is_utf8 and actual_mime_type.find("charset") >= 0 and actual_mime_type.find("utf-8") < 0:
-        print "Warning: %s is valid utf-8, but has a mime-type of %s." % (
-            file_name, actual_mime_type)
+    if (file_is_utf8 and actual_mime_type.find("charset") >= 0 and
+        actual_mime_type.find("utf-8") < 0):
+        print("Warning: %s is valid utf-8, but has a mime-type of %s." % (
+            file_name, actual_mime_type))
 
     if ord(bytes[0]) == 0xef:
         if not file_name.endswith(".txt"):
-            print "Warning: file %s contains a UTF-8 BOM: " % file_name
+            print("Warning: file %s contains a UTF-8 BOM: " % file_name)
 
     # If the file already has a charset in its mime-type, don't make any change.
 
     if actual_mime_type.find("charset=") >= 0:
         return actual_mime_type
 
     return base_mime_type
 
 
 def main(argv):
     fix_problems = False
     try:
         opts, args = getopt.getopt(argv, "fh", ("fix", "help"))
     except getopt.GetoptError:
-        print "unrecognized option: " + argv[0]
+        print("unrecognized option: " + argv[0])
         usage()
         sys.exit(2)
     for opt, arg in opts:
         if opt in ("-h", "--help"):
             usage()
             sys.exit()
         if opt in ("-f", "--fix"):
             fix_problems = True
     if args:
-        print "unexpected command line argument"
+        print("unexpected command line argument")
         usage()
         sys.exit()
 
     parse_auto_props()
     output = runCommand("svn ls -R ")
     file_list = output.splitlines()
 
     for f in file_list:
         if os.path.isdir(f):
             # print "Skipping dir " + f
             continue
         if not os.path.isfile(f):
-            print "Repository file not in working copy: " + f
+            print("Repository file not in working copy: " + f)
             continue
 
         for file_pattern, props in file_types:
             if re.match(file_pattern, f):
                 # print "doing " + f
                 for propname, propval in props:
                     actual_propval = runCommand("svn propget --strict " + propname + " " + f)
-                    #print propname + ": " + actual_propval
+                    # print propname + ": " + actual_propval
                     if propname == "svn:mime-type" and propval.find("text/") == 0:
-                        # check for UTF-8 text files, should have svn:mime-type=text/something; charset=utf8
+                        # check for UTF-8 text files, should have
+                        # svn:mime-type=text/something; charset=utf8
                         propval = check_utf8(f, propval, actual_propval)
-                    if not (propval == actual_propval or (propval == "" and actual_propval == "*")):
-                        print "svn propset %s '%s' %s" % (propname, propval, f)
+                    if (not (propval == actual_propval or
+                             (propval == "" and actual_propval == "*"))):
+                        print("svn propset %s '%s' %s" % (propname, propval, f))
                         if fix_problems:
                             os.system("svn propset %s '%s' %s" % (propname, propval, f))
 
 
 if __name__ == "__main__":
     main(sys.argv[1:])
--- a/intl/icu_sources_data.py
+++ b/intl/icu_sources_data.py
@@ -146,17 +146,17 @@ def update_data_file(topsrcdir):
         print('Error: no ICU data in ICU objdir', file=sys.stderr)
         return False
     if os.path.basename(old_data_file) != os.path.basename(new_data_file):
         # Data file name has the major version number embedded.
         os.unlink(old_data_file)
     shutil.copy(new_data_file, tree_data_path)
     try:
         shutil.rmtree(objdir)
-    except:
+    except Exception:
         print('Warning: failed to remove %s' % objdir, file=sys.stderr)
     return True
 
 
 def main():
     if len(sys.argv) != 2:
         print('Usage: icu_sources_data.py <mozilla topsrcdir>',
               file=sys.stderr)
--- a/intl/locale/props2arrays.py
+++ b/intl/locale/props2arrays.py
@@ -1,14 +1,12 @@
 # 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/.
 
-import sys
-
 
 def main(header, propFile):
     mappings = {}
 
     with open(propFile, 'r') as f:
         for line in f:
             line = line.strip()
             if not line.startswith('#'):