diff options
author | Seth Hitefield <sdhitefield@gmail.com> | 2014-07-02 17:46:31 -0400 |
---|---|---|
committer | Sebastian Koslowski <koslowski@kit.edu> | 2014-08-26 10:40:22 +0200 |
commit | a8c8af1d032f5622168c3b2636800f1e6647267b (patch) | |
tree | 68e52b734b279c80681c26af5009836db40670c2 /grc | |
parent | 3c165ab4a17473de1e642830c74027274f4a5a5c (diff) |
grc: adding version information to flowgraph files using XML processing instructions
Diffstat (limited to 'grc')
-rw-r--r-- | grc/base/ParseXML.py | 48 | ||||
-rw-r--r-- | grc/base/Platform.py | 17 | ||||
-rw-r--r-- | grc/gui/ActionHandler.py | 3 | ||||
-rw-r--r-- | grc/python/Platform.py | 2 |
4 files changed, 66 insertions, 4 deletions
diff --git a/grc/base/ParseXML.py b/grc/base/ParseXML.py index 70af65192d..78b96abfa1 100644 --- a/grc/base/ParseXML.py +++ b/grc/base/ParseXML.py @@ -60,6 +60,32 @@ def validate_dtd(xml_file, dtd_file=None): except etree.LxmlError: raise XMLSyntaxError(dtd.error_log) + +# Parse the file and also return any GRC processing instructions +def from_file_with_instructions(xml_file): + """ + Create nested data from an xml file using the from xml helper. + Also get the grc version information. + + Args: + xml_file: the xml file path + + Returns: + the nested data, grc version information + """ + xml = etree.parse(xml_file) + + # Get the embedded instructions and build a dictionary item + instructions = None + xml_instructions = xml.xpath('/processing-instruction()') + for inst in xml_instructions: + if (inst.target == 'grc'): + instructions = inst.attrib + + nested_data = _from_file(xml.getroot()) + return (nested_data, instructions) + + def from_file(xml_file): """ Create nested data from an xml file using the from xml helper. @@ -111,6 +137,28 @@ def to_file(nested_data, xml_file): open(xml_file, 'w').write(etree.tostring(xml, xml_declaration=True, pretty_print=True)) +def to_file_with_instructions(nested_data, file_path, instructions): + """ + Write to an xml file and insert processing instructions for versioning + + Args: + nested_data: the nested data + xml_file: the xml file path + instructions: array of instructions to add to the xml + """ + xml = _to_file(nested_data)[0] + + # Create the processing instruction from the array + pi_data = "" + for key, value in instructions.iteritems(): + pi_data += str(key) + "=\'" + str(value) + "\' " + pi = etree.ProcessingInstruction('grc', pi_data) + + xml_data = etree.tostring(pi, xml_declaration=True, pretty_print=True) + xml_data += etree.tostring(xml, pretty_print=True) + open(file_path, 'w').write(xml_data) + + def _to_file(nested_data): """ Recursivly parse the nested data into xml tree format. diff --git a/grc/base/Platform.py b/grc/base/Platform.py index 25d5939b02..eea381c7b1 100644 --- a/grc/base/Platform.py +++ b/grc/base/Platform.py @@ -53,7 +53,13 @@ class Platform(_Element): """ _Element.__init__(self) self._name = name - self._version = version + # Save the verion string to the first + self._version = version[0] + self._version_major = version[1] + self._version_api = version[2] + self._version_minor = version[3] + self._version_short = version[1] + "." + version[2] + "." + version[3] + self._key = key self._license = license self._website = website @@ -137,7 +143,8 @@ class Platform(_Element): 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) + (xml, instructions) = ParseXML.from_file_with_instructions(flow_graph_file) + return xml def load_block_tree(self, block_tree): """ @@ -183,6 +190,7 @@ class Platform(_Element): def get_generator(self): return self._generator + ############################################## # Access Blocks ############################################## @@ -193,6 +201,11 @@ class Platform(_Element): def get_name(self): return self._name def get_version(self): return self._version + def get_version_major(self): return self._version_major + def get_version_api(self): return self._version_api + def get_version_minor(self): return self._version_minor + def get_version_short(self): return self._version_short + def get_key(self): return self._key def get_license(self): return self._license def get_website(self): return self._website diff --git a/grc/gui/ActionHandler.py b/grc/gui/ActionHandler.py index 60fa07050d..a8c91b4978 100644 --- a/grc/gui/ActionHandler.py +++ b/grc/gui/ActionHandler.py @@ -449,7 +449,8 @@ class ActionHandler: #otherwise try to save else: try: - ParseXML.to_file(self.get_flow_graph().export_data(), self.get_page().get_file_path()) + instructions = {'created': self.platform.get_version_short(), 'compatible': '3.6.1', 'locked': True} + ParseXML.to_file_with_instructions(self.get_flow_graph().export_data(), self.get_page().get_file_path(), instructions) self.get_flow_graph().grc_file_path = self.get_page().get_file_path() self.get_page().set_saved(True) except IOError: diff --git a/grc/python/Platform.py b/grc/python/Platform.py index 93527a11b9..3013e59400 100644 --- a/grc/python/Platform.py +++ b/grc/python/Platform.py @@ -45,7 +45,7 @@ class Platform(_Platform, _GUIPlatform): _Platform.__init__( self, name='GNU Radio Companion', - version=gr.version(), + version=(gr.version(), gr.major_version(), gr.api_version(), gr.minor_version()), key='grc', license=__doc__.strip(), website='http://gnuradio.org/redmine/wiki/gnuradio/GNURadioCompanion', |