commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] [gnuradio] 03/10: grc: adding version information to f


From: git
Subject: [Commit-gnuradio] [gnuradio] 03/10: grc: adding version information to flowgraph files using XML processing instructions
Date: Tue, 26 Aug 2014 19:40:07 +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 a8c8af1d032f5622168c3b2636800f1e6647267b
Author: Seth Hitefield <address@hidden>
Date:   Wed Jul 2 17:46:31 2014 -0400

    grc: adding version information to flowgraph files using XML processing 
instructions
---
 gnuradio-runtime/include/gnuradio/constants.h | 15 +++++++++
 gnuradio-runtime/lib/constants.cc.in          | 19 +++++++++++
 gnuradio-runtime/swig/constants.i             |  5 +++
 grc/base/ParseXML.py                          | 48 +++++++++++++++++++++++++++
 grc/base/Platform.py                          | 17 ++++++++--
 grc/gui/ActionHandler.py                      |  3 +-
 grc/python/Platform.py                        |  2 +-
 7 files changed, 105 insertions(+), 4 deletions(-)

diff --git a/gnuradio-runtime/include/gnuradio/constants.h 
b/gnuradio-runtime/include/gnuradio/constants.h
index 5e4a20f..416f039 100644
--- a/gnuradio-runtime/include/gnuradio/constants.h
+++ b/gnuradio-runtime/include/gnuradio/constants.h
@@ -54,6 +54,21 @@ namespace gr {
   GR_RUNTIME_API const std::string version();
 
   /*!
+   * \brief return just the major version defined by cmake
+   */
+  GR_RUNTIME_API const std::string major_version();
+
+  /*!
+   * \brief return just the api version defined by cmake
+   */
+  GR_RUNTIME_API const std::string api_version();
+
+  /*!
+   * \brief returnjust the minor version defined by cmake
+   */
+  GR_RUNTIME_API const std::string minor_version();
+
+  /*!
    * \brief return C compiler used to build this version of GNU Radio
    */
   GR_RUNTIME_API const std::string c_compiler();
diff --git a/gnuradio-runtime/lib/constants.cc.in 
b/gnuradio-runtime/lib/constants.cc.in
index c174091..9ba34e3 100644
--- a/gnuradio-runtime/lib/constants.cc.in
+++ b/gnuradio-runtime/lib/constants.cc.in
@@ -58,6 +58,25 @@ namespace gr {
     return "@VERSION@";
   }
 
+  // Return individual parts of the version
+  const std::string
+  major_version()
+  {
+    return "@MAJOR_VERSION@";
+  }
+
+  const std::string
+  api_version()
+  {
+    return "@API_COMPAT@";
+  }
+
+  const std::string
+  minor_version()
+  {
+    return "@MINOR_VERSION@";
+  }
+
   const std::string
   c_compiler()
   {
diff --git a/gnuradio-runtime/swig/constants.i 
b/gnuradio-runtime/swig/constants.i
index d9e5e28..d63c5e6 100644
--- a/gnuradio-runtime/swig/constants.i
+++ b/gnuradio-runtime/swig/constants.i
@@ -6,10 +6,15 @@ namespace gr {
   %rename(prefsdir) prefsdir;
   %rename(build_date) build_date;
   %rename(version) version;
+  %rename(version_info) version_info;
 
   const std::string prefix();
   const std::string sysconfdir();
   const std::string prefsdir();
   const std::string build_date();
   const std::string version();
+  const std::string major_version();
+  const std::string api_version();
+  const std::string minor_version();
+  
 }
diff --git a/grc/base/ParseXML.py b/grc/base/ParseXML.py
index 70af651..78b96ab 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 25d5939..eea381c 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 60fa070..a8c91b4 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 93527a1..3013e59 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',



reply via email to

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