anatoly techtonik avatar anatoly techtonik committed bcb60b5

runtest.py: Gradually moving from getopt to optparse

Comments (1)

Files changed (1)

 
 cwd = os.getcwd()
 
-all = 0
 baseline = 0
 builddir = os.path.join(cwd, 'build')
 external = 0
   PRESERVE, PRESERVE_{PASS,FAIL,NO_RESULT}: preserve test subdirs
   TESTCMD_VERBOSE: turn on verbosity in TestCommand
 """
+
+
+# "Pass-through" option parsing -- an OptionParser that ignores
+# unknown options and lets them pile up in the leftover argument
+# list.  Useful to gradually port getopt to optparse.
+
+from optparse import OptionParser, BadOptionError
+
+class PassThroughOptionParser(OptionParser):
+    def _process_long_opt(self, rargs, values):
+        try:
+            OptionParser._process_long_opt(self, rargs, values)
+        except BadOptionError, err:
+            self.largs.append(err.opt_str)
+    def _process_short_opts(self, rargs, values):
+        try:
+            OptionParser._process_short_opts(self, rargs, values)
+        except BadOptionError, err:
+            self.largs.append(err.opt_str)
+
+parser = PassThroughOptionParser(add_help_option=False)
+parser.add_option('-a', '--all', action='store_true',
+                      help="Run all tests.")
+(options, args) = parser.parse_args()
+
+#print "options:", options
+#print "args:", args
 
-opts, args = getopt.getopt(sys.argv[1:], "3ab:def:hklno:P:p:qsv:Xx:t",
-                            ['all', 'baseline=', 'builddir=',
+
+opts, args = getopt.getopt(args, "3b:def:hklno:P:p:qsv:Xx:t",
+                            ['baseline=', 'builddir=',
                              'debug', 'external', 'file=', 'help', 'no-progress',
                              'list', 'no-exec', 'noqmtest', 'nopipefiles', 'output=',
                              'package=', 'passed', 'python=', 'qmtest',
 for o, a in opts:
     if o in ['-3']:
         python3incompatibilities = 1
-    elif o in ['-a', '--all']:
-        all = 1
     elif o in ['-b', '--baseline']:
         baseline = a
     elif o in ['--builddir']:
     elif o in ['--xml']:
         format = o
 
-if not args and not all and not testlistfile:
+if not args and not options.all and not testlistfile:
     sys.stderr.write("""\
 runtest.py:  No tests were specified.
              List one or more tests on the command line, use the
     tests = [x for x in tests if x[0] != '#']
     tests = [x[:-1] for x in tests]
     tests = [x.strip() for x in tests]
-elif all and not qmtest:
+elif options.all and not qmtest:
     # Find all of the SCons functional tests in the local directory
     # tree.  This is anything under the 'src' subdirectory that ends
     # with 'Tests.py', or any Python script (*.py) under the 'test'
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.