From 9988664127b367fa8fee4409f8460673d6f265e1 Mon Sep 17 00:00:00 2001 From: jblum Date: Tue, 23 Jun 2009 20:38:18 +0000 Subject: Merging r11186:11273 from grc branch. Fixes, features, and reorganization for grc. Minor fixes and features for wxgui forms. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@11274 221aa14e-8319-0410-a670-987f0aec2ac5 --- grc/base/Platform.py | 174 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 174 insertions(+) create mode 100644 grc/base/Platform.py (limited to 'grc/base/Platform.py') diff --git a/grc/base/Platform.py b/grc/base/Platform.py new file mode 100644 index 000000000..6cbe741dd --- /dev/null +++ b/grc/base/Platform.py @@ -0,0 +1,174 @@ +""" +Copyright 2008, 2009 Free Software Foundation, Inc. +This file is part of GNU Radio + +GNU Radio Companion is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +GNU Radio Companion is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA +""" + +import os +import sys +from .. base import ParseXML +from Element import Element as _Element +from FlowGraph import FlowGraph as _FlowGraph +from Connection import Connection as _Connection +from Block import Block as _Block +from Port import Port as _Port +from Param import Param as _Param +from Constants import BLOCK_TREE_DTD, FLOW_GRAPH_DTD + +class Platform(_Element): + + def __init__(self, name, version, key, + block_paths, block_dtd, default_flow_graph, generator, + 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 + """ + _Element.__init__(self) + self._name = name + self._version = version + self._key = key + self._license = license + self._website = website + self._block_paths = block_paths + self._block_dtd = block_dtd + self._default_flow_graph = default_flow_graph + self._generator = generator + self._colors = colors + #create a dummy flow graph for the blocks + self._flow_graph = _Element(self) + #search for *.xml files in the given search path + xml_files = list() + for block_path in self._block_paths: + if os.path.isfile(block_path): xml_files.append(block_path) + elif os.path.isdir(block_path): + for dirpath, dirnames, filenames in os.walk(block_path): + for filename in filter(lambda f: f.endswith('.xml'), filenames): + xml_files.append(os.path.join(dirpath, filename)) + #load the blocks + self._blocks = dict() + self._blocks_n = dict() + self._block_tree_files = list() + for xml_file in xml_files: + try: #try to add the xml file as a block wrapper + ParseXML.validate_dtd(xml_file, self._block_dtd) + n = ParseXML.from_file(xml_file).find('block') + #inject block wrapper path + n['block_wrapper_path'] = xml_file + 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 + 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) + self._block_tree_files.append(xml_file) + except ParseXML.XMLSyntaxError, e: + print >> sys.stderr, 'Warning: Block validation failed:\n\t%s\n\tIgnoring: %s'%(e, xml_file) + except Exception, e: + print >> sys.stderr, 'Warning: Block loading failed:\n\t%s\n\tIgnoring: %s'%(e, xml_file) + + def parse_flow_graph(self, flow_graph_file): + """ + 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 + @throws exception if the validation fails + """ + flow_graph_file = flow_graph_file or self._default_flow_graph + open(flow_graph_file, 'r') #test open + ParseXML.validate_dtd(flow_graph_file, FLOW_GRAPH_DTD) + return ParseXML.from_file(flow_graph_file) + + def load_block_tree(self, block_tree): + """ + 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 + """ + #recursive function to load categories and blocks + def load_category(cat_n, parent=[]): + #add this category + parent = parent + [cat_n.find('name')] + block_tree.add_block(parent) + #recursive call to load sub categories + map(lambda c: load_category(c, parent), cat_n.findall('cat')) + #add blocks in this category + for block_key in cat_n.findall('block'): + if block_key not in self.get_block_keys(): + print >> sys.stderr, 'Warning: Block key "%s" not found when loading category tree.'%(block_key) + continue + block_tree.add_block(parent, self.get_block(block_key)) + #load the block tree + for block_tree_file in self._block_tree_files: + #recursivly add all blocks in the tree + load_category(ParseXML.from_file(block_tree_file).find('cat')) + #add all other blocks, use the catgory tag + for block in self.get_blocks(): + #blocks with empty categories are in the xml block tree or hidden + if not block.get_category(): continue + block_tree.add_block(block.get_category(), block) + + def __str__(self): return 'Platform - %s(%s)'%(self.get_key(), self.get_name()) + + def is_platform(self): return True + + def get_new_flow_graph(self): return self.FlowGraph(self) + + def get_generator(self): return self._generator + + ############################################## + # Access Blocks + ############################################## + def get_block_keys(self): return self._blocks.keys() + def get_block(self, key): return self._blocks[key] + def get_blocks(self): return self._blocks.values() + def get_new_block(self, flow_graph, key): return self.Block(flow_graph, n=self._blocks_n[key]) + + def get_name(self): return self._name + def get_version(self): return self._version + def get_key(self): return self._key + def get_license(self): return self._license + def get_website(self): return self._website + def get_colors(self): return self._colors + + ############################################## + # Constructors + ############################################## + FlowGraph = _FlowGraph + Connection = _Connection + Block = _Block + Source = _Port + Sink = _Port + Param = _Param -- cgit From 5762d01a3d45b8d500c5ad560c272692d7d46db2 Mon Sep 17 00:00:00 2001 From: jblum Date: Mon, 29 Jun 2009 04:29:36 +0000 Subject: Added ability to extract category names from doxygen. For now, this is commented out until the current block tree is overhauled. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@11304 221aa14e-8319-0410-a670-987f0aec2ac5 --- grc/base/Platform.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'grc/base/Platform.py') diff --git a/grc/base/Platform.py b/grc/base/Platform.py index 6cbe741dd..3050e5e47 100644 --- a/grc/base/Platform.py +++ b/grc/base/Platform.py @@ -19,7 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA import os import sys -from .. base import ParseXML +from .. base import ParseXML, odict from Element import Element as _Element from FlowGraph import FlowGraph as _FlowGraph from Connection import Connection as _Connection @@ -66,11 +66,11 @@ class Platform(_Element): if os.path.isfile(block_path): xml_files.append(block_path) elif os.path.isdir(block_path): for dirpath, dirnames, filenames in os.walk(block_path): - for filename in filter(lambda f: f.endswith('.xml'), filenames): + for filename in sorted(filter(lambda f: f.endswith('.xml'), filenames)): xml_files.append(os.path.join(dirpath, filename)) #load the blocks - self._blocks = dict() - self._blocks_n = dict() + self._blocks = odict() + self._blocks_n = odict() self._block_tree_files = list() for xml_file in xml_files: try: #try to add the xml file as a block wrapper -- cgit From 25c5d91fb7c4b54f1e7d77fd9af213a3675a8339 Mon Sep 17 00:00:00 2001 From: jblum Date: Mon, 6 Jul 2009 02:28:52 +0000 Subject: Merged r11309:11357 from grc branch. Adds notebook cabability to grc and its wxgui windows/controls. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@11358 221aa14e-8319-0410-a670-987f0aec2ac5 --- grc/base/Platform.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'grc/base/Platform.py') diff --git a/grc/base/Platform.py b/grc/base/Platform.py index 3050e5e47..02d6d2319 100644 --- a/grc/base/Platform.py +++ b/grc/base/Platform.py @@ -129,7 +129,9 @@ class Platform(_Element): if block_key not in self.get_block_keys(): print >> sys.stderr, 'Warning: Block key "%s" not found when loading category tree.'%(block_key) continue - block_tree.add_block(parent, self.get_block(block_key)) + block = self.get_block(block_key) + #if it exists, the block's category overrides the block tree + if not block.get_category(): block_tree.add_block(parent, block) #load the block tree for block_tree_file in self._block_tree_files: #recursivly add all blocks in the tree -- cgit 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/Platform.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'grc/base/Platform.py') diff --git a/grc/base/Platform.py b/grc/base/Platform.py index 02d6d2319..db7ade9a3 100644 --- a/grc/base/Platform.py +++ b/grc/base/Platform.py @@ -171,6 +171,5 @@ class Platform(_Element): FlowGraph = _FlowGraph Connection = _Connection Block = _Block - Source = _Port - Sink = _Port + Port = _Port Param = _Param -- 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/Platform.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'grc/base/Platform.py') diff --git a/grc/base/Platform.py b/grc/base/Platform.py index db7ade9a3..51a3b2f87 100644 --- a/grc/base/Platform.py +++ b/grc/base/Platform.py @@ -146,7 +146,7 @@ class Platform(_Element): def is_platform(self): return True - def get_new_flow_graph(self): return self.FlowGraph(self) + def get_new_flow_graph(self): return self.FlowGraph(platform=self) def get_generator(self): return self._generator -- cgit From f2e366cc4c9929cb2ca70038783b98f9672f6abe Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 30 Mar 2011 19:18:35 -0700 Subject: grc: added python checks for weird python interpreters --- grc/base/Platform.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'grc/base/Platform.py') diff --git a/grc/base/Platform.py b/grc/base/Platform.py index 51a3b2f87..096fdec41 100644 --- a/grc/base/Platform.py +++ b/grc/base/Platform.py @@ -1,5 +1,5 @@ """ -Copyright 2008, 2009 Free Software Foundation, Inc. +Copyright 2008, 2009, 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,6 +17,16 @@ 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 -- cgit From 4f41cde8c65a76cfd74d40ec24b530ef3fe4a5f4 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 14 Apr 2011 09:37:27 -0700 Subject: grc: remove integrity checks, we wont need them when I'm done --- grc/base/Platform.py | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'grc/base/Platform.py') diff --git a/grc/base/Platform.py b/grc/base/Platform.py index 096fdec41..0620cf21b 100644 --- a/grc/base/Platform.py +++ b/grc/base/Platform.py @@ -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 -- cgit From 4cdd41c1046cef12601602bd38dc8ebf42d1550d Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 14 Apr 2011 10:05:33 -0700 Subject: grc: replaced asserts in python subdirectory --- grc/base/Platform.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'grc/base/Platform.py') diff --git a/grc/base/Platform.py b/grc/base/Platform.py index 0620cf21b..a6d420799 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 -- cgit From 66d7b23402dd9c366bb6c824d693274ccf3868db Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 14 Apr 2011 10:40:36 -0700 Subject: grc: replaced asserts in base subdirectory --- grc/base/Platform.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'grc/base/Platform.py') diff --git a/grc/base/Platform.py b/grc/base/Platform.py index a6d420799..a66c28ab9 100644 --- a/grc/base/Platform.py +++ b/grc/base/Platform.py @@ -81,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) -- cgit From f919f9dcbb54a08e6e26d6c229ce92fb784fa1b2 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Fri, 13 Apr 2012 18:36:53 -0400 Subject: Removed whitespace and added dtools/bin/remove-whitespace as a tool to do this in the future. The sed script was provided by Moritz Fischer. --- grc/base/Platform.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'grc/base/Platform.py') diff --git a/grc/base/Platform.py b/grc/base/Platform.py index a66c28ab9..94d0077ea 100644 --- a/grc/base/Platform.py +++ b/grc/base/Platform.py @@ -87,7 +87,7 @@ class Platform(_Element): else: self._blocks[key] = block self._blocks_n[key] = n - except ParseXML.XMLSyntaxError, e: + except ParseXML.XMLSyntaxError, e: try: #try to add the xml file as a block tree ParseXML.validate_dtd(xml_file, BLOCK_TREE_DTD) self._block_tree_files.append(xml_file) -- cgit From a07fe1904412af78b3d70a6225e6efe10c9efbe5 Mon Sep 17 00:00:00 2001 From: Tim O'Shea Date: Tue, 25 Sep 2012 11:40:10 -0400 Subject: adding GRC Reload Block XML action --- grc/base/Platform.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'grc/base/Platform.py') diff --git a/grc/base/Platform.py b/grc/base/Platform.py index 94d0077ea..d4b09088b 100644 --- a/grc/base/Platform.py +++ b/grc/base/Platform.py @@ -61,6 +61,10 @@ class Platform(_Element): #create a dummy flow graph for the blocks self._flow_graph = _Element(self) #search for *.xml files in the given search path + + self.loadblocks(); + + def loadblocks(self): xml_files = list() for block_path in self._block_paths: if os.path.isfile(block_path): xml_files.append(block_path) -- cgit