Horst Gutmann avatar Horst Gutmann committed ee8c872

Added option parsing via optparse to pep381run

Comments (0)

Files changed (1)

 #!/usr/bin/env python
-import sys, os, shutil
+import sys, os, shutil, optparse
 import pep381client
 
-quiet = False
-if '-q' in sys.argv:
-    sys.argv.remove('-q')
-    quiet = True
+opts = optparse.OptionParser(usage="Usage: pep381run [OPTIONS] <targetdir>")
+opts.add_option("-q", "--quiet", dest="quiet", action="store_true", default=False,
+        help="Don't print status information")
+options, args = opts.parse_args()
 
-if len(sys.argv) != 2:
-    print "Usage: pep381run [-q] <targetdir>"
-    raise SystemExit
+if len(args) != 1:
+    opts.error("You have to specify a target directory")
 
-targetdir = sys.argv[1]
+targetdir = args[0]
 if not os.path.exists(os.path.join(targetdir, 'web')):
     state = pep381client.Synchronization.initialize(targetdir)
 else:
     state = pep381client.Synchronization.load(targetdir)
 
-state.quiet = quiet
+state.quiet = options.quiet
 
 state.synchronize()
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.