commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] [gnuradio] 01/01: grc: start using file format tags


From: git
Subject: [Commit-gnuradio] [gnuradio] 01/01: grc: start using file format tags
Date: Tue, 26 Aug 2014 21:10:18 +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 76a271ac7d79c7b857e6b47b8d35386eaafde617
Author: Sebastian Koslowski <address@hidden>
Date:   Tue Aug 26 15:34:22 2014 +0200

    grc: start using file format tags
---
 grc/base/Constants.py |  6 +++++-
 grc/base/FlowGraph.py | 29 +++++++++++++++++++++++++----
 grc/base/ParseXML.py  |  2 +-
 3 files changed, 31 insertions(+), 6 deletions(-)

diff --git a/grc/base/Constants.py b/grc/base/Constants.py
index 73f9293..75a6560 100644
--- a/grc/base/Constants.py
+++ b/grc/base/Constants.py
@@ -23,7 +23,11 @@ import os
 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')
-FLOW_GRAPH_FILE_FORMAT_VERSION = 0
+
+# 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"
diff --git a/grc/base/FlowGraph.py b/grc/base/FlowGraph.py
index e51843c..02d1b11 100644
--- a/grc/base/FlowGraph.py
+++ b/grc/base/FlowGraph.py
@@ -265,6 +265,12 @@ class FlowGraph(Element):
         errors = False
         #remove previous elements
         self._elements = list()
+        # set file format
+        try:
+            instructions = n.find('_instructions') or {}
+            file_format = int(instructions.get('format', '0')) or 
self._guess_file_format_1(n)
+        except:
+            file_format = 0
         #use blank data if none provided
         fg_n = n and n.find('flow_graph') or odict()
         blocks_n = fg_n.findall('block')
@@ -303,9 +309,10 @@ class FlowGraph(Element):
                 source_block = self.get_block(source_block_id)
                 sink_block = self.get_block(sink_block_id)
                 # fix old, numeric message ports keys
-                source_key, sink_key = self.update_old_message_port_keys(
-                    source_key, sink_key, source_block, sink_block
-                )
+                if file_format < 1:
+                    source_key, sink_key = self._update_old_message_port_keys(
+                        source_key, sink_key, source_block, sink_block
+                    )
                 #verify the ports
                 if source_key not in source_block.get_source_keys():
                     # dummy blocks learn their ports here
@@ -333,7 +340,7 @@ class FlowGraph(Element):
         return errors
 
     @staticmethod
-    def update_old_message_port_keys(source_key, sink_key, source_block, 
sink_block):
+    def _update_old_message_port_keys(source_key, sink_key, source_block, 
sink_block):
         """Backward compatibility for message port keys
 
         Message ports use their names as key (like in the 'connect' method).
@@ -355,6 +362,20 @@ class FlowGraph(Element):
             pass
         return source_key, sink_key  # do nothing
 
+    @staticmethod
+    def _guess_file_format_1(n):
+        """Try to guess the file format for flow-graph files without version 
tag"""
+        try:
+            has_non_numeric_message_keys = any(not (
+                connection_n.find('source_key').isdigit() and
+                connection_n.find('sink_key').isdigit()
+            ) for connection_n in n.find('flow_graph').findall('connection'))
+            if has_non_numeric_message_keys:
+                return 1
+        except:
+            pass
+        return 0
+
 
 def _initialize_dummy_block(block, block_n):
     """This is so ugly... dummy-fy a block
diff --git a/grc/base/ParseXML.py b/grc/base/ParseXML.py
index 7742e5f..888272a 100644
--- a/grc/base/ParseXML.py
+++ b/grc/base/ParseXML.py
@@ -79,7 +79,7 @@ def from_file(xml_file):
     nested_data['_instructions'] = {}
     xml_instructions = xml.xpath('/processing-instruction()')
     for inst in filter(lambda i: i.target == 'grc', xml_instructions):
-        nested_data['_instructions'] = inst.attrib
+        nested_data['_instructions'] = odict(inst.attrib)
     return nested_data
 
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]