diff options
author | Sebastian Koslowski <koslowski@kit.edu> | 2015-12-02 17:45:06 +0100 |
---|---|---|
committer | Sebastian Koslowski <koslowski@kit.edu> | 2015-12-04 21:08:38 +0100 |
commit | 635bb2d62420001e4a0c34b3898aa259775e43b8 (patch) | |
tree | 87a3d3322f60bd7ca3a76e8900b19c02b2c2b119 /grc/python/FlowGraph.py | |
parent | df4f5820cea5c8786f118bf94adb950afe6b2aab (diff) |
grc: add embedded python modules
Diffstat (limited to 'grc/python/FlowGraph.py')
-rw-r--r-- | grc/python/FlowGraph.py | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/grc/python/FlowGraph.py b/grc/python/FlowGraph.py index bedf9ccf33..686dae70fa 100644 --- a/grc/python/FlowGraph.py +++ b/grc/python/FlowGraph.py @@ -17,6 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA """ import re +import imp from operator import methodcaller from . import expr_utils @@ -203,6 +204,12 @@ class FlowGraph(_FlowGraph, _GUIFlowGraph): self.iter_enabled_blocks()) return monitors + def get_python_modules(self): + """Iterate over custom code block ID and Source""" + for block in self.iter_enabled_blocks(): + if block.get_key() == 'epy_module': + yield block.get_id(), block.get_param('source_code').get_value() + def get_bussink(self): bussink = filter(lambda b: _bussink_searcher.search(b.get_key()), self.get_enabled_blocks()) @@ -213,8 +220,6 @@ class FlowGraph(_FlowGraph, _GUIFlowGraph): return False - - def get_bussrc(self): bussrc = filter(lambda b: _bussrc_searcher.search(b.get_key()), self.get_enabled_blocks()) @@ -278,9 +283,18 @@ class FlowGraph(_FlowGraph, _GUIFlowGraph): #reload namespace n = dict() #load imports - for imp in self.get_imports(): - try: exec imp in n + for code in self.get_imports(): + try: exec code in n except: pass + + for id, code in self.get_python_modules(): + try: + module = imp.new_module(id) + exec code in module.__dict__ + n[id] = module + except: + pass + #load parameters np = dict() for parameter in self.get_parameters(): |