[Zope-CVS] CVS: Packages/FunctionalTests - FTRunner.py:1.5
Tres Seaver
tseaver@zope.com
Thu, 14 Mar 2002 15:08:24 -0500
Update of /cvs-repository/Packages/FunctionalTests
In directory cvs.zope.org:/tmp/cvs-serv22136
Modified Files:
FTRunner.py
Log Message:
- Parse arbitrary defaults from command-line, as name=value pairs.
=== Packages/FunctionalTests/FTRunner.py 1.4 => 1.5 ===
"""
-import sys, getopt, ConfigParser
+import sys, getopt, re, ConfigParser
_marker = []
@@ -31,7 +31,7 @@
FTRunner [-htTvq] [-c config_file] \\
[-u portal_url] [-r site_path] \\
- scenario_1 ...
+ [name1=value]* scenario_1 ...
-?, --help Print this help message
@@ -83,7 +83,7 @@
time_requests = check_responses = check_elapsed_times = None
try:
- opts, filenames = getopt.getopt( args
+ opts, arglist = getopt.getopt( args
, "?tTrReEvqc:u:p:"
, [ 'help'
, 'time-requests'
@@ -140,6 +140,8 @@
if o == '-p' or o == '--site-path':
site_path = v
+ defaults, filenames = self.parseDefaults( arglist )
+
if len( filenames ) == 0:
self.printUsage( message='must specify at least one scenario' )
@@ -150,6 +152,8 @@
, 'site_path' : self._site_path
}
+ self._defaults.update( defaults )
+
# ... then config file, ...
if config_file is None:
try:
@@ -182,6 +186,28 @@
if site_path is not None:
self._defaults[ 'site_path' ] = site_path
+
+ def parseDefaults( self, arglist ):
+ """
+ Return a dictionary containing name-value pairs from
+ arglist (those whose arg matched 'name=value'), plus
+ a sequence of "normal" arguments.
+ """
+ ARG_PATTERN = re.compile( r'([A-Za-z_][\w_]*)[ ]*=[ ]*(.*)' )
+
+ defaults = {}
+ filenames = []
+
+ for arg in arglist:
+
+ match = ARG_PATTERN.match( arg )
+
+ if match:
+ defaults[ match.group(1) ] = match.group(2)
+ else:
+ filenames.append( arg )
+
+ return defaults, filenames
def readConfigFile( self, defaults ):
"""