Commits

Pedro Romano committed 1c01b26 Draft

Use 'optparse' module to parse command line arguments.

Comments (0)

Files changed (1)

distribute_setup.py

 import fnmatch
 import tempfile
 import tarfile
+import optparse
 from distutils import log
 
 try:
                 self._dbg(1, "tarfile: %s" % e)
 
 
-def _build_install_args(argv):
+def _build_install_args(user_install):
     install_args = []
-    user_install = '--user' in argv
-    if user_install and sys.version_info < (2, 6):
-        log.warn("--user requires Python 2.6 or later")
-        raise SystemExit(1)
     if user_install:
-        install_args.append('--user')
+        if sys.version_info < (2, 6):
+            log.warn("--user requires Python 2.6 or later")
+            raise SystemExit(1)
+        else:
+            install_args.append('--user')
     return install_args
 
 
-def main(argv, version=DEFAULT_VERSION):
+def main(version=DEFAULT_VERSION):
     """Install or upgrade setuptools and EasyInstall"""
+    parser = optparse.OptionParser()
+    parser.add_option(
+        '--user', dest='user_install', action='store_true', default=False,
+        help='install in user site package (requires Python 2.6 or later)')
+    options, args = parser.parse_args()
     tarball = download_setuptools()
-    _install(tarball, _build_install_args(argv))
+    _install(tarball, _build_install_args(options.user_install))
 
 
 if __name__ == '__main__':
-    main(sys.argv[1:])
+    main()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.