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 From dcd4b6efd6e0a0130fbdc8f8aa5db1bc182e653f Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 25 Sep 2009 12:54:33 -0700 Subject: hash the tuple of hashes to id the current params --- 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 203e878e4..b2015cc40 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: hash(tuple(map(hash, self.get_params()))) my_hash = 0 while get_hash() != my_hash: params_n = n.findall('param') -- cgit