summaryrefslogtreecommitdiff
path: root/tools/regression/xsl_reports/utils/accept_args.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/regression/xsl_reports/utils/accept_args.py')
-rw-r--r--tools/regression/xsl_reports/utils/accept_args.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/tools/regression/xsl_reports/utils/accept_args.py b/tools/regression/xsl_reports/utils/accept_args.py
new file mode 100644
index 0000000000..b08739f40b
--- /dev/null
+++ b/tools/regression/xsl_reports/utils/accept_args.py
@@ -0,0 +1,30 @@
+
+import getopt
+import re
+import sys
+
+def accept_args( args_spec, args, options, usage ):
+
+ defaults_num = len(options)
+
+ ( option_pairs, rest_args ) = getopt.getopt( args, '', args_spec )
+ map( lambda x: options.__setitem__( x[0], x[1] ), option_pairs )
+
+ if ( options.has_key( '--help' ) or len( options.keys() ) == defaults_num ):
+ usage()
+ sys.exit( 1 )
+
+ if len( rest_args ) > 0 and rest_args[0][0] == '@':
+ f = open( rest_args[0][1:], 'r' )
+ config_lines = f.read().splitlines()
+ f.close()
+ for l in config_lines:
+ if re.search( r'^\s*#', l ): continue
+ if re.search( r'^\s*$', l ): continue
+ m = re.match( r'^(?P<name>.*?)=(?P<value>.*)', l )
+ if m:
+ options[ '--%s' % m.group( 'name' ) ] = m.group( 'value' )
+ else:
+ raise 'Invalid format of config line "%s"' % l
+
+ return rest_args