diff options
author | sienkiew <sienkiew@d34015c8-bcbb-4646-8ac8-8ba5febf221d> | 2012-06-08 12:37:27 -0400 |
---|---|---|
committer | sienkiew <sienkiew@d34015c8-bcbb-4646-8ac8-8ba5febf221d> | 2012-06-08 12:37:27 -0400 |
commit | a34160ae3d464f2482f3f666f6ce500e01b54540 (patch) | |
tree | 4a80c5b1a554749b380302cf0b13550174812e67 /steuermann/nodes.py | |
parent | 402af8f8bb04d920ee6c19af8b92a034ef42cced (diff) | |
download | steuermann-a34160ae3d464f2482f3f666f6ce500e01b54540.tar.gz |
@hostgroup in AFTER clauses
git-svn-id: https://svn.stsci.edu/svn/ssb/etal/steuermann/trunk@708 d34015c8-bcbb-4646-8ac8-8ba5febf221d
Diffstat (limited to 'steuermann/nodes.py')
-rw-r--r-- | steuermann/nodes.py | 55 |
1 files changed, 35 insertions, 20 deletions
diff --git a/steuermann/nodes.py b/steuermann/nodes.py index 4264a64..51f3264 100644 --- a/steuermann/nodes.py +++ b/steuermann/nodes.py @@ -36,20 +36,20 @@ class command_tree(object): # - we can have forward references # - we can use wild cards in our AFTER clauses - # before is the predecessor, after comes AFTER the predecessor + # before is the predecessor, after comes "AFTER before" for before, after, required, pos in self.node_order : - if ( '*' in before ) or ( '?' in before ) or ( '[' in before ): - host, table, cmd = crack_name(before) + if ( '*' in before ) or ( '?' in before ) or ( '[' in before ) or ( '@' in before ): + print "CONNECTING %-50s %-50s"%(before, after) for x in self.node_index : - hl, tl, cl = crack_name(x) - if ( fnmatch.fnmatchcase(hl,host ) and - fnmatch.fnmatchcase(tl,table) and - fnmatch.fnmatchcase(cl,cmd ) ) : + if wildcard_name( wild=before, name=x ) : + print " found",x # yes, the wild card matches this one; connect them # (but don't let a node come before itself because the wild card is too loose) if x != after : self.connect(x, after, required, pos) else : + print "CONNECTING %-50s %-50s"%(before, after) + print " found",after self.connect(before, after, required, pos) # Work out the depths of each node. @@ -62,7 +62,7 @@ class command_tree(object): if not before in self.node_index : if required : - print "error: %s happens after non-existant %s - line %s"%(before,after,line) + print "error: %s happens after non-existant %s - line %s"%(after,before,line) return if not after in self.node_index : @@ -153,24 +153,30 @@ def normalize_name( host, table, name ) : return name ##### - +# +# this checks whether a particular wildcard pattern matches a particular name +# _wildcard_cache = ( None, None ) def wildcard_name( wild, name ) : global _wildcard_cache - if wild != _wildcard_cache : - host, table, cmd = crack_name(wild) - _wildcard_cache = ( name, ( host, table, cmd ) ) - - host, table, cmd = _wildcard_cache[1] + w_host, w_table, w_cmd = crack_name(wild) - hl, tl, cl = crack_name(name) + n_host, n_table, n_cmd = crack_name(name) - return ( fnmatch.fnmatchcase(hl,host ) and - fnmatch.fnmatchcase(tl,table) and - fnmatch.fnmatchcase(cl,cmd ) ) + if w_host.startswith('@') : + # hostgroups are a special case of wild cards. it matches if the host part of + if n_host in get_hostgroup(w_host) : + return ( fnmatch.fnmatchcase(n_table,w_table) and + fnmatch.fnmatchcase(n_cmd, w_cmd ) ) + else : + return False + else : + return ( fnmatch.fnmatchcase(n_host, w_host ) and + fnmatch.fnmatchcase(n_table,w_table) and + fnmatch.fnmatchcase(n_cmd, w_cmd ) ) ##### @@ -376,7 +382,11 @@ def declare_conditions( text, filename ) : def check_condition( name, filename ) : if name in saved_conditions : - ans = saved_conditions[name]() + c = saved_conditions[name] + if callable(c) : + ans = c() + else : + ans = c else : ans = False return ans @@ -388,7 +398,12 @@ hostgroups = { } def add_hostgroup( name, host ) : if not name in hostgroups : hostgroups[name] = [ ] - hostgroups[name].append(host) + if host.startswith('@') : + new = get_hostgroup(host) + else : + new = [ host ] + + hostgroups[name] = hostgroups[name] + new def get_hostgroup( name ) : return hostgroups[name] |