diff options
author | Sebastian Koslowski <koslowski@kit.edu> | 2016-09-16 09:52:09 -0600 |
---|---|---|
committer | Sebastian Koslowski <koslowski@kit.edu> | 2016-09-23 21:12:03 +0200 |
commit | 17a57c886ac5d6a3c013c94d5909f418e67b704e (patch) | |
tree | 6e75afe04d9618a59a60787ea75e79d9edfc0cb6 /grc | |
parent | 554ccb816cfaad5650513837f820a408105a87f2 (diff) |
grc: make recursive flow graph load and generate more flexible
Diffstat (limited to 'grc')
-rw-r--r-- | grc/core/FlowGraph.py | 2 | ||||
-rw-r--r-- | grc/core/Platform.py | 23 |
2 files changed, 13 insertions, 12 deletions
diff --git a/grc/core/FlowGraph.py b/grc/core/FlowGraph.py index 2c3c7872de..ecae11cf1a 100644 --- a/grc/core/FlowGraph.py +++ b/grc/core/FlowGraph.py @@ -420,7 +420,7 @@ class FlowGraph(Element): cwd=self.grc_file_path ) if file_path: # grc file found. load and get block - self.platform.load_and_generate_flow_graph(file_path) + self.platform.load_and_generate_flow_graph(file_path, hier_only=True) block = self.new_block(key) # can be None if not block: # looks like this block key cannot be found diff --git a/grc/core/Platform.py b/grc/core/Platform.py index 0dc6eb055a..b73dade2e8 100644 --- a/grc/core/Platform.py +++ b/grc/core/Platform.py @@ -93,42 +93,43 @@ class Platform(Element): if os.path.exists(os.path.normpath(file_path)): return file_path - def load_and_generate_flow_graph(self, file_path): + def load_and_generate_flow_graph(self, file_path, out_path=None, hier_only=False): """Loads a flow graph from file and generates it""" Messages.set_indent(len(self._auto_hier_block_generate_chain)) - Messages.send('>>> Loading: %r\n' % file_path) + Messages.send('>>> Loading: {}\n'.format(file_path)) if file_path in self._auto_hier_block_generate_chain: Messages.send(' >>> Warning: cyclic hier_block dependency\n') - return False + return None, None self._auto_hier_block_generate_chain.add(file_path) try: flow_graph = self.get_new_flow_graph() flow_graph.grc_file_path = file_path - # Other, nested higiter_blocks might be auto-loaded here + # Other, nested hier_blocks might be auto-loaded here flow_graph.import_data(self.parse_flow_graph(file_path)) flow_graph.rewrite() flow_graph.validate() if not flow_graph.is_valid(): raise Exception('Flowgraph invalid') - if not flow_graph.get_option('generate_options').startswith('hb'): + if hier_only and not flow_graph.get_option('generate_options').startswith('hb'): raise Exception('Not a hier block') except Exception as e: Messages.send('>>> Load Error: {}: {}\n'.format(file_path, str(e))) - return False + return None, None finally: self._auto_hier_block_generate_chain.discard(file_path) Messages.set_indent(len(self._auto_hier_block_generate_chain)) try: - Messages.send('>>> Generating: {}\n'.format(file_path)) - generator = self.Generator(flow_graph, file_path) + generator = self.Generator(flow_graph, out_path or file_path) + Messages.send('>>> Generating: {}\n'.format(generator.file_path)) generator.write() except Exception as e: Messages.send('>>> Generate Error: {}: {}\n'.format(file_path, str(e))) - return False + return None, None - self.load_block_xml(generator.get_file_path_xml()) - return True + if flow_graph.get_option('generate_options').startswith('hb'): + self.load_block_xml(generator.get_file_path_xml()) + return flow_graph, generator.file_path def build_block_library(self): """load the blocks and block tree from the search paths""" |