commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] [gnuradio] 02/04: grc: also read user default flow gra


From: git
Subject: [Commit-gnuradio] [gnuradio] 02/04: grc: also read user default flow graph from env
Date: Wed, 3 Aug 2016 16:50:26 +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 b18c00c327446c1c2c7431f304f60f7537564bea
Author: Sebastian Koslowski <address@hidden>
Date:   Tue Aug 2 09:40:14 2016 +0200

    grc: also read user default flow graph from env
---
 grc/core/Config.py    | 13 ++++++++++++-
 grc/core/Constants.py |  2 +-
 grc/core/Platform.py  | 10 +++-------
 grc/grc.conf.in       |  1 +
 4 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/grc/core/Config.py b/grc/core/Config.py
index ac38d99..78ff344 100644
--- a/grc/core/Config.py
+++ b/grc/core/Config.py
@@ -20,6 +20,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
 02110-1301, USA
 import os
 from os.path import expanduser, normpath, expandvars, exists
 
+from . import Constants
+
 
 class Config(object):
 
@@ -28,7 +30,7 @@ class Config(object):
     license = __doc__.strip()
     website = 'http://gnuradio.org'
 
-    hier_block_lib_dir = os.environ.get('GRC_HIER_PATH', 
expanduser('~/.grc_gnuradio'))
+    hier_block_lib_dir = os.environ.get('GRC_HIER_PATH', 
Constants.DEFAULT_HIER_BLOCK_LIB_DIR)
 
     def __init__(self, prefs_file, version, version_parts=None):
         self.prefs = prefs_file
@@ -53,3 +55,12 @@ class Config(object):
                        for path in collected_paths if exists(path)]
 
         return valid_paths
+
+    @property
+    def default_flow_graph(self):
+        user_default = (
+            os.environ.get('GRC_DEFAULT_FLOW_GRAPH') or
+            self.prefs.get_string('grc', 'default_flow_graph', '') or
+            os.path.join(self.hier_block_lib_dir, 'default_flow_graph.grc')
+        )
+        return user_default if exists(user_default) else 
Constants.DEFAULT_FLOW_GRAPH
diff --git a/grc/core/Constants.py b/grc/core/Constants.py
index 808ff12..61a44d0 100644
--- a/grc/core/Constants.py
+++ b/grc/core/Constants.py
@@ -27,7 +27,7 @@ FLOW_GRAPH_DTD = os.path.join(DATA_DIR, 'flow_graph.dtd')
 BLOCK_TREE_DTD = os.path.join(DATA_DIR, 'block_tree.dtd')
 BLOCK_DTD = os.path.join(DATA_DIR, 'block.dtd')
 DEFAULT_FLOW_GRAPH = os.path.join(DATA_DIR, 'default_flow_graph.grc')
-USER_DEFAULT_FLOW_GRAPH = 
os.path.expanduser('~/.grc_gnuradio/default_flow_graph.grc')
+DEFAULT_HIER_BLOCK_LIB_DIR = os.path.expanduser('~/.grc_gnuradio')
 DOMAIN_DTD = os.path.join(DATA_DIR, 'domain.dtd')
 
 # File format versions:
diff --git a/grc/core/Platform.py b/grc/core/Platform.py
index 557ceba..0dc6eb0 100644
--- a/grc/core/Platform.py
+++ b/grc/core/Platform.py
@@ -60,10 +60,6 @@ class Platform(Element):
             callback_finished=lambda: self.block_docstrings_loaded_callback()
         )
 
-        self._block_dtd = Constants.BLOCK_DTD
-        self._default_flow_graph = Constants.USER_DEFAULT_FLOW_GRAPH if \
-            os.path.exists(Constants.USER_DEFAULT_FLOW_GRAPH) else 
Constants.DEFAULT_FLOW_GRAPH
-
         # Create a dummy flow graph for the blocks
         self._flow_graph = Element(self)
         self._flow_graph.connections = []
@@ -189,7 +185,7 @@ class Platform(Element):
     def load_block_xml(self, xml_file):
         """Load block description from xml file"""
         # Validate and import
-        ParseXML.validate_dtd(xml_file, self._block_dtd)
+        ParseXML.validate_dtd(xml_file, Constants.BLOCK_DTD)
         n = ParseXML.from_file(xml_file).find('block')
         n['block_wrapper_path'] = xml_file  # inject block wrapper path
         # Get block instance and add it to the list of blocks
@@ -292,8 +288,8 @@ class Platform(Element):
             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
+        flow_graph_file = flow_graph_file or self.config.default_flow_graph
+        open(flow_graph_file, 'r').close()  # Test open
         ParseXML.validate_dtd(flow_graph_file, Constants.FLOW_GRAPH_DTD)
         return ParseXML.from_file(flow_graph_file)
 
diff --git a/grc/grc.conf.in b/grc/grc.conf.in
index 71c4f63..1dbb13b 100644
--- a/grc/grc.conf.in
+++ b/grc/grc.conf.in
@@ -5,6 +5,7 @@
 [grc]
 global_blocks_path = @blocksdir@
 local_blocks_path =
+default_flow_graph =
 xterm_executable = @GRC_XTERM_EXE@
 canvas_font_size = 8
 canvas_default_size = 1280, 1024



reply via email to

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