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
--- 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):