Bug 1382697 - Minor nsinstall.py code cleanup; r=glandium draft
authorGregory Szorc <gps@mozilla.com>
Thu, 20 Jul 2017 16:03:24 -0700
changeset 613681 482975a0142fb8ac06f54a4aa8d48f0dc4ea76d8
parent 613680 008f7317e2d0d9718fe8beb6fbb5c4ee57f0ab99
child 613682 8c3e68e7b356cd9cac3f1852d319e7d5458f1f3d
push id69832
push usergszorc@mozilla.com
push dateSat, 22 Jul 2017 06:27:51 +0000
reviewersglandium
bugs1382697
milestone56.0a1
Bug 1382697 - Minor nsinstall.py code cleanup; r=glandium * Removed an unused import * Removed redundant os.path import * Reorder imports * Delete some argument parsing code to screen for arguments not accepted by the Python version (the option parser will error on unknown arguments anyway) * Remove some parens around a tuple assignment * Avoid bare except MozReview-Commit-ID: HbDXXqiA7dj
config/nsinstall.py
--- a/config/nsinstall.py
+++ b/config/nsinstall.py
@@ -5,23 +5,23 @@
 # This is a partial python port of nsinstall.
 # It's intended to be used when there's no natively compile nsinstall
 # available, and doesn't intend to be fully equivalent.
 # Its major use is for l10n repackaging on systems that don't have
 # a full build environment set up.
 # The basic limitation is, it doesn't even try to link and ignores
 # all related options.
 from __future__ import print_function
+
 from optparse import OptionParser
-import mozfile
 import os
-import os.path
 import sys
 import shutil
-import stat
+
+import mozfile
 
 
 def _nsinstall_internal(argv):
     usage = "usage: %prog [options] arg1 [arg2 ...] target-directory"
     p = OptionParser(usage=usage)
 
     p.add_option('-D', action="store_true",
                  help="Create a single directory only")
@@ -33,36 +33,23 @@ def _nsinstall_internal(argv):
                  help="Create directories in target")
     p.add_option('-R', action="store_true",
                  help="Use relative symbolic links (ignored)")
     p.add_option('-L', action="store", metavar="linkprefix",
                  help="Link prefix (ignored)")
     p.add_option('-X', action="append", metavar="file",
                  help="Ignore a file when installing a directory recursively.")
 
-    # The remaining arguments are not used in our tree, thus they're not
-    # implented.
-    def BadArg(option, opt, value, parser):
-        parser.error('option not supported: {0}'.format(opt))
-
-    p.add_option('-C', action="callback", metavar="CWD",
-                 callback=BadArg,
-                 help="NOT SUPPORTED")
-    p.add_option('-o', action="callback", callback=BadArg,
-                 help="Set owner (NOT SUPPORTED)", metavar="owner")
-    p.add_option('-g', action="callback", callback=BadArg,
-                 help="Set group (NOT SUPPORTED)", metavar="group")
-
-    (options, args) = p.parse_args(argv)
+    options, args = p.parse_args(argv)
 
     if options.m:
         # mode is specified
         try:
             options.m = int(options.m, 8)
-        except:
+        except ValueError:
             sys.stderr.write('nsinstall: {0} is not a valid mode\n'
                              .format(options.m))
             return 1
 
     # just create one directory?
     def maybe_create_dir(dir, mode, try_again):
         dir = os.path.abspath(dir)
         if os.path.exists(dir):