[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] [gnuradio] 01/22: grc: add domain xml DTD and parsing
From: |
git |
Subject: |
[Commit-gnuradio] [gnuradio] 01/22: grc: add domain xml DTD and parsing |
Date: |
Tue, 23 Dec 2014 09:38:56 +0000 (UTC) |
This is an automated email from the git hooks/post-receive script.
jcorgan pushed a commit to branch master
in repository gnuradio.
commit 8d579a42871b157a7e360ba89d0925d81950e021
Author: Sebastian Koslowski <address@hidden>
Date: Tue Dec 2 21:52:01 2014 +0100
grc: add domain xml DTD and parsing
---
grc/base/CMakeLists.txt | 1 +
grc/base/Constants.py | 4 ++++
grc/base/Platform.py | 31 ++++++++++++++++++++++++++++-
grc/base/{Constants.py => domain.dtd} | 37 +++++++++++++++++------------------
4 files changed, 53 insertions(+), 20 deletions(-)
diff --git a/grc/base/CMakeLists.txt b/grc/base/CMakeLists.txt
index 1087e84..bdc8a50 100644
--- a/grc/base/CMakeLists.txt
+++ b/grc/base/CMakeLists.txt
@@ -36,6 +36,7 @@ GR_PYTHON_INSTALL(FILES
install(FILES
block_tree.dtd
+ domain.dtd
flow_graph.dtd
DESTINATION ${GR_PYTHON_DIR}/gnuradio/grc/base
COMPONENT "grc"
diff --git a/grc/base/Constants.py b/grc/base/Constants.py
index 75a6560..15f72ad 100644
--- a/grc/base/Constants.py
+++ b/grc/base/Constants.py
@@ -32,3 +32,7 @@ FLOW_GRAPH_FILE_FORMAT_VERSION = 1
# Param tabs
DEFAULT_PARAM_TAB = "General"
ADVANCED_PARAM_TAB = "Advanced"
+
+# Port domains
+DEFAULT_DOMAIN ="gr_stream"
+DOMAIN_DTD = os.path.join(DATA_DIR, 'domain.dtd')
diff --git a/grc/base/Platform.py b/grc/base/Platform.py
index 095b70c..91969b2 100644
--- a/grc/base/Platform.py
+++ b/grc/base/Platform.py
@@ -26,7 +26,7 @@ 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
+from Constants import BLOCK_TREE_DTD, FLOW_GRAPH_DTD, DOMAIN_DTD,
DEFAULT_DOMAIN
class Platform(_Element):
@@ -74,6 +74,8 @@ class Platform(_Element):
self._blocks = None
self._blocks_n = None
self._category_trees_n = None
+ self._domains = dict()
+ self._connection_templates = dict()
self.load_blocks()
def load_blocks(self):
@@ -82,12 +84,16 @@ class Platform(_Element):
self._blocks = odict()
self._blocks_n = odict()
self._category_trees_n = list()
+ self._domains.clear()
+ self._connection_templates.clear()
ParseXML.xml_failures.clear()
# try to parse and load blocks
for xml_file in self.iter_xml_files():
try:
if xml_file.endswith("block_tree.xml"):
self.load_category_tree_xml(xml_file)
+ elif xml_file.endswith('domain.xml'):
+ self.load_domain_xml(xml_file)
else:
self.load_block_xml(xml_file)
except ParseXML.XMLSyntaxError as e:
@@ -128,6 +134,25 @@ class Platform(_Element):
n = ParseXML.from_file(xml_file).find('cat')
self._category_trees_n.append(n)
+ def load_domain_xml(self, xml_file):
+ ParseXML.validate_dtd(xml_file, DOMAIN_DTD)
+ n = ParseXML.from_file(xml_file).find('domain')
+
+ key = n.find('key')
+ if key in self.get_domains(): # test against repeated keys
+ print >> sys.stderr, 'Warning: Domain with key "%s" already
exists.\n\tIgnoring: %s' % (key, xml_file)
+ return
+
+ self._domains[key] = dict(
+ name=n.find('name') or key,
+ multiple_sinks=n.find('multiple_sinks') or True
+ )
+ for connection_n in n.findall('connection'):
+ source_domain = connection_n.find('source_domain') or
DEFAULT_DOMAIN
+ sink_domain = connection_n.find('sink_domain') or DEFAULT_DOMAIN
+ make = connection_n.find('make') or ''
+ self._connection_templates[(source_domain, sink_domain)] = make
+
def parse_flow_graph(self, flow_graph_file):
"""
Parse a saved flow graph file.
@@ -197,6 +222,10 @@ class Platform(_Element):
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_domains(self): return self._domains
+ def get_domain(self, key): return self._domains[key]
+ def get_connection_templates(self): return self._connection_templates
+
def get_name(self): return self._name
def get_version(self): return self._version
def get_version_major(self): return self._version_major
diff --git a/grc/base/Constants.py b/grc/base/domain.dtd
similarity index 61%
copy from grc/base/Constants.py
copy to grc/base/domain.dtd
index 75a6560..b13e1a7 100644
--- a/grc/base/Constants.py
+++ b/grc/base/domain.dtd
@@ -1,5 +1,5 @@
-"""
-Copyright 2008, 2009 Free Software Foundation, Inc.
+<!--
+Copyright 2008 Free Software Foundation, Inc.
This file is part of GNU Radio
GNU Radio Companion is free software; you can redistribute it and/or
@@ -15,20 +15,19 @@ 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
-
-#data files
-DATA_DIR = os.path.dirname(__file__)
-FLOW_GRAPH_DTD = os.path.join(DATA_DIR, 'flow_graph.dtd')
-BLOCK_TREE_DTD = os.path.join(DATA_DIR, 'block_tree.dtd')
-
-# file format versions:
-# 0: undefined / legacy
-# 1: non-numeric message port keys (label is used instead)
-FLOW_GRAPH_FILE_FORMAT_VERSION = 1
-
-# Param tabs
-DEFAULT_PARAM_TAB = "General"
-ADVANCED_PARAM_TAB = "Advanced"
+-->
+<!ELEMENT domain (name, key, multiple_sinks?, connection*)>
+<!--
+ Sub level elements.
+ -->
+<!ELEMENT connection (source_domain, sink_domain, make)>
+<!--
+ Bottom level elements.
+ Character data only.
+ -->
+<!ELEMENT name (#PCDATA)>
+<!ELEMENT key (#PCDATA)>
+<!ELEMENT multiple_sinks (#PCDATA)>
+<!ELEMENT make (#PCDATA)>
+<!ELEMENT source_domain (#PCDATA)>
+<!ELEMENT sink_domain (#PCDATA)>
- [Commit-gnuradio] [gnuradio] 09/22: grc: make Generator use gr_message domain, (continued)
- [Commit-gnuradio] [gnuradio] 09/22: grc: make Generator use gr_message domain, git, 2014/12/23
- [Commit-gnuradio] [gnuradio] 03/22: grc: draw ports with custom domain differently, git, 2014/12/23
- [Commit-gnuradio] [gnuradio] 22/22: Merge remote-tracking branch 'gnuradio-wg-grc/master_grcwg', git, 2014/12/23
- [Commit-gnuradio] [gnuradio] 04/22: grc: don't fail for unknown domains, git, 2014/12/23
- [Commit-gnuradio] [gnuradio] 19/22: Merge branch 'port_domains' into master_grcwg, git, 2014/12/23
- [Commit-gnuradio] [gnuradio] 05/22: grc: use domain connection templates in Generator, git, 2014/12/23
- [Commit-gnuradio] [gnuradio] 21/22: Merge remote-tracking branch 'skoslowski/msg_connect_extended', git, 2014/12/23
- [Commit-gnuradio] [gnuradio] 18/22: grc: port domain code clean-up, git, 2014/12/23
- [Commit-gnuradio] [gnuradio] 20/22: Merge branch 'maint', git, 2014/12/23
- [Commit-gnuradio] [gnuradio] 02/22: grc: add domain attribute to ports, git, 2014/12/23
- [Commit-gnuradio] [gnuradio] 01/22: grc: add domain xml DTD and parsing,
git <=