summaryrefslogtreecommitdiff
path: root/grc/base
diff options
context:
space:
mode:
Diffstat (limited to 'grc/base')
-rw-r--r--grc/base/Block.py50
-rw-r--r--grc/base/Connection.py20
-rw-r--r--grc/base/Element.py12
-rw-r--r--grc/base/FlowGraph.py66
-rw-r--r--grc/base/Param.py14
-rw-r--r--grc/base/ParseXML.py36
-rw-r--r--grc/base/Platform.py38
-rw-r--r--grc/base/Port.py16
-rw-r--r--grc/base/odict.py32
9 files changed, 202 insertions, 82 deletions
diff --git a/grc/base/Block.py b/grc/base/Block.py
index fe7ad3c2f3..3c61bc90e3 100644
--- a/grc/base/Block.py
+++ b/grc/base/Block.py
@@ -54,9 +54,13 @@ class Block(Element):
def __init__(self, flow_graph, n):
"""
Make a new block from nested data.
- @param flow graph the parent element
- @param n the nested odict
- @return block a new block
+
+ Args:
+ flow: graph the parent element
+ n: the nested odict
+
+ Returns:
+ block a new block
"""
#build the block
Element.__init__(self, flow_graph)
@@ -118,7 +122,9 @@ class Block(Element):
def get_enabled(self):
"""
Get the enabled state of the block.
- @return true for enabled
+
+ Returns:
+ true for enabled
"""
try: return eval(self.get_param('_enabled').get_value())
except: return True
@@ -126,7 +132,9 @@ class Block(Element):
def set_enabled(self, enabled):
"""
Set the enabled state of the block.
- @param enabled true for enabled
+
+ Args:
+ enabled: true for enabled
"""
self.get_param('_enabled').set_value(str(enabled))
@@ -169,8 +177,12 @@ class Block(Element):
def resolve_dependencies(self, tmpl):
"""
Resolve a paramater dependency with cheetah templates.
- @param tmpl the string with dependencies
- @return the resolved value
+
+ Args:
+ tmpl: the string with dependencies
+
+ Returns:
+ the resolved value
"""
tmpl = str(tmpl)
if '$' not in tmpl: return tmpl
@@ -184,8 +196,12 @@ class Block(Element):
def type_controller_modify(self, direction):
"""
Change the type controller.
- @param direction +1 or -1
- @return true for change
+
+ Args:
+ direction: +1 or -1
+
+ Returns:
+ true for change
"""
changed = False
type_param = None
@@ -209,8 +225,12 @@ class Block(Element):
def port_controller_modify(self, direction):
"""
Change the port controller.
- @param direction +1 or -1
- @return true for change
+
+ Args:
+ direction: +1 or -1
+
+ Returns:
+ true for change
"""
return False
@@ -220,7 +240,9 @@ class Block(Element):
def export_data(self):
"""
Export this block's params to nested data.
- @return a nested data odict
+
+ Returns:
+ a nested data odict
"""
n = odict()
n['key'] = self.get_key()
@@ -235,7 +257,9 @@ class Block(Element):
call rewrite, and repeat the load until the params stick.
This call to rewrite will also create any dynamic ports
that are needed for the connections creation phase.
- @param n the nested data odict
+
+ Args:
+ n: the nested data odict
"""
get_hash = lambda: hash(tuple(map(hash, self.get_params())))
my_hash = 0
diff --git a/grc/base/Connection.py b/grc/base/Connection.py
index 3ce7fd07f9..b9afe1434d 100644
--- a/grc/base/Connection.py
+++ b/grc/base/Connection.py
@@ -25,11 +25,15 @@ class Connection(Element):
def __init__(self, flow_graph, porta, portb):
"""
Make a new connection given the parent and 2 ports.
- @param flow_graph the parent of this element
- @param porta a port (any direction)
- @param portb a port (any direction)
+
+ Args:
+ flow_graph: the parent of this element
+ porta: a port (any direction)
+ portb: a port (any direction)
@throws Error cannot make connection
- @return a new connection
+
+ Returns:
+ a new connection
"""
Element.__init__(self, flow_graph)
source = sink = None
@@ -70,7 +74,9 @@ class Connection(Element):
def get_enabled(self):
"""
Get the enabled state of this connection.
- @return true if source and sink blocks are enabled
+
+ Returns:
+ true if source and sink blocks are enabled
"""
return self.get_source().get_parent().get_enabled() and \
self.get_sink().get_parent().get_enabled()
@@ -87,7 +93,9 @@ class Connection(Element):
def export_data(self):
"""
Export this connection's info.
- @return a nested data odict
+
+ Returns:
+ a nested data odict
"""
n = odict()
n['source_block_id'] = self.get_source().get_parent().get_id()
diff --git a/grc/base/Element.py b/grc/base/Element.py
index a57090f3b2..74097eea9a 100644
--- a/grc/base/Element.py
+++ b/grc/base/Element.py
@@ -36,14 +36,18 @@ class Element(object):
def is_valid(self):
"""
Is this element valid?
- @return true when the element is enabled and has no error messages
+
+ Returns:
+ true when the element is enabled and has no error messages
"""
return not self.get_error_messages() or not self.get_enabled()
def add_error_message(self, msg):
"""
Add an error message to the list of errors.
- @param msg the error message string
+
+ Args:
+ msg: the error message string
"""
self._error_messages.append(msg)
@@ -52,7 +56,9 @@ class Element(object):
Get the list of error messages from this element and all of its children.
Do not include the error messages from disabled children.
Cleverly indent the children error messages for printing purposes.
- @return a list of error message strings
+
+ Returns:
+ a list of error message strings
"""
error_messages = list(self._error_messages) #make a copy
for child in filter(lambda c: c.get_enabled(), self.get_children()):
diff --git a/grc/base/FlowGraph.py b/grc/base/FlowGraph.py
index 0ba1f23899..e8c49466d0 100644
--- a/grc/base/FlowGraph.py
+++ b/grc/base/FlowGraph.py
@@ -26,8 +26,12 @@ class FlowGraph(Element):
def __init__(self, platform):
"""
Make a flow graph from the arguments.
- @param platform a platforms with blocks and contrcutors
- @return the flow graph object
+
+ Args:
+ platform: a platforms with blocks and contrcutors
+
+ Returns:
+ the flow graph object
"""
#initialize
Element.__init__(self, platform)
@@ -37,8 +41,12 @@ class FlowGraph(Element):
def _get_unique_id(self, base_id=''):
"""
Get a unique id starting with the base id.
- @param base_id the id starts with this and appends a count
- @return a unique id
+
+ Args:
+ base_id: the id starts with this and appends a count
+
+ Returns:
+ a unique id
"""
index = 0
while True:
@@ -53,8 +61,12 @@ class FlowGraph(Element):
"""
Get the option for a given key.
The option comes from the special options block.
- @param key the param key for the options block
- @return the value held by that param
+
+ Args:
+ key: the param key for the options block
+
+ Returns:
+ the value held by that param
"""
return self._options_block.get_param(key).get_evaluated()
@@ -71,7 +83,9 @@ class FlowGraph(Element):
"""
Get a list of all the elements.
Always ensure that the options block is in the list (only once).
- @return the element list
+
+ Returns:
+ the element list
"""
options_block_count = self._elements.count(self._options_block)
if not options_block_count:
@@ -83,14 +97,18 @@ class FlowGraph(Element):
def get_enabled_blocks(self):
"""
Get a list of all blocks that are enabled.
- @return a list of blocks
+
+ Returns:
+ a list of blocks
"""
return filter(lambda b: b.get_enabled(), self.get_blocks())
def get_enabled_connections(self):
"""
Get a list of all connections that are enabled.
- @return a list of connections
+
+ Returns:
+ a list of connections
"""
return filter(lambda c: c.get_enabled(), self.get_connections())
@@ -98,8 +116,12 @@ class FlowGraph(Element):
"""
Get a new block of the specified key.
Add the block to the list of elements.
- @param key the block key
- @return the new block or None if not found
+
+ Args:
+ key: the block key
+
+ Returns:
+ the new block or None if not found
"""
if key not in self.get_parent().get_block_keys(): return None
block = self.get_parent().get_new_block(self, key)
@@ -109,10 +131,14 @@ class FlowGraph(Element):
def connect(self, porta, portb):
"""
Create a connection between porta and portb.
- @param porta a port
- @param portb another port
+
+ Args:
+ porta: a port
+ portb: another port
@throw Exception bad connection
- @return the new connection
+
+ Returns:
+ the new connection
"""
connection = self.get_parent().Connection(flow_graph=self, porta=porta, portb=portb)
self.get_elements().append(connection)
@@ -138,7 +164,9 @@ class FlowGraph(Element):
def evaluate(self, expr):
"""
Evaluate the expression.
- @param expr the string expression
+
+ Args:
+ expr: the string expression
@throw NotImplementedError
"""
raise NotImplementedError
@@ -150,7 +178,9 @@ class FlowGraph(Element):
"""
Export this flow graph to nested data.
Export all block and connection data.
- @return a nested data odict
+
+ Returns:
+ a nested data odict
"""
import time
n = odict()
@@ -164,7 +194,9 @@ class FlowGraph(Element):
Import blocks and connections into this flow graph.
Clear this flowgraph of all previous blocks and connections.
Any blocks or connections in error will be ignored.
- @param n the nested data odict
+
+ Args:
+ n: the nested data odict
"""
#remove previous elements
self._elements = list()
diff --git a/grc/base/Param.py b/grc/base/Param.py
index c2fa5461ae..76a74d3ed7 100644
--- a/grc/base/Param.py
+++ b/grc/base/Param.py
@@ -63,8 +63,10 @@ class Param(Element):
def __init__(self, block, n):
"""
Make a new param from nested data.
- @param block the parent element
- @param n the nested odict
+
+ Args:
+ block: the parent element
+ n: the nested odict
"""
#grab the data
self._name = n.find('name')
@@ -148,7 +150,9 @@ class Param(Element):
Get the repr (nice string format) for this param.
Just return the value (special case enum).
Derived classes can handle complex formatting.
- @return the string representation
+
+ Returns:
+ the string representation
"""
if self.is_enum(): return self.get_option(self.get_value()).get_name()
return self.get_value()
@@ -173,7 +177,9 @@ class Param(Element):
def export_data(self):
"""
Export this param's key/value.
- @return a nested data odict
+
+ Returns:
+ a nested data odict
"""
n = odict()
n['key'] = self.get_key()
diff --git a/grc/base/ParseXML.py b/grc/base/ParseXML.py
index 078ebd078b..0d19f6b212 100644
--- a/grc/base/ParseXML.py
+++ b/grc/base/ParseXML.py
@@ -29,8 +29,10 @@ class XMLSyntaxError(Exception):
def validate_dtd(xml_file, dtd_file=None):
"""
Validate an xml file against its dtd.
- @param xml_file the xml file
- @param dtd_file the optional dtd file
+
+ Args:
+ xml_file: the xml file
+ dtd_file: the optional dtd file
@throws Exception validation fails
"""
#perform parsing, use dtd validation if dtd file is not specified
@@ -45,8 +47,12 @@ def validate_dtd(xml_file, dtd_file=None):
def from_file(xml_file):
"""
Create nested data from an xml file using the from xml helper.
- @param xml_file the xml file path
- @return the nested data
+
+ Args:
+ xml_file: the xml file path
+
+ Returns:
+ the nested data
"""
xml = etree.parse(xml_file).getroot()
return _from_file(xml)
@@ -54,8 +60,12 @@ def from_file(xml_file):
def _from_file(xml):
"""
Recursivly parse the xml tree into nested data format.
- @param xml the xml tree
- @return the nested data
+
+ Args:
+ xml: the xml tree
+
+ Returns:
+ the nested data
"""
tag = xml.tag
if not len(xml):
@@ -73,8 +83,10 @@ def _from_file(xml):
def to_file(nested_data, xml_file):
"""
Write an xml file and use the to xml helper method to load it.
- @param nested_data the nested data
- @param xml_file the xml file path
+
+ Args:
+ nested_data: the nested data
+ xml_file: the xml file path
"""
xml = _to_file(nested_data)[0]
open(xml_file, 'w').write(etree.tostring(xml, xml_declaration=True, pretty_print=True))
@@ -82,8 +94,12 @@ def to_file(nested_data, xml_file):
def _to_file(nested_data):
"""
Recursivly parse the nested data into xml tree format.
- @param nested_data the nested data
- @return the xml tree filled with child nodes
+
+ Args:
+ nested_data: the nested data
+
+ Returns:
+ the xml tree filled with child nodes
"""
nodes = list()
for key, values in nested_data.iteritems():
diff --git a/grc/base/Platform.py b/grc/base/Platform.py
index 94d0077ea9..d6a3b5dd28 100644
--- a/grc/base/Platform.py
+++ b/grc/base/Platform.py
@@ -35,17 +35,21 @@ class Platform(_Element):
license='', website=None, colors=[]):
"""
Make a platform from the arguments.
- @param name the platform name
- @param version the version string
- @param key the unique platform key
- @param block_paths the file paths to blocks in this platform
- @param block_dtd the dtd validator for xml block wrappers
- @param default_flow_graph the default flow graph file path
- @param generator the generator class for this platform
- @param colors a list of title, color_spec tuples
- @param license a multi-line license (first line is copyright)
- @param website the website url for this platform
- @return a platform object
+
+ Args:
+ name: the platform name
+ version: the version string
+ key: the unique platform key
+ block_paths: the file paths to blocks in this platform
+ block_dtd: the dtd validator for xml block wrappers
+ default_flow_graph: the default flow graph file path
+ generator: the generator class for this platform
+ colors: a list of title, color_spec tuples
+ license: a multi-line license (first line is copyright)
+ website: the website url for this platform
+
+ Returns:
+ a platform object
"""
_Element.__init__(self)
self._name = name
@@ -100,8 +104,12 @@ class Platform(_Element):
"""
Parse a saved flow graph file.
Ensure that the file exists, and passes the dtd check.
- @param flow_graph_file the flow graph file
- @return nested data
+
+ Args:
+ flow_graph_file: the flow graph file
+
+ Returns:
+ nested data
@throws exception if the validation fails
"""
flow_graph_file = flow_graph_file or self._default_flow_graph
@@ -114,7 +122,9 @@ class Platform(_Element):
Load a block tree with categories and blocks.
Step 1: Load all blocks from the xml specification.
Step 2: Load blocks with builtin category specifications.
- @param block_tree the block tree object
+
+ Args:
+ block_tree: the block tree object
"""
#recursive function to load categories and blocks
def load_category(cat_n, parent=[]):
diff --git a/grc/base/Port.py b/grc/base/Port.py
index 7a1b5d4e69..0e58f583c3 100644
--- a/grc/base/Port.py
+++ b/grc/base/Port.py
@@ -24,9 +24,11 @@ class Port(Element):
def __init__(self, block, n, dir):
"""
Make a new port from nested data.
- @param block the parent element
- @param n the nested odict
- @param dir the direction source or sink
+
+ Args:
+ block: the parent element
+ n: the nested odict
+ dir: the direction source or sink
"""
#build the port
Element.__init__(self, block)
@@ -69,7 +71,9 @@ class Port(Element):
def get_connections(self):
"""
Get all connections that use this port.
- @return a list of connection objects
+
+ Returns:
+ a list of connection objects
"""
connections = self.get_parent().get_parent().get_connections()
connections = filter(lambda c: c.get_source() is self or c.get_sink() is self, connections)
@@ -78,6 +82,8 @@ class Port(Element):
def get_enabled_connections(self):
"""
Get all enabled connections that use this port.
- @return a list of connection objects
+
+ Returns:
+ a list of connection objects
"""
return filter(lambda c: c.get_enabled(), self.get_connections())
diff --git a/grc/base/odict.py b/grc/base/odict.py
index 044d04ad78..302583163b 100644
--- a/grc/base/odict.py
+++ b/grc/base/odict.py
@@ -50,9 +50,11 @@ class odict(DictMixin):
"""
Insert the new key, value entry after the entry given by the position key.
If the positional key is None, insert at the end.
- @param pos_key the positional key
- @param key the key for the new entry
- @param val the value for the new entry
+
+ Args:
+ pos_key: the positional key
+ key: the key for the new entry
+ val: the value for the new entry
"""
index = (pos_key is None) and len(self._keys) or self._keys.index(pos_key)
if key in self._keys: raise KeyError('Cannot insert, key "%s" already exists'%str(key))
@@ -63,9 +65,11 @@ class odict(DictMixin):
"""
Insert the new key, value entry before the entry given by the position key.
If the positional key is None, insert at the begining.
- @param pos_key the positional key
- @param key the key for the new entry
- @param val the value for the new entry
+
+ Args:
+ pos_key: the positional key
+ key: the key for the new entry
+ val: the value for the new entry
"""
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))
@@ -75,8 +79,12 @@ class odict(DictMixin):
def find(self, key):
"""
Get the value for this key if exists.
- @param key the key to search for
- @return the value or None
+
+ Args:
+ key: the key to search for
+
+ Returns:
+ the value or None
"""
if self.has_key(key): return self[key]
return None
@@ -84,8 +92,12 @@ class odict(DictMixin):
def findall(self, key):
"""
Get a list of values for this key.
- @param key the key to search for
- @return a list of values or empty list
+
+ Args:
+ key: the key to search for
+
+ Returns:
+ a list of values or empty list
"""
obj = self.find(key)
if obj is None: obj = list()