revsetbenchmark: use optparse to retrieve argument
authorPierre-Yves David <pierre-yves.david@fb.com>
Tue, 29 Apr 2014 11:40:42 -0700
changeset 21287 2d93b74335a2
parent 21286 f0f810096842
child 21288 eb6eaef7ae44
revsetbenchmark: use optparse to retrieve argument We need more flexibility. For example we'll want to run the benchmark on other repository.
contrib/revsetbenchmarks.py
--- a/contrib/revsetbenchmarks.py	Fri Apr 25 13:35:31 2014 -0700
+++ b/contrib/revsetbenchmarks.py	Tue Apr 29 11:40:42 2014 -0700
@@ -15,6 +15,10 @@
 
 import sys
 from subprocess import check_call, Popen, CalledProcessError, STDOUT, PIPE
+# cannot use argparse, python 2.7 only
+from optparse import OptionParser
+
+
 
 def check_output(*args, **kwargs):
     kwargs.setdefault('stderr', PIPE)
@@ -65,16 +69,22 @@
     return [r for r in out.split() if r]
 
 
+parser = OptionParser(usage="usage: %prog [options] <revs>")
+parser.add_option("-f", "--file",
+                  help="read revset from FILE", metavar="FILE")
+
+(options, args) = parser.parse_args()
 
 if len(sys.argv) < 2:
-    print >> sys.stderr, 'usage: %s <revs> [file]' % sys.argv[0]
+    parser.print_help()
     sys.exit(255)
 
-target_rev = sys.argv[1]
+
+target_rev = args[0]
 
 revsetsfile = sys.stdin
-if len(sys.argv) > 2:
-    revsetsfile = open(sys.argv[2])
+if options.file:
+    revsetsfile = open(options.file)
 
 revsets = [l.strip() for l in revsetsfile]