Commits

Jason R. Coombs  committed bbd7fd9

Extract argument parsing as a separate function

  • Participants
  • Parent commits 8dbd992

Comments (0)

Files changed (1)

File distribute_setup.py

 import tempfile
 import tarfile
 import optparse
+
 from distutils import log
 
 try:
                 self._dbg(1, "tarfile: %s" % e)
 
 
-def _build_install_args(user_install):
+def _build_install_args(options):
+    """
+    Build the arguments to 'python setup.py install' on the distribute package
+    """
     install_args = []
-    if user_install:
+    if options.user_install:
         if sys.version_info < (2, 6):
             log.warn("--user requires Python 2.6 or later")
             raise SystemExit(1)
-        else:
-            install_args.append('--user')
+        install_args.append('--user')
     return install_args
 
-
-def main(version=DEFAULT_VERSION):
-    """Install or upgrade setuptools and EasyInstall"""
+def _parse_args():
+    """
+    Parse the command line for options
+    """
     parser = optparse.OptionParser()
     parser.add_option(
         '--user', dest='user_install', action='store_true', default=False,
         default=DEFAULT_URL,
         help='alternative URL from where to download the distribute package')
     options, args = parser.parse_args()
+    # positional arguments are ignored
+    return options
+
+def main(version=DEFAULT_VERSION):
+    """Install or upgrade setuptools and EasyInstall"""
+    options = _parse_args()
     tarball = download_setuptools(download_base=options.download_base)
-    _install(tarball, _build_install_args(options.user_install))
-
+    _install(tarball, _build_install_args(options))
 
 if __name__ == '__main__':
     main()