From 554ccb816cfaad5650513837f820a408105a87f2 Mon Sep 17 00:00:00 2001 From: Sebastian Koslowski <koslowski@kit.edu> Date: Fri, 16 Sep 2016 09:50:33 -0600 Subject: grc: move run command getter to core --- grc/core/FlowGraph.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'grc/core/FlowGraph.py') diff --git a/grc/core/FlowGraph.py b/grc/core/FlowGraph.py index 949eecaa71..2c3c7872de 100644 --- a/grc/core/FlowGraph.py +++ b/grc/core/FlowGraph.py @@ -16,16 +16,16 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA import imp -import time from itertools import ifilter, chain from operator import methodcaller, attrgetter - import re +import sys +import time from . import Messages from .Constants import FLOW_GRAPH_FILE_FORMAT_VERSION from .Element import Element -from .utils import odict, expr_utils +from .utils import odict, expr_utils, shlex _parameter_matcher = re.compile('^(parameter)$') _monitors_searcher = re.compile('(ctrlport_monitor)') @@ -186,6 +186,16 @@ class FlowGraph(Element): """ return self._options_block.get_param(key).get_evaluated() + def get_run_command(self, file_path, split=False): + run_command = self.get_option('run_command') + try: + run_command = run_command.format( + python=shlex.quote(sys.executable), + filename=shlex.quote(file_path)) + return shlex.split(run_command) if split else run_command + except Exception as e: + raise ValueError("Can't parse run command {!r}: {}".format(run_command, e)) + ############################################## # Access Elements ############################################## -- cgit v1.2.3 From 17a57c886ac5d6a3c013c94d5909f418e67b704e Mon Sep 17 00:00:00 2001 From: Sebastian Koslowski <koslowski@kit.edu> Date: Fri, 16 Sep 2016 09:52:09 -0600 Subject: grc: make recursive flow graph load and generate more flexible --- grc/core/FlowGraph.py | 2 +- grc/core/Platform.py | 23 ++++++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-) (limited to 'grc/core/FlowGraph.py') 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""" -- cgit v1.2.3