summaryrefslogtreecommitdiff
path: root/grc/core/utils/epy_block_io.py
diff options
context:
space:
mode:
authorSebastian Koslowski <koslowski@kit.edu>2016-03-16 16:25:09 +0100
committerSebastian Koslowski <koslowski@kit.edu>2016-04-05 10:10:36 +0200
commitc285036f5674ee54c16b46c3088ed86503d63d83 (patch)
tree40888ab30b540c86037a8af117a258d56dce10eb /grc/core/utils/epy_block_io.py
parent3201557bfbed7ad81e0e5a34ece48bbd93ad709b (diff)
grc-refactor: remove (hopefully) all deps to GR in core/ and gui/
Diffstat (limited to 'grc/core/utils/epy_block_io.py')
-rw-r--r--grc/core/utils/epy_block_io.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/grc/core/utils/epy_block_io.py b/grc/core/utils/epy_block_io.py
index c070e1c3f3..df3a4bbc3e 100644
--- a/grc/core/utils/epy_block_io.py
+++ b/grc/core/utils/epy_block_io.py
@@ -2,9 +2,6 @@
import inspect
import collections
-from gnuradio import gr
-import pmt
-
TYPE_MAP = {
'complex64': 'complex', 'complex': 'complex',
@@ -31,21 +28,27 @@ def _ports(sigs, msgs):
return ports
-def _blk_class(source_code):
+def _find_block_class(source_code, cls):
ns = {}
try:
exec source_code in ns
except Exception as e:
raise ValueError("Can't interpret source code: " + str(e))
for var in ns.itervalues():
- if inspect.isclass(var) and issubclass(var, gr.gateway.gateway_block):
+ if inspect.isclass(var) and issubclass(var, cls):
return var
raise ValueError('No python block class found in code')
def extract(cls):
+ try:
+ from gnuradio import gr
+ import pmt
+ except ImportError:
+ raise EnvironmentError("Can't import GNU Radio")
+
if not inspect.isclass(cls):
- cls = _blk_class(cls)
+ cls = _find_block_class(cls, gr.gateway.gateway_block)
spec = inspect.getargspec(cls.__init__)
defaults = map(repr, spec.defaults or ())