From 63c928575c10741ac6a6c3c3c8be9c238e7b8432 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 17 Aug 2009 00:54:11 -0700 Subject: Removed Source and Sink classes as Port subclasses. A port can be a source or a sink based on the dir parameter. --- grc/base/Block.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'grc/base/Block.py') diff --git a/grc/base/Block.py b/grc/base/Block.py index d5e104785..82d276567 100644 --- a/grc/base/Block.py +++ b/grc/base/Block.py @@ -98,7 +98,7 @@ class Block(Element): self.get_params().append(param) #create the source objects self._sources = list() - for source in map(lambda n: self.get_parent().get_parent().Source(self, n), sources): + for source in map(lambda n: self.get_parent().get_parent().Port(self, n, dir='source'), sources): key = source.get_key() #test against repeated keys try: assert key not in self.get_source_keys() @@ -107,7 +107,7 @@ class Block(Element): self.get_sources().append(source) #create the sink objects self._sinks = list() - for sink in map(lambda n: self.get_parent().get_parent().Sink(self, n), sinks): + for sink in map(lambda n: self.get_parent().get_parent().Port(self, n, dir='sink'), sinks): key = sink.get_key() #test against repeated keys try: assert key not in self.get_sink_keys() -- cgit From bf232a6e6e73d156c9a46c26842480352c6794c0 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 20 Aug 2009 01:30:23 -0700 Subject: added continuation mode for pad source and sinks --- grc/base/Block.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'grc/base/Block.py') diff --git a/grc/base/Block.py b/grc/base/Block.py index 82d276567..349e71f76 100644 --- a/grc/base/Block.py +++ b/grc/base/Block.py @@ -47,7 +47,9 @@ class TemplateArg(UserDict): return self._param.get_evaluated() def _get_keys(lst): return [elem.get_key() for elem in lst] -def _get_elem(lst, key): return lst[_get_keys(lst).index(key)] +def _get_elem(lst, key): + try: return lst[_get_keys(lst).index(key)] + except ValueError: raise ValueError, 'Key "%s" not found in %s.'%(key, _get_keys(lst)) class Block(Element): -- cgit From 854bed10dfb61e9f9feab5259a75e809941089ab Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 26 Aug 2009 11:23:23 -0700 Subject: Added virtual sink and logic to clone port. Tweaks to the base validation routines. Validate twice in the update until rewrite functions are implemented. --- grc/base/Block.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'grc/base/Block.py') diff --git a/grc/base/Block.py b/grc/base/Block.py index 349e71f76..491c594cc 100644 --- a/grc/base/Block.py +++ b/grc/base/Block.py @@ -145,13 +145,12 @@ class Block(Element): Validate the block. All ports and params must be valid. All checks must evaluate to true. + Validate the params, ports, and the connections to this block. """ Element.validate(self) for c in self.get_params() + self.get_ports() + self.get_connections(): - try: - c.validate() - assert c.is_valid() - except AssertionError: + c.validate() + if not c.is_valid(): for msg in c.get_error_messages(): self.add_error_message('>>> %s:\n\t%s'%(c, msg)) -- cgit From dc9e9db16047ec589a7b0488fac04c5bb682903c Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 26 Aug 2009 13:29:28 -0700 Subject: added rewrite methods to element to separate from validation logic --- grc/base/Block.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'grc/base/Block.py') diff --git a/grc/base/Block.py b/grc/base/Block.py index 491c594cc..d2266e783 100644 --- a/grc/base/Block.py +++ b/grc/base/Block.py @@ -140,6 +140,14 @@ class Block(Element): """ self.get_param('_enabled').set_value(str(enabled)) + def rewrite(self): + """ + Rewrite critical structures. + Call rewrite on all sub elements. + """ + Element.rewrite(self) + for elem in self.get_ports() + self.get_params(): elem.rewrite() + def validate(self): """ Validate the block. -- cgit From 576d3978c7fafe5d6727c77281e3aad6d92074d2 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 29 Aug 2009 01:04:58 -0700 Subject: Replaced TYPES in Port and Param with types parameter. Replaced odict in options for storing options with a list. Fix virtual port check in flow graph template. --- grc/base/Block.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'grc/base/Block.py') diff --git a/grc/base/Block.py b/grc/base/Block.py index d2266e783..737010305 100644 --- a/grc/base/Block.py +++ b/grc/base/Block.py @@ -91,7 +91,7 @@ class Block(Element): 'hide': 'all', }) )) - for param in map(lambda n: self.get_parent().get_parent().Param(self, n), params): + 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() @@ -100,7 +100,7 @@ class Block(Element): self.get_params().append(param) #create the source objects self._sources = list() - for source in map(lambda n: self.get_parent().get_parent().Port(self, n, dir='source'), sources): + 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() @@ -109,7 +109,7 @@ class Block(Element): self.get_sources().append(source) #create the sink objects self._sinks = list() - for sink in map(lambda n: self.get_parent().get_parent().Port(self, n, dir='sink'), sinks): + 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() -- cgit From 152fcbc219cd2e4f6df7b38843844bc85fdf2bc2 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sun, 30 Aug 2009 10:34:10 -0700 Subject: Switched the python classes to inherit from the base and gui classes. Use only **kwargs so all contructor parameters must be passed with keys. Moved gui input forms classes from base to gui param module. --- grc/base/Block.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'grc/base/Block.py') diff --git a/grc/base/Block.py b/grc/base/Block.py index 737010305..a9dae660a 100644 --- a/grc/base/Block.py +++ b/grc/base/Block.py @@ -74,16 +74,16 @@ class Block(Element): self._params = list() #add the id param self.get_params().append(self.get_parent().get_parent().Param( - self, - odict({ + block=self, + n=odict({ 'name': 'ID', 'key': 'id', 'type': 'id', }) )) self.get_params().append(self.get_parent().get_parent().Param( - self, - odict({ + block=self, + n=odict({ 'name': 'Enabled', 'key': '_enabled', 'type': 'raw', -- cgit From 6b47cc3dc64d86cb19eb28ab4843a0f278db6d0a Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 3 Sep 2009 15:46:07 -0700 Subject: we dont use test() -> remove it --- grc/base/Block.py | 8 -------- 1 file changed, 8 deletions(-) (limited to 'grc/base/Block.py') diff --git a/grc/base/Block.py b/grc/base/Block.py index a9dae660a..fc501205f 100644 --- a/grc/base/Block.py +++ b/grc/base/Block.py @@ -116,14 +116,6 @@ class Block(Element): except AssertionError: raise Exception, 'Key "%s" already exists in sinks'%key #store the port self.get_sinks().append(sink) - #begin the testing - self.test() - - def test(self): - """ - Call test on all children. - """ - map(lambda c: c.test(), self.get_params() + self.get_sinks() + self.get_sources()) def get_enabled(self): """ -- cgit From 58cebfd63726dc2082ab31681afcd78e25c36132 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 5 Sep 2009 00:45:14 -0700 Subject: Implement a recursive validation api in the base Element class. The rewrite and validate methods will invoke themselves on the child elements. The error messages are now a super-list of element and child error messages. As a side-effect, this cleans up code in base Block and Flowgraph class. --- grc/base/Block.py | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) (limited to 'grc/base/Block.py') diff --git a/grc/base/Block.py b/grc/base/Block.py index fc501205f..cb21c3958 100644 --- a/grc/base/Block.py +++ b/grc/base/Block.py @@ -132,28 +132,6 @@ class Block(Element): """ self.get_param('_enabled').set_value(str(enabled)) - def rewrite(self): - """ - Rewrite critical structures. - Call rewrite on all sub elements. - """ - Element.rewrite(self) - for elem in self.get_ports() + self.get_params(): elem.rewrite() - - def validate(self): - """ - Validate the block. - All ports and params must be valid. - All checks must evaluate to true. - Validate the params, ports, and the connections to this block. - """ - Element.validate(self) - for c in self.get_params() + self.get_ports() + self.get_connections(): - c.validate() - if not c.is_valid(): - for msg in c.get_error_messages(): - self.add_error_message('>>> %s:\n\t%s'%(c, msg)) - def __str__(self): return 'Block - %s - %s(%s)'%(self.get_id(), self.get_name(), self.get_key()) def get_id(self): return self.get_param('id').get_value() @@ -163,6 +141,7 @@ class Block(Element): def get_category(self): return self._category def get_doc(self): return '' def get_ports(self): return self.get_sources() + self.get_sinks() + def get_children(self): return self.get_ports() + self.get_params() def get_block_wrapper_path(self): return self._block_wrapper_path ############################################## -- cgit From 24b3c103b859737d086d4813d6d345882b926e81 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 18 Sep 2009 20:37:05 -0700 Subject: bug fix for handling loading of dynamic params --- grc/base/Block.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'grc/base/Block.py') diff --git a/grc/base/Block.py b/grc/base/Block.py index cb21c3958..43f9ba4e9 100644 --- a/grc/base/Block.py +++ b/grc/base/Block.py @@ -233,12 +233,22 @@ class Block(Element): """ Import this block's params from nested data. Any param keys that do not exist will be ignored. + Since params can be dynamically created based another param, + 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 """ - params_n = n.findall('param') - for param_n in params_n: - key = param_n.find('key') - value = param_n.find('value') - #the key must exist in this block's params - if key in self.get_param_keys(): - self.get_param(key).set_value(value) + get_hash = lambda: reduce(lambda x, y: x | y, [hash(param) for param in self.get_params()], 0) + my_hash = 0 + while get_hash() != my_hash: + params_n = n.findall('param') + for param_n in params_n: + key = param_n.find('key') + value = param_n.find('value') + #the key must exist in this block's params + if key in self.get_param_keys(): + self.get_param(key).set_value(value) + #store hash and call rewrite + my_hash = get_hash() + self.rewrite() -- cgit From 803943020c3d53686f2b65a70cd24a780b46c925 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 18 Sep 2009 23:27:06 -0700 Subject: xor that hash --- grc/base/Block.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'grc/base/Block.py') diff --git a/grc/base/Block.py b/grc/base/Block.py index 43f9ba4e9..203e878e4 100644 --- a/grc/base/Block.py +++ b/grc/base/Block.py @@ -239,7 +239,7 @@ class Block(Element): that are needed for the connections creation phase. @param n the nested data odict """ - get_hash = lambda: reduce(lambda x, y: x | y, [hash(param) for param in self.get_params()], 0) + get_hash = lambda: reduce(lambda x, y: x ^ y, [hash(param) for param in self.get_params()], 0) my_hash = 0 while get_hash() != my_hash: params_n = n.findall('param') -- cgit