diff options
Diffstat (limited to 'steuermann')
-rw-r--r-- | steuermann/nodes.py | 40 | ||||
-rw-r--r-- | steuermann/run_all.py | 22 |
2 files changed, 37 insertions, 25 deletions
diff --git a/steuermann/nodes.py b/steuermann/nodes.py index 871b7c6..17b73ab 100644 --- a/steuermann/nodes.py +++ b/steuermann/nodes.py @@ -3,6 +3,8 @@ Stuff related to the tree structure of the command set ''' import fnmatch +from run_all import allowed_flags +import sys #import exyapps.runtime @@ -366,6 +368,21 @@ def read_file_list( file_list ) : saved_conditions = { 'True' : True, 'False' : False } +# 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('=') + saved_conditions[k] = eval(v) + + def declare_conditions( text, filename ) : # the parameter "text" is the token that begins "CONDITION\n" # and ends "\nEND\n", with a block of python code in the middle. @@ -377,22 +394,13 @@ def declare_conditions( text, filename ) : text = text.split('\n',1)[1] # tear off "CONDITION\n" text = text.rsplit('\n',2)[0] # tear off "END\n" - # if it is indented at all, compensate for the indent so the - # 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 - - + for ln in text.split('\n'): + ln = ln.strip() + cond = saved_conditions.copy() + exec ln in cond + for k, v in cond.items(): + if k not in saved_conditions: + saved_conditions[k] = v def check_condition( name, filename ) : diff --git a/steuermann/run_all.py b/steuermann/run_all.py index 50b415e..425d5e3 100644 --- a/steuermann/run_all.py +++ b/steuermann/run_all.py @@ -35,6 +35,15 @@ username=getpass.getuser() ##### +allowed_flags = { + '--all' : '-a' , + '-a' : '' , # run all nodes non-interactively + '-r' : '=' , # give run name + '-n' : '' , # do not actually execute any processes + '-h' : '=' , # give hosts (*.ini) file +} + + def main() : global xnodes @@ -60,20 +69,15 @@ def main() : # # several times to get a list # '--verbose' : '-v', # arg is an alias for some other arg - allowed_flags = { - '--all' : '-a' , - '-a' : '' , # run all nodes non-interactively - '-r' : '=' , # give run name - '-n' : '' , # do not actually execute any processes - '-h' : '=' , # give hosts (*.ini) file - } - opt, args = easyargs.get(allowed_flags, allow_unexpected = True) all = opt['-a'] no_run = opt['-n'] + ''' + NOTE: moving this functionality into nodes.py + # find any unknown arguments like --something=whatever, set as conditions arguments = sys.argv[1:] for a in arguments: @@ -88,7 +92,7 @@ def main() : 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 ) |