summaryrefslogtreecommitdiff
path: root/grc
diff options
context:
space:
mode:
authorTom Rondeau2011-05-02 12:35:16 +0100
committerTom Rondeau2011-05-02 12:35:16 +0100
commit207a2ae73bd5d6cab201bb57ed8db64fd54cfd90 (patch)
tree3a828f115fdf011b7f78e45d75c45b7c4912a046 /grc
parent7a91b8226f71d75b027beb466f965bbba97c07a8 (diff)
parenta92cb89b5529728d9fce781aff85916b3879fbdd (diff)
downloadgnuradio-207a2ae73bd5d6cab201bb57ed8db64fd54cfd90.tar.gz
gnuradio-207a2ae73bd5d6cab201bb57ed8db64fd54cfd90.tar.bz2
gnuradio-207a2ae73bd5d6cab201bb57ed8db64fd54cfd90.zip
Merge branch 'mergeme/grc/cross_platform_work'
Diffstat (limited to 'grc')
-rw-r--r--grc/Makefile.am1
-rw-r--r--grc/base/Block.py14
-rw-r--r--grc/base/Connection.py12
-rw-r--r--grc/base/FlowGraph.py20
-rw-r--r--grc/base/Param.py30
-rw-r--r--grc/base/Platform.py21
-rw-r--r--grc/base/Port.py6
-rw-r--r--grc/base/odict.py8
-rw-r--r--grc/grc.conf.in1
-rw-r--r--grc/gui/ActionHandler.py5
-rw-r--r--grc/gui/Actions.py5
-rw-r--r--grc/gui/FlowGraph.py10
-rw-r--r--grc/gui/Utils.py5
-rw-r--r--grc/python/Block.py13
-rw-r--r--grc/python/Connection.py6
-rw-r--r--grc/python/Constants.py6
-rw-r--r--grc/python/Generator.py20
-rw-r--r--grc/python/Param.py75
-rw-r--r--grc/python/Platform.py4
-rw-r--r--grc/python/Port.py21
-rw-r--r--grc/python/expr_utils.py6
-rw-r--r--grc/python/extract_docs.py6
22 files changed, 146 insertions, 149 deletions
diff --git a/grc/Makefile.am b/grc/Makefile.am
index c36786281..9d473b4d3 100644
--- a/grc/Makefile.am
+++ b/grc/Makefile.am
@@ -43,7 +43,6 @@ BUILT_SOURCES += grc.conf
grc.conf: $(srcdir)/grc.conf.in Makefile
sed \
- -e 's|@pythonw[@]|$(PYTHONW)|g' \
-e 's|@blocksdir[@]|$(grc_blocksdir)|g' \
-e 's|@docdir[@]|$(gr_docdir)|g' \
$< > $@
diff --git a/grc/base/Block.py b/grc/base/Block.py
index 42eb6b3fb..fe7ad3c2f 100644
--- a/grc/base/Block.py
+++ b/grc/base/Block.py
@@ -1,5 +1,5 @@
"""
-Copyright 2008, 2009 Free Software Foundation, Inc.
+Copyright 2008-2011 Free Software Foundation, Inc.
This file is part of GNU Radio
GNU Radio Companion is free software; you can redistribute it and/or
@@ -92,8 +92,8 @@ class Block(Element):
for param in map(lambda n: self.get_parent().get_parent().Param(block=self, n=n), params):
key = param.get_key()
#test against repeated keys
- try: assert key not in self.get_param_keys()
- except AssertionError: raise Exception, 'Key "%s" already exists in params'%key
+ if key in self.get_param_keys():
+ raise Exception, 'Key "%s" already exists in params'%key
#store the param
self.get_params().append(param)
#create the source objects
@@ -101,8 +101,8 @@ class Block(Element):
for source in map(lambda n: self.get_parent().get_parent().Port(block=self, n=n, dir='source'), sources):
key = source.get_key()
#test against repeated keys
- try: assert key not in self.get_source_keys()
- except AssertionError: raise Exception, 'Key "%s" already exists in sources'%key
+ if key in self.get_source_keys():
+ raise Exception, 'Key "%s" already exists in sources'%key
#store the port
self.get_sources().append(source)
#create the sink objects
@@ -110,8 +110,8 @@ class Block(Element):
for sink in map(lambda n: self.get_parent().get_parent().Port(block=self, n=n, dir='sink'), sinks):
key = sink.get_key()
#test against repeated keys
- try: assert key not in self.get_sink_keys()
- except AssertionError: raise Exception, 'Key "%s" already exists in sinks'%key
+ if key in self.get_sink_keys():
+ raise Exception, 'Key "%s" already exists in sinks'%key
#store the port
self.get_sinks().append(sink)
diff --git a/grc/base/Connection.py b/grc/base/Connection.py
index 94d4751b2..3ce7fd07f 100644
--- a/grc/base/Connection.py
+++ b/grc/base/Connection.py
@@ -1,5 +1,5 @@
"""
-Copyright 2008, 2009 Free Software Foundation, Inc.
+Copyright 2008-2011 Free Software Foundation, Inc.
This file is part of GNU Radio
GNU Radio Companion is free software; you can redistribute it and/or
@@ -37,10 +37,12 @@ class Connection(Element):
for port in (porta, portb):
if port.is_source(): source = port
if port.is_sink(): sink = port
- assert(source and sink)
+ if not source: raise ValueError('Connection could not isolate source')
+ if not sink: raise ValueError('Connection could not isolate sink')
#ensure that this connection (source -> sink) is unique
for connection in self.get_parent().get_connections():
- assert not (connection.get_source() is source and connection.get_sink() is sink)
+ if connection.get_source() is source and connection.get_sink() is sink:
+ raise Exception('This connection between source and sink is not unique.')
self._source = source
self._sink = sink
@@ -62,8 +64,8 @@ class Connection(Element):
Element.validate(self)
source_type = self.get_source().get_type()
sink_type = self.get_sink().get_type()
- try: assert source_type == sink_type
- except AssertionError: self.add_error_message('Source type "%s" does not match sink type "%s".'%(source_type, sink_type))
+ if source_type != sink_type:
+ self.add_error_message('Source type "%s" does not match sink type "%s".'%(source_type, sink_type))
def get_enabled(self):
"""
diff --git a/grc/base/FlowGraph.py b/grc/base/FlowGraph.py
index b4ac8fc3a..0ba1f2389 100644
--- a/grc/base/FlowGraph.py
+++ b/grc/base/FlowGraph.py
@@ -1,5 +1,5 @@
"""
-Copyright 2008, 2009 Free Software Foundation, Inc.
+Copyright 2008-2011 Free Software Foundation, Inc.
This file is part of GNU Radio
GNU Radio Companion is free software; you can redistribute it and/or
@@ -194,18 +194,26 @@ class FlowGraph(Element):
sink_key = connection_n.find('sink_key')
#verify the blocks
block_ids = map(lambda b: b.get_id(), self.get_blocks())
- assert(source_block_id in block_ids)
- assert(sink_block_id in block_ids)
+ if source_block_id not in block_ids:
+ raise LookupError('source block id "%s" not in block ids'%source_block_id)
+ if sink_block_id not in block_ids:
+ raise LookupError('sink block id "%s" not in block ids'%sink_block_id)
#get the blocks
source_block = self.get_block(source_block_id)
sink_block = self.get_block(sink_block_id)
#verify the ports
- assert(source_key in source_block.get_source_keys())
- assert(sink_key in sink_block.get_sink_keys())
+ if source_key not in source_block.get_source_keys():
+ raise LookupError('source key "%s" not in source block keys'%source_key)
+ if sink_key not in sink_block.get_sink_keys():
+ raise LookupError('sink key "%s" not in sink block keys'%sink_key)
#get the ports
source = source_block.get_source(source_key)
sink = sink_block.get_sink(sink_key)
#build the connection
self.connect(source, sink)
- except AssertionError: Messages.send_error_load('Connection between %s(%s) and %s(%s) could not be made.'%(source_block_id, source_key, sink_block_id, sink_key))
+ except LookupError, e: Messages.send_error_load(
+ 'Connection between %s(%s) and %s(%s) could not be made.\n\t%s'%(
+ source_block_id, source_key, sink_block_id, sink_key, e
+ )
+ )
self.rewrite() #global rewrite
diff --git a/grc/base/Param.py b/grc/base/Param.py
index 5cd0f9d6d..c2fa5461a 100644
--- a/grc/base/Param.py
+++ b/grc/base/Param.py
@@ -1,5 +1,5 @@
"""
-Copyright 2008, 2009 Free Software Foundation, Inc.
+Copyright 2008-2011 Free Software Foundation, Inc.
This file is part of GNU Radio
GNU Radio Companion is free software; you can redistribute it and/or
@@ -34,16 +34,16 @@ class Option(Element):
self._opts = dict()
opts = n.findall('opt')
#test against opts when non enum
- try: assert self.get_parent().is_enum() or not opts
- except AssertionError: raise Exception, 'Options for non-enum types cannot have sub-options'
+ if not self.get_parent().is_enum() and opts:
+ raise Exception, 'Options for non-enum types cannot have sub-options'
#extract opts
for opt in opts:
#separate the key:value
try: key, value = opt.split(':')
except: raise Exception, 'Error separating "%s" into key:value'%opt
#test against repeated keys
- try: assert not self._opts.has_key(key)
- except AssertionError: raise Exception, 'Key "%s" already exists in option'%key
+ if self._opts.has_key(key):
+ raise Exception, 'Key "%s" already exists in option'%key
#store the option
self._opts[key] = value
@@ -79,24 +79,24 @@ class Param(Element):
for option in map(lambda o: Option(param=self, n=o), n.findall('option')):
key = option.get_key()
#test against repeated keys
- try: assert key not in self.get_option_keys()
- except AssertionError: raise Exception, 'Key "%s" already exists in options'%key
+ if key in self.get_option_keys():
+ raise Exception, 'Key "%s" already exists in options'%key
#store the option
self.get_options().append(option)
#test the enum options
if self.is_enum():
#test against options with identical keys
- try: assert len(set(self.get_option_keys())) == len(self.get_options())
- except AssertionError: raise Exception, 'Options keys "%s" are not unique.'%self.get_option_keys()
+ if len(set(self.get_option_keys())) != len(self.get_options()):
+ raise Exception, 'Options keys "%s" are not unique.'%self.get_option_keys()
#test against inconsistent keys in options
opt_keys = self.get_options()[0].get_opt_keys()
for option in self.get_options():
- try: assert set(opt_keys) == set(option.get_opt_keys())
- except AssertionError: raise Exception, 'Opt keys "%s" are not identical across all options.'%opt_keys
+ if set(opt_keys) != set(option.get_opt_keys()):
+ raise Exception, 'Opt keys "%s" are not identical across all options.'%opt_keys
#if a value is specified, it must be in the options keys
self._value = value if value or value in self.get_option_keys() else self.get_option_keys()[0]
- try: assert self.get_value() in self.get_option_keys()
- except AssertionError: raise Exception, 'The value "%s" is not in the possible values of "%s".'%(self.get_value(), self.get_option_keys())
+ if self.get_value() not in self.get_option_keys():
+ raise Exception, 'The value "%s" is not in the possible values of "%s".'%(self.get_value(), self.get_option_keys())
else: self._value = value or ''
def validate(self):
@@ -105,8 +105,8 @@ class Param(Element):
The value must be evaluated and type must a possible type.
"""
Element.validate(self)
- try: assert self.get_type() in self.get_types()
- except AssertionError: self.add_error_message('Type "%s" is not a possible type.'%self.get_type())
+ if self.get_type() not in self.get_types():
+ self.add_error_message('Type "%s" is not a possible type.'%self.get_type())
def get_evaluated(self): raise NotImplementedError
diff --git a/grc/base/Platform.py b/grc/base/Platform.py
index 096fdec41..a66c28ab9 100644
--- a/grc/base/Platform.py
+++ b/grc/base/Platform.py
@@ -1,5 +1,5 @@
"""
-Copyright 2008, 2009, 2011 Free Software Foundation, Inc.
+Copyright 2008-2011 Free Software Foundation, Inc.
This file is part of GNU Radio
GNU Radio Companion is free software; you can redistribute it and/or
@@ -17,16 +17,6 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
"""
-#Perform python integrity checks:
-# GRC will not work with interpreters that fail the checks below.
-# This can fail on interpreters built with special optimizations.
-try:
- assert False
- raise Exception, 'Failed python integrity check: assert not supported'
-except AssertionError: pass
-if __doc__ is None:
- raise Exception, 'Failed python integrity check: __doc__ not supported'
-
import os
import sys
from .. base import ParseXML, odict
@@ -91,13 +81,12 @@ class Platform(_Element):
block = self.Block(self._flow_graph, n)
key = block.get_key()
#test against repeated keys
- try:
- assert key not in self.get_block_keys()
- #store the block
+ if key in self.get_block_keys():
+ print >> sys.stderr, 'Warning: Block with key "%s" already exists.\n\tIgnoring: %s'%(key, xml_file)
+ #store the block
+ else:
self._blocks[key] = block
self._blocks_n[key] = n
- except AssertionError:
- print >> sys.stderr, 'Warning: Block with key "%s" already exists.\n\tIgnoring: %s'%(key, xml_file)
except ParseXML.XMLSyntaxError, e:
try: #try to add the xml file as a block tree
ParseXML.validate_dtd(xml_file, BLOCK_TREE_DTD)
diff --git a/grc/base/Port.py b/grc/base/Port.py
index 494ea894f..7a1b5d4e6 100644
--- a/grc/base/Port.py
+++ b/grc/base/Port.py
@@ -1,5 +1,5 @@
"""
-Copyright 2008, 2009 Free Software Foundation, Inc.
+Copyright 2008-2011 Free Software Foundation, Inc.
This file is part of GNU Radio
GNU Radio Companion is free software; you can redistribute it and/or
@@ -42,8 +42,8 @@ class Port(Element):
The port must be non-empty and type must a possible type.
"""
Element.validate(self)
- try: assert self.get_type() in self.get_types()
- except AssertionError: self.add_error_message('Type "%s" is not a possible type.'%self.get_type())
+ if self.get_type() not in self.get_types():
+ self.add_error_message('Type "%s" is not a possible type.'%self.get_type())
def __str__(self):
if self.is_source():
diff --git a/grc/base/odict.py b/grc/base/odict.py
index ac3cb2070..044d04ad7 100644
--- a/grc/base/odict.py
+++ b/grc/base/odict.py
@@ -1,5 +1,5 @@
"""
-Copyright 2008, 2009 Free Software Foundation, Inc.
+Copyright 2008-2011 Free Software Foundation, Inc.
This file is part of GNU Radio
GNU Radio Companion is free software; you can redistribute it and/or
@@ -55,7 +55,7 @@ class odict(DictMixin):
@param val the value for the new entry
"""
index = (pos_key is None) and len(self._keys) or self._keys.index(pos_key)
- assert key not in self._keys
+ if key in self._keys: raise KeyError('Cannot insert, key "%s" already exists'%str(key))
self._keys.insert(index+1, key)
self._data[key] = val
@@ -67,8 +67,8 @@ class odict(DictMixin):
@param key the key for the new entry
@param val the value for the new entry
"""
- index = (pos_key is not None) and self._keys.index(pos_key) or 0
- assert key not in self._keys
+ index = (pos_key is not None) and self._keys.index(pos_key) or 0
+ if key in self._keys: raise KeyError('Cannot insert, key "%s" already exists'%str(key))
self._keys.insert(index, key)
self._data[key] = val
diff --git a/grc/grc.conf.in b/grc/grc.conf.in
index 37a049971..9363ca981 100644
--- a/grc/grc.conf.in
+++ b/grc/grc.conf.in
@@ -3,7 +3,6 @@
# ~/.gnuradio/config.conf
[grc]
-pythonw = @pythonw@
doc_dir = @docdir@
global_blocks_path = @blocksdir@
local_blocks_path =
diff --git a/grc/gui/ActionHandler.py b/grc/gui/ActionHandler.py
index 350b297bb..15785f2ee 100644
--- a/grc/gui/ActionHandler.py
+++ b/grc/gui/ActionHandler.py
@@ -1,5 +1,5 @@
"""
-Copyright 2007, 2008, 2009, 2011 Free Software Foundation, Inc.
+Copyright 2007-2011 Free Software Foundation, Inc.
This file is part of GNU Radio
GNU Radio Companion is free software; you can redistribute it and/or
@@ -78,8 +78,7 @@ class ActionHandler:
When not in focus, gtk and the accelerators handle the the key press.
@return false to let gtk handle the key action
"""
- try: assert self.get_focus_flag()
- except AssertionError: return False
+ if not self.get_focus_flag(): return False
return Actions.handle_key_press(event)
def _quit(self, window, event):
diff --git a/grc/gui/Actions.py b/grc/gui/Actions.py
index f374efde1..4d196477e 100644
--- a/grc/gui/Actions.py
+++ b/grc/gui/Actions.py
@@ -1,5 +1,5 @@
"""
-Copyright 2007, 2008, 2009 Free Software Foundation, Inc.
+Copyright 2007-2011 Free Software Foundation, Inc.
This file is part of GNU Radio
GNU Radio Companion is free software; you can redistribute it and/or
@@ -76,7 +76,8 @@ class Action(gtk.Action):
for i in range(len(keypresses)/2):
keyval, mod_mask = keypresses[i*2:(i+1)*2]
#register this keypress
- assert not _actions_keypress_dict.has_key((keyval, mod_mask))
+ if _actions_keypress_dict.has_key((keyval, mod_mask)):
+ raise KeyError('keyval/mod_mask pair already registered "%s"'%str((keyval, mod_mask)))
_actions_keypress_dict[(keyval, mod_mask)] = self
#set the accelerator group, and accelerator path
#register the key name and mod mask with the accelerator path
diff --git a/grc/gui/FlowGraph.py b/grc/gui/FlowGraph.py
index 897145a1d..9f3326ada 100644
--- a/grc/gui/FlowGraph.py
+++ b/grc/gui/FlowGraph.py
@@ -1,5 +1,5 @@
"""
-Copyright 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+Copyright 2007-2011 Free Software Foundation, Inc.
This file is part of GNU Radio
GNU Radio Companion is free software; you can redistribute it and/or
@@ -290,10 +290,10 @@ class FlowGraph(Element):
for selected in selected_elements:
if selected in elements: continue
selected_elements.remove(selected)
- try: assert self._old_selected_port.get_parent() in elements
- except: self._old_selected_port = None
- try: assert self._new_selected_port.get_parent() in elements
- except: self._new_selected_port = None
+ if self._old_selected_port and self._old_selected_port.get_parent() not in elements:
+ self._old_selected_port = None
+ if self._new_selected_port and self._new_selected_port.get_parent() not in elements:
+ self._new_selected_port = None
#update highlighting
for element in elements:
element.set_highlighted(element in selected_elements)
diff --git a/grc/gui/Utils.py b/grc/gui/Utils.py
index b5489d56e..bb19ed3d9 100644
--- a/grc/gui/Utils.py
+++ b/grc/gui/Utils.py
@@ -1,5 +1,5 @@
"""
-Copyright 2008, 2009 Free Software Foundation, Inc.
+Copyright 2008-2011 Free Software Foundation, Inc.
This file is part of GNU Radio
GNU Radio Companion is free software; you can redistribute it and/or
@@ -53,7 +53,8 @@ def get_rotated_coordinate(coor, rotation):
"""
#handles negative angles
rotation = (rotation + 360)%360
- assert rotation in POSSIBLE_ROTATIONS
+ if rotation not in POSSIBLE_ROTATIONS:
+ raise ValueError('unusable rotation angle "%s"'%str(rotation))
#determine the number of degrees to rotate
cos_r, sin_r = {
0: (1, 0),
diff --git a/grc/python/Block.py b/grc/python/Block.py
index bd03eb5cd..14a5859e4 100644
--- a/grc/python/Block.py
+++ b/grc/python/Block.py
@@ -1,5 +1,5 @@
"""
-Copyright 2008, 2009 Free Software Foundation, Inc.
+Copyright 2008-2011 Free Software Foundation, Inc.
This file is part of GNU Radio
GNU Radio Companion is free software; you can redistribute it and/or
@@ -65,9 +65,8 @@ class Block(_Block, _GUIBlock):
for check in self._checks:
check_res = self.resolve_dependencies(check)
try:
- check_eval = self.get_parent().evaluate(check_res)
- try: assert check_eval
- except AssertionError: self.add_error_message('Check "%s" failed.'%check)
+ if not self.get_parent().evaluate(check_res):
+ self.add_error_message('Check "%s" failed.'%check)
except: self.add_error_message('Check "%s" did not evaluate.'%check)
def rewrite(self):
@@ -134,9 +133,9 @@ class Block(_Block, _GUIBlock):
try:
value = param.get_evaluated()
value = value + direction
- assert 0 < value
- param.set_value(value)
- changed = True
+ if 0 < value:
+ param.set_value(value)
+ changed = True
except: pass
return changed
diff --git a/grc/python/Connection.py b/grc/python/Connection.py
index edc18841a..39f915740 100644
--- a/grc/python/Connection.py
+++ b/grc/python/Connection.py
@@ -1,5 +1,5 @@
"""
-Copyright 2008, 2009 Free Software Foundation, Inc.
+Copyright 2008-2011 Free Software Foundation, Inc.
This file is part of GNU Radio
GNU Radio Companion is free software; you can redistribute it and/or
@@ -38,5 +38,5 @@ class Connection(_Connection, _GUIConnection):
#check vector length
source_vlen = self.get_source().get_vlen()
sink_vlen = self.get_sink().get_vlen()
- try: assert source_vlen == sink_vlen
- except AssertionError: self.add_error_message('Source vector length "%s" does not match sink vector length "%s".'%(source_vlen, sink_vlen))
+ if source_vlen != sink_vlen:
+ self.add_error_message('Source vector length "%s" does not match sink vector length "%s".'%(source_vlen, sink_vlen))
diff --git a/grc/python/Constants.py b/grc/python/Constants.py
index e661c3927..868c822aa 100644
--- a/grc/python/Constants.py
+++ b/grc/python/Constants.py
@@ -1,5 +1,5 @@
"""
-Copyright 2008, 2009 Free Software Foundation, Inc.
+Copyright 2008-2011 Free Software Foundation, Inc.
This file is part of GNU Radio
GNU Radio Companion is free software; you can redistribute it and/or
@@ -23,10 +23,8 @@ from gnuradio import gr
_gr_prefs = gr.prefs()
-PYEXEC = os.environ.get('PYTHONW', _gr_prefs.get_string('grc', 'pythonw', ''))
-
#setup paths
-PATH_SEP = ':'
+PATH_SEP = {'/':':', '\\':';'}[os.path.sep]
DOCS_DIR = os.environ.get('GR_DOC_DIR', _gr_prefs.get_string('grc', 'doc_dir', ''))
HIER_BLOCKS_LIB_DIR = os.path.join(os.path.expanduser('~'), '.grc_gnuradio')
BLOCKS_DIRS = filter( #filter blank strings
diff --git a/grc/python/Generator.py b/grc/python/Generator.py
index b669fa65a..b31f0a009 100644
--- a/grc/python/Generator.py
+++ b/grc/python/Generator.py
@@ -18,14 +18,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
"""
import os
+import sys
import subprocess
import tempfile
from Cheetah.Template import Template
import expr_utils
from Constants import \
TOP_BLOCK_FILE_MODE, HIER_BLOCK_FILE_MODE, \
- HIER_BLOCKS_LIB_DIR, PYEXEC, \
- FLOW_GRAPH_TEMPLATE
+ HIER_BLOCKS_LIB_DIR, FLOW_GRAPH_TEMPLATE
import convert_hier
from .. gui import Messages
@@ -74,10 +74,20 @@ Add a Misc->Throttle block to your flow graph to avoid CPU congestion.''')
Execute this python flow graph.
@return a popen object
"""
- #execute
- cmds = [PYEXEC, '-u', self.get_file_path()] #-u is unbuffered stdio
- if self._generate_options == 'no_gui':
+ #extract the path to the python executable
+ python_exe = sys.executable
+
+ #when using wx gui on mac os, execute with pythonw
+ if self._generate_options == 'wx_gui' and 'darwin' in sys.platform.lower():
+ python_exe += 'w'
+
+ #setup the command args to run
+ cmds = [python_exe, '-u', self.get_file_path()] #-u is unbuffered stdio
+
+ #when in no gui mode on linux, use an xterm (looks nice)
+ if self._generate_options == 'no_gui' and 'linux' in sys.platform.lower():
cmds = ['xterm', '-e'] + cmds
+
p = subprocess.Popen(args=cmds, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=False, universal_newlines=True)
return p
diff --git a/grc/python/Param.py b/grc/python/Param.py
index 303ab3ed8..5536138c1 100644
--- a/grc/python/Param.py
+++ b/grc/python/Param.py
@@ -213,8 +213,7 @@ class Param(_Param, _GUIParam):
lambda p: p._vlen, self.get_parent().get_ports())
):
try:
- assert int(self.get_evaluated()) == 1
- return 'part'
+ if int(self.get_evaluated()) == 1: return 'part'
except: pass
#hide empty grid positions
if self.get_key() in ('grid_pos', 'notebook') and not self.get_value(): return 'part'
@@ -244,8 +243,7 @@ class Param(_Param, _GUIParam):
def eval_string(v):
try:
e = self.get_parent().get_parent().evaluate(v)
- assert isinstance(e, str)
- return e
+ if isinstance(e, str): return e
except:
self._stringify_flag = True
return v
@@ -265,21 +263,21 @@ class Param(_Param, _GUIParam):
#raise an exception if the data is invalid
if t == 'raw': return e
elif t == 'complex':
- try: assert isinstance(e, COMPLEX_TYPES)
- except AssertionError: raise Exception, 'Expression "%s" is invalid for type complex.'%str(e)
+ if not isinstance(e, COMPLEX_TYPES):
+ raise Exception, 'Expression "%s" is invalid for type complex.'%str(e)
return e
elif t == 'real':
- try: assert isinstance(e, REAL_TYPES)
- except AssertionError: raise Exception, 'Expression "%s" is invalid for type real.'%str(e)
+ if not isinstance(e, REAL_TYPES):
+ raise Exception, 'Expression "%s" is invalid for type real.'%str(e)
return e
elif t == 'int':
- try: assert isinstance(e, INT_TYPES)
- except AssertionError: raise Exception, 'Expression "%s" is invalid for type integer.'%str(e)
+ if not isinstance(e, INT_TYPES):
+ raise Exception, 'Expression "%s" is invalid for type integer.'%str(e)
return e
elif t == 'hex': return hex(e)
elif t == 'bool':
- try: assert isinstance(e, bool)
- except AssertionError: raise Exception, 'Expression "%s" is invalid for type bool.'%str(e)
+ if not isinstance(e, bool):
+ raise Exception, 'Expression "%s" is invalid for type bool.'%str(e)
return e
else: raise TypeError, 'Type "%s" not handled'%t
#########################
@@ -295,25 +293,22 @@ class Param(_Param, _GUIParam):
if not isinstance(e, VECTOR_TYPES):
self._lisitify_flag = True
e = [e]
- try:
- for ei in e: assert isinstance(ei, COMPLEX_TYPES)
- except AssertionError: raise Exception, 'Expression "%s" is invalid for type complex vector.'%str(e)
+ if not all([isinstance(ei, COMPLEX_TYPES) for ei in e]):
+ raise Exception, 'Expression "%s" is invalid for type complex vector.'%str(e)
return e
elif t == 'real_vector':
if not isinstance(e, VECTOR_TYPES):
self._lisitify_flag = True
e = [e]
- try:
- for ei in e: assert isinstance(ei, REAL_TYPES)
- except AssertionError: raise Exception, 'Expression "%s" is invalid for type real vector.'%str(e)
+ if not all([isinstance(ei, REAL_TYPES) for ei in e]):
+ raise Exception, 'Expression "%s" is invalid for type real vector.'%str(e)
return e
elif t == 'int_vector':
if not isinstance(e, VECTOR_TYPES):
self._lisitify_flag = True
e = [e]
- try:
- for ei in e: assert isinstance(ei, INT_TYPES)
- except AssertionError: raise Exception, 'Expression "%s" is invalid for type integer vector.'%str(e)
+ if not all([isinstance(ei, INT_TYPES) for ei in e]):
+ raise Exception, 'Expression "%s" is invalid for type integer vector.'%str(e)
return e
#########################
# String Types
@@ -327,13 +322,13 @@ class Param(_Param, _GUIParam):
#########################
elif t == 'id':
#can python use this as a variable?
- try: assert _check_id_matcher.match(v)
- except AssertionError: raise Exception, 'ID "%s" must begin with a letter and may contain letters, numbers, and underscores.'%v
+ if not _check_id_matcher.match(v):
+ raise Exception, 'ID "%s" must begin with a letter and may contain letters, numbers, and underscores.'%v
ids = [param.get_value() for param in self.get_all_params(t)]
- try: assert ids.count(v) <= 1 #id should only appear once, or zero times if block is disabled
- except: raise Exception, 'ID "%s" is not unique.'%v
- try: assert v not in ID_BLACKLIST
- except: raise Exception, 'ID "%s" is blacklisted.'%v
+ if ids.count(v) > 1: #id should only appear once, or zero times if block is disabled
+ raise Exception, 'ID "%s" is not unique.'%v
+ if v in ID_BLACKLIST:
+ raise Exception, 'ID "%s" is blacklisted.'%v
return v
#########################
# Stream ID Type
@@ -346,12 +341,12 @@ class Param(_Param, _GUIParam):
)]
#check that the virtual sink's stream id is unique
if self.get_parent().is_virtual_sink():
- try: assert ids.count(v) <= 1 #id should only appear once, or zero times if block is disabled
- except: raise Exception, 'Stream ID "%s" is not unique.'%v
+ if ids.count(v) > 1: #id should only appear once, or zero times if block is disabled
+ raise Exception, 'Stream ID "%s" is not unique.'%v
#check that the virtual source's steam id is found
if self.get_parent().is_virtual_source():
- try: assert v in ids
- except: raise Exception, 'Stream ID "%s" is not found.'%v
+ if v not in ids:
+ raise Exception, 'Stream ID "%s" is not found.'%v
return v
#########################
# GUI Position/Hint
@@ -382,17 +377,15 @@ class Param(_Param, _GUIParam):
elif t == 'grid_pos':
if not v: return '' #allow for empty grid pos
e = self.get_parent().get_parent().evaluate(v)
- try:
- assert isinstance(e, (list, tuple)) and len(e) == 4
- for ei in e: assert isinstance(ei, int)
- except AssertionError: raise Exception, 'A grid position must be a list of 4 integers.'
+ if not isinstance(e, (list, tuple)) or len(e) != 4 or not all([isinstance(ei, int) for ei in e]):
+ raise Exception, 'A grid position must be a list of 4 integers.'
row, col, row_span, col_span = e
#check row, col
- try: assert row >= 0 and col >= 0
- except AssertionError: raise Exception, 'Row and column must be non-negative.'
+ if row < 0 or col < 0:
+ raise Exception, 'Row and column must be non-negative.'
#check row span, col span
- try: assert row_span > 0 and col_span > 0
- except AssertionError: raise Exception, 'Row and column span must be greater than zero.'
+ if row_span <= 0 or col_span <= 0:
+ raise Exception, 'Row and column span must be greater than zero.'
#get hostage cell parent
try: my_parent = self.get_parent().get_param('notebook').evaluate()
except: my_parent = ''
@@ -421,8 +414,8 @@ class Param(_Param, _GUIParam):
try: notebook_block = filter(lambda b: b.get_id() == notebook_id, notebook_blocks)[0]
except: raise Exception, 'Notebook id "%s" is not an existing notebook id.'%notebook_id
#check that page index exists
- try: assert int(page_index) in range(len(notebook_block.get_param('labels').evaluate()))
- except: raise Exception, 'Page index "%s" is not a valid index number.'%page_index
+ if int(page_index) not in range(len(notebook_block.get_param('labels').evaluate())):
+ raise Exception, 'Page index "%s" is not a valid index number.'%page_index
return notebook_id, page_index
#########################
# Import Type
diff --git a/grc/python/Platform.py b/grc/python/Platform.py
index ec3f94096..a9c2b18ad 100644
--- a/grc/python/Platform.py
+++ b/grc/python/Platform.py
@@ -1,5 +1,5 @@
-"""
-Copyright 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+__doc__ = """
+Copyright 2008-2011 Free Software Foundation, Inc.
This file is part of GNU Radio
GNU Radio Companion is free software; you can redistribute it and/or
diff --git a/grc/python/Port.py b/grc/python/Port.py
index 6e5a5c59f..3846b0f4e 100644
--- a/grc/python/Port.py
+++ b/grc/python/Port.py
@@ -1,5 +1,5 @@
"""
-Copyright 2008, 2009 Free Software Foundation, Inc.
+Copyright 2008-2011 Free Software Foundation, Inc.
This file is part of GNU Radio
GNU Radio Companion is free software; you can redistribute it and/or
@@ -83,16 +83,16 @@ class Port(_Port, _GUIPort):
def validate(self):
_Port.validate(self)
- try: assert self.get_enabled_connections() or self.get_optional()
- except AssertionError: self.add_error_message('Port is not connected.')
- try: assert self.is_source() or len(self.get_enabled_connections()) <= 1
- except AssertionError: self.add_error_message('Port has too many connections.')
+ if not self.get_enabled_connections() and not self.get_optional():
+ self.add_error_message('Port is not connected.')
+ if not self.is_source() and len(self.get_enabled_connections()) > 1:
+ self.add_error_message('Port has too many connections.')
#message port logic
if self.get_type() == 'msg':
- try: assert not self.get_nports()
- except AssertionError: self.add_error_message('A port of type "msg" cannot have "nports" set.')
- try: assert self.get_vlen() == 1
- except AssertionError: self.add_error_message('A port of type "msg" must have a "vlen" of 1.')
+ if self.get_nports():
+ self.add_error_message('A port of type "msg" cannot have "nports" set.')
+ if self.get_vlen() != 1:
+ self.add_error_message('A port of type "msg" must have a "vlen" of 1.')
def rewrite(self):
"""
@@ -134,8 +134,7 @@ class Port(_Port, _GUIPort):
if not nports: return ''
try:
nports = int(self.get_parent().get_parent().evaluate(nports))
- assert 0 < nports
- return nports
+ if 0 < nports: return nports
except: return 1
def get_optional(self): return bool(self._optional)
diff --git a/grc/python/expr_utils.py b/grc/python/expr_utils.py
index 3c39f5d89..a2e56eedf 100644
--- a/grc/python/expr_utils.py
+++ b/grc/python/expr_utils.py
@@ -1,5 +1,5 @@
"""
-Copyright 2008, 2009 Free Software Foundation, Inc.
+Copyright 2008-2011 Free Software Foundation, Inc.
This file is part of GNU Radio
GNU Radio Companion is free software; you can redistribute it and/or
@@ -118,7 +118,7 @@ def sort_variables(exprs):
Get a list of variables in order of dependencies.
@param exprs a mapping of variable name to expression
@return a list of variable names
- @throws AssertionError circular dependencies
+ @throws Exception circular dependencies
"""
var_graph = get_graph(exprs)
sorted_vars = list()
@@ -126,7 +126,7 @@ def sort_variables(exprs):
while var_graph.get_nodes():
#get a list of nodes with no edges
indep_vars = filter(lambda var: not var_graph.get_edges(var), var_graph.get_nodes())
- assert indep_vars
+ if not indep_vars: raise Exception('circular dependency caught in sort_variables')
#add the indep vars to the end of the list
sorted_vars.extend(sorted(indep_vars))
#remove each edge-less node from the graph
diff --git a/grc/python/extract_docs.py b/grc/python/extract_docs.py
index f41f415b2..aa85397f9 100644
--- a/grc/python/extract_docs.py
+++ b/grc/python/extract_docs.py
@@ -1,5 +1,5 @@
"""
-Copyright 2008, 2009 Free Software Foundation, Inc.
+Copyright 2008-2011 Free Software Foundation, Inc.
This file is part of GNU Radio
GNU Radio Companion is free software; you can redistribute it and/or
@@ -81,8 +81,8 @@ def extract(key):
@param key the block key
@return a string with documentation
"""
- try: assert _docs_cache.has_key(key)
- except: _docs_cache[key] = _extract(key)
+ if not _docs_cache.has_key(key):
+ _docs_cache[key] = _extract(key)
return _docs_cache[key]
if __name__ == '__main__':