Anonymous avatar Anonymous committed 90dbe75

Cleanup: use module optparse instead of getopt

git-svn-id: file:///tmp/pyinstaller-svn/trunk@1638 6d373633-9ee7-468a-befa-14b9e37bb2df

Comments (0)

Files changed (1)

 
 import os, sys, win32api, Makespec
 
+import optparse
+
 tmplt = '''\
 import sys
 import os
                             "COM Object")
 '''
 
-def create(scripts, debug, verbosity, workdir, ascii=0):
+def create(scripts, debug, verbose, workdir, ascii=0):
     infos = []  # (path, module, klasses)
     for script in scripts:
         infos.append(analscriptname(script))
     outf = open(outfnm, 'w')
     klassspecs = []
     modimports = []
-    flags = 'debug=%s, quiet=%s' % (debug, verbosity==0)
+    flags = 'debug=%s, quiet=%s' % (debug, not verbose)
     paths = []
     for path, module, klasses in infos:
         if path:
             return 0
     return 1
 
-usage = """\
-Usage: python %s [options] <scriptname>.py [<scriptname>.py ...]
- --debug -> use debug console build and register COM servers with debug
- --verbose -> use verbose flag in COM server registration
- --out dir -> generate script and spec file in dir
-
-The next step is to run Build.py against the generated spec file.
-See doc/Tutorial.html for details.
-"""
+epilog = ("The next step is to run Build.py against the generated "
+          "spec file. See doc/Tutorial.html for details.")
 
 if __name__ == '__main__':
-    #scripts, debug, verbosity, workdir
-    debug = verbosity = ascii = 0
-    workdir = '.'
-    import getopt
-    opts, args = getopt.getopt(sys.argv[1:], '', ['debug', 'verbose', 'ascii', 'out='])
-    for opt, val in opts:
-        if opt == '--debug':
-            debug = 1
-        elif opt == '--verbose':
-            verbosity = 1
-        elif opt == '--out':
-            workdir = val
-        elif opt == '--ascii':
-            ascii = 1
-        else:
-            print usage % sys.argv[0]
-            sys.exit(1)
+    parser = optparse.OptionParser(
+        usage='python %s [options] <scriptname>.py [<scriptname>.py ...]',
+        epilog="The next step is to run Build.py against the generated"
+               "spec file. See doc/Tutorial.html for details."
+        )
+    parser.add_option('--debug', default=False, action='store_true',
+                      help='use debug console build and register COM servers with debug')
+    parser.add_option('--verbose', default=False, action='store_true',
+                      help='use verbose flag in COM server registration')
+    parser.add_option('--out', default='.',
+                      metavar='DIR',
+                      dest='workdir',
+                      help='generate script and spec file in dir')
+    parser.add_option('--ascii', default=False, action='store_true')
+
+    opts, args = parser.parse_args()
     if not args:
-        print usage % sys.argv[0]
-    else:
-        try:
-            create(args, debug, verbosity, workdir, ascii)
-        except KeyboardInterrupt:
-            raise SystemExit("Aborted by user request.")
+        parser.error('Requires at least one script filename')
+
+    try:
+        print
+        print epilog
+    except KeyboardInterrupt:
+        raise SystemExit("Aborted by user request.")
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.