commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] [gnuradio] 03/13: grc: nicer output of blocks paths an


From: git
Subject: [Commit-gnuradio] [gnuradio] 03/13: grc: nicer output of blocks paths and prefs file
Date: Tue, 15 Apr 2014 23:55:53 +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 14625c6ed115af2206e379bc92ad2adf96f6cff9
Author: Sebastian Koslowski <address@hidden>
Date:   Wed Apr 9 17:41:52 2014 +0200

    grc: nicer output of blocks paths and prefs file
---
 grc/base/Platform.py    |  1 +
 grc/gui/Messages.py     | 11 ++++++++++-
 grc/gui/Platform.py     |  7 ++++++-
 grc/gui/Preferences.py  |  7 ++-----
 grc/python/Constants.py |  5 ++++-
 grc/python/Platform.py  | 27 ++++++++++-----------------
 6 files changed, 33 insertions(+), 25 deletions(-)

diff --git a/grc/base/Platform.py b/grc/base/Platform.py
index 3ff80e8..187a50c 100644
--- a/grc/base/Platform.py
+++ b/grc/base/Platform.py
@@ -196,6 +196,7 @@ class Platform(_Element):
     def get_license(self): return self._license
     def get_website(self): return self._website
     def get_colors(self): return self._colors
+    def get_block_paths(self): return self._block_paths
 
     ##############################################
     # Constructors
diff --git a/grc/gui/Messages.py b/grc/gui/Messages.py
index c470645..2bf488b 100644
--- a/grc/gui/Messages.py
+++ b/grc/gui/Messages.py
@@ -48,7 +48,16 @@ register_messenger(sys.stdout.write)
 # Special functions for specific program functionalities
 ###########################################################################
 def send_init(platform):
-    send("""<<< Welcome to %s %s >>>\n"""%(platform.get_name(), 
platform.get_version()))
+    p = platform
+    send('\n'.join([
+        "<<< Welcome to %s %s >>>" % (p.get_name(), p.get_version()),
+        "",
+        "Preferences file: " + p.get_prefs_file(),
+        "Block paths:"
+    ] + [
+        "\t%s" % path + (" (%s)" % opath if opath != path else "")
+            for path, opath in p.get_block_paths().iteritems()
+    ]) + "\n")
 
 def send_page_switch(file_path):
     send('\nShowing: "%s"\n'%file_path)
diff --git a/grc/gui/Platform.py b/grc/gui/Platform.py
index 6a8175b..db77ff2 100644
--- a/grc/gui/Platform.py
+++ b/grc/gui/Platform.py
@@ -20,4 +20,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
 02110-1301, USA
 from Element import Element
 
 class Platform(Element):
-    def __init__(self): Element.__init__(self)
+    def __init__(self, prefs_file):
+        Element.__init__(self)
+
+        self._prefs_file = prefs_file
+
+    def get_prefs_file(self): return self._prefs_file
\ No newline at end of file
diff --git a/grc/gui/Preferences.py b/grc/gui/Preferences.py
index 061bda9..b15fb97 100644
--- a/grc/gui/Preferences.py
+++ b/grc/gui/Preferences.py
@@ -24,7 +24,6 @@ _platform = None
 _config_parser = ConfigParser.ConfigParser()
 
 def file_extension(): return '.'+_platform.get_key()
-def _prefs_file(): return os.environ.get('GRC_PREFS_PATH', 
os.path.join(os.path.expanduser('~'), file_extension()))
 
 def load(platform):
     global _platform
@@ -32,12 +31,10 @@ def load(platform):
     #create sections
     _config_parser.add_section('main')
     _config_parser.add_section('files_open')
-    print "Reading preferences from:", _prefs_file()
-    try: _config_parser.read(_prefs_file())
+    try: _config_parser.read(_platform.get_prefs_file())
     except: pass
 def save():
-    print "Writing preferences to:", _prefs_file()
-    try: _config_parser.write(open(_prefs_file(), 'w'))
+    try: _config_parser.write(open(_platform.get_prefs_file(), 'w'))
     except: pass
 
 ###########################################################################
diff --git a/grc/python/Constants.py b/grc/python/Constants.py
index 9f27589..79ff8ba 100644
--- a/grc/python/Constants.py
+++ b/grc/python/Constants.py
@@ -25,7 +25,10 @@ _gr_prefs = gr.prefs()
 
 #setup paths
 PATH_SEP = {'/':':', '\\':';'}[os.path.sep]
-HIER_BLOCKS_LIB_DIR = os.path.join(os.path.expanduser('~'), 
os.environ.get('GRC_HIER_PATH', '.grc_gnuradio'))
+HIER_BLOCKS_LIB_DIR = os.environ.get('GRC_HIER_PATH',
+                                     os.path.expanduser('~/.grc_gnuradio'))
+PREFS_FILE = os.environ.get('GRC_PREFS_PATH',
+                            os.path.join(os.path.expanduser('~/.grc')))
 BLOCKS_DIRS = filter( #filter blank strings
     lambda x: x, PATH_SEP.join([
         os.environ.get('GRC_BLOCKS_PATH', ''),
diff --git a/grc/python/Platform.py b/grc/python/Platform.py
index 7e5ad81..f4f55e9 100644
--- a/grc/python/Platform.py
+++ b/grc/python/Platform.py
@@ -30,7 +30,7 @@ from Param import Param as _Param
 from Generator import Generator
 from Constants import \
     HIER_BLOCKS_LIB_DIR, BLOCK_DTD, \
-    DEFAULT_FLOW_GRAPH, BLOCKS_DIRS
+    DEFAULT_FLOW_GRAPH, BLOCKS_DIRS, PREFS_FILE
 import Constants
 
 COLORS = [(name, color) for name, key, sizeof, color in Constants.CORE_TYPES]
@@ -43,21 +43,10 @@ class Platform(_Platform, _GUIPlatform):
         """
         #ensure hier dir
         if not os.path.exists(HIER_BLOCKS_LIB_DIR): 
os.mkdir(HIER_BLOCKS_LIB_DIR)
-        #convert block paths to absolute paths
-        # Create a mapping from the absolute path to what was passed in
-        user_to_abs_path = map(lambda x: (os.path.abspath(x), x), BLOCKS_DIRS)
-        # Keep each unique absolute path and maintain order
-        paths_dict = OrderedDict(user_to_abs_path)
-        # Prepare the ordered, unique absolute path list for _Platform
-        block_paths = paths_dict.keys()
-        # Print out the paths that are used (differently, depending on whether 
they
-        #   were transformed from their original state)
-        print "Block paths:"
-        for p in block_paths:
-            if p != paths_dict[p]:
-                print "\t%s (%s)" % (paths_dict[p], p)
-            else:
-                print "\t%s" % (p)
+        # Convert block paths to absolute paths:
+        # - Create a mapping from the absolute path to what was passed in
+        # - Keep each unique absolute path and maintain order
+        block_paths = OrderedDict(map(lambda x: (os.path.abspath(x), x), 
BLOCKS_DIRS))
         #init
         _Platform.__init__(
             self,
@@ -72,7 +61,11 @@ class Platform(_Platform, _GUIPlatform):
             generator=Generator,
             colors=COLORS,
         )
-        _GUIPlatform.__init__(self)
+
+        _GUIPlatform.__init__(
+            self,
+            prefs_file=PREFS_FILE
+        )
 
     ##############################################
     # Constructors



reply via email to

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