Patchwork [6,of,8] revsetbenchmark: use optparse to retrieve argument

login
register
mail settings
Submitter Pierre-Yves David
Date May 2, 2014, 1:45 a.m.
Message ID <5aa9fb32c6eb67357a7b.1398995127@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/4479/
State Accepted
Commit 2d93b74335a23d3f70aeebb138ca6be487239e2c
Headers show

Comments

Pierre-Yves David - May 2, 2014, 1:45 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1398796842 25200
#      Tue Apr 29 11:40:42 2014 -0700
# Node ID 5aa9fb32c6eb67357a7bdada00d1d7b0725bbf47
# Parent  3bb87edcae46d4362641d7a57c48a73e3ee076d4
revsetbenchmark: use optparse to retrieve argument

We need more flexibility. For example we'll want to run the benchmark on other
repository.

Patch

diff --git a/contrib/revsetbenchmarks.py b/contrib/revsetbenchmarks.py
--- a/contrib/revsetbenchmarks.py
+++ b/contrib/revsetbenchmarks.py
@@ -13,10 +13,14 @@ 
 # This script also does one run of the current version of mercurial installed
 # to compare performance.
 
 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)
     kwargs.setdefault('stdout', PIPE)
     proc = Popen(*args, **kwargs)
@@ -63,20 +67,26 @@  def getrevs(spec):
         print >> sys.stderr, "abort, can't get revision from %s" % spec
         sys.exit(exc.returncode)
     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]
 
 print "Revsets to benchmark"
 print "----------------------------"