diff options
author | cslocum <cslocum@d34015c8-bcbb-4646-8ac8-8ba5febf221d> | 2012-12-28 11:55:24 -0500 |
---|---|---|
committer | cslocum <cslocum@d34015c8-bcbb-4646-8ac8-8ba5febf221d> | 2012-12-28 11:55:24 -0500 |
commit | c4191477969419683a90c7e5ec1fcb8349492ca2 (patch) | |
tree | 649fb034fb31a65f8d390971b9385ae92fdd97bc | |
parent | aa99d8b0ea5f55e1992fd880d8f285f38fa4cbc6 (diff) | |
download | steuermann-c4191477969419683a90c7e5ec1fcb8349492ca2.tar.gz |
changes to several files to make command line conditional args work
git-svn-id: https://svn.stsci.edu/svn/ssb/etal/steuermann/trunk@922 d34015c8-bcbb-4646-8ac8-8ba5febf221d
-rw-r--r-- | steuermann/nodes.py | 17 | ||||
-rw-r--r-- | steuermann/run_all.py | 53 | ||||
-rw-r--r-- | steuermann/specfile.exy | 2 |
3 files changed, 42 insertions, 30 deletions
diff --git a/steuermann/nodes.py b/steuermann/nodes.py index 095b3d3..871b7c6 100644 --- a/steuermann/nodes.py +++ b/steuermann/nodes.py @@ -330,6 +330,7 @@ import specfile current_file_name = None def read_file_list( file_list ) : + global current_file_name di = command_tree( ) imported = { } @@ -380,11 +381,22 @@ def declare_conditions( text, filename ) : # exec will work if text.startswith(' ') or text.startswith('\t') : text = 'if 1 :\n' + text + + # exec it into cond first, and then move any entries that are unique + # into saved_conditions; this allows us to specify conditions on the + # command line and not have them overwritten by the same variable in + # a CONDITIONS block + cond = {} + exec text in cond + for k, v in cond.items(): + if k not in saved_conditions: + saved_conditions[k] = v + - # exec it into the dict - exec text in saved_conditions + def check_condition( name, filename ) : + if name in saved_conditions : c = saved_conditions[name] if callable(c) : @@ -393,6 +405,7 @@ def check_condition( name, filename ) : ans = c else : ans = False + return ans ##### diff --git a/steuermann/run_all.py b/steuermann/run_all.py index fc15f93..1890820 100644 --- a/steuermann/run_all.py +++ b/steuermann/run_all.py @@ -36,6 +36,7 @@ username=getpass.getuser() ##### def main() : + global xnodes global no_run @@ -50,14 +51,14 @@ def main() : atexit.register(readline.write_history_file, history) -# easyargs spec definition: -# -# '-v' : '', # arg takes no parameter, opt['-v'] is -# # how many times it occurred -# '-f' : '=', # arg takes a parameter -# '-mf' : '=+', # arg takes a parameter, may be specified -# # several times to get a list -# '--verbose' : '-v', # arg is an alias for some other arg + # easyargs spec definition: + # + # '-v' : '', # arg takes no parameter, opt['-v'] is + # # how many times it occurred + # '-f' : '=', # arg takes a parameter + # '-mf' : '=+', # arg takes a parameter, may be specified + # # several times to get a list + # '--verbose' : '-v', # arg is an alias for some other arg allowed_flags = { '--all' : '-a' , @@ -69,15 +70,28 @@ def main() : opt, args = easyargs.get(allowed_flags, allow_unexpected = True) - # - # - all = opt['-a'] no_run = opt['-n'] + + # find any unknown arguments like --something=whatever, set as conditions + arguments = sys.argv[1:] + for a in arguments: + if '--' in a and '=' in a: + + not_allowed_flag = True + for f in allowed_flags.keys(): + if a.startswith(f): + not_allowed_flag = False + break + if not_allowed_flag: + a = a.lstrip('--') + k, v = a.split('=') + nodes.saved_conditions[k] = eval(v) + + sm_files = [a for a in args if ('--' not in a and '=' not in a)] di_nodes = nodes.read_file_list( sm_files ) - xnodes = di_nodes.node_index # get run name @@ -97,21 +111,6 @@ def main() : db = steuermann.config.open_db() - # find any unknown arguments like --something=whatever, set as conditions - arguments = sys.argv[1:] - for a in arguments: - print a - if '--' in a and '=' in a: - not_allowed_flag = True - for f in allowed_flags.keys(): - if a.startswith(f): - not_allowed_flag = False - break - if not_allowed_flag: - a = a.lstrip('--') - k, v = a.split('=') - nodes.saved_conditions[k] = v - if all : run_all(xnodes, run_name, hosts_ini, db) else : diff --git a/steuermann/specfile.exy b/steuermann/specfile.exy index 38211aa..346ee20 100644 --- a/steuermann/specfile.exy +++ b/steuermann/specfile.exy @@ -88,7 +88,7 @@ parser specfile: ## # rule cond_command<<table_name,hostlist>> : - IF name COLON command + IF name COLON command {{ if nodes.check_condition(name, self._scanner.filename ) : self.data.add_command_list( table_name, hostlist, [ command ] ) }} | IFNOT name COLON command {{ if not nodes.check_condition(name, self._scanner.filename ) : self.data.add_command_list( table_name, hostlist, [ command ] ) }} |