changeset 21287:2d93b74335a2

revsetbenchmark: use optparse to retrieve argument We need more flexibility. For example we'll want to run the benchmark on other repository.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Tue, 29 Apr 2014 11:40:42 -0700
parents f0f810096842
children eb6eaef7ae44
files contrib/revsetbenchmarks.py
diffstat 1 files changed, 14 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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]