Commit db3177e3 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Add helper functions

parent 214b2ee7
Subproject commit 59a971440f0b96144d4910abefcfd6f698186c92 Subproject commit b1f0cd80a6e68b98cc31c74958d30ddb2c27dd70
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
state_aggregations: enrich AST with state aggregation flags, state_aggregations: enrich AST with state aggregation flags,
and return the list of substates of aggregations and return the list of substates of aggregations
parallel_states: return a list of strings naming all parallel states parallel_states: return a list of strings naming all parallel states
statenames: return a list of properly-formatted state names
rec_findstates: recursively find parallel/composite statenames
Copyright (c) 2012-2015 European Space Agency Copyright (c) 2012-2015 European Space Agency
...@@ -37,7 +39,27 @@ LOG = logging.getLogger(__name__) ...@@ -37,7 +39,27 @@ LOG = logging.getLogger(__name__)
__all__ = ['flatten', 'rename_everything', 'inner_labels_to_floating', __all__ = ['flatten', 'rename_everything', 'inner_labels_to_floating',
'map_input_state', 'sorted_fields', 'state_aggregations', 'map_input_state', 'sorted_fields', 'state_aggregations',
'parallel_states'] 'parallel_states', 'statenames', 'rec_findstates']
def statenames(context, sep=u'\u00dc'):
''' Return the list of states (just the names) of a given context
Format the output by replacing unicode separator symbol with a dot '''
return (s.replace(sep, u'.') for s in context.mapping.viewkeys()
if not s.endswith(u'START'))
def rec_findstates(context, prefix=''):
''' In case of state compositions/aggregations, find substates '''
for each in context.composite_states:
if not isinstance(each, ogAST.StateAggregation):
# Aggregations are just containers, not states
for name in statenames(each):
yield u'{}{}.{}'.format(prefix, each.statename, name)
for substate in rec_findstates(each,
prefix=u'{}{}.'.format(prefix,
each.statename)):
yield substate
def state_aggregations(process): def state_aggregations(process):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment