diff options
author | Sebastian Koslowski <koslowski@kit.edu> | 2015-08-12 14:46:00 +0200 |
---|---|---|
committer | Sebastian Koslowski <koslowski@kit.edu> | 2015-08-13 14:00:00 +0200 |
commit | dda4f8306f194ff142d25bbedeb7ee5dabd0f523 (patch) | |
tree | 65c556c2c9175801314ac9fb9b9550cdfaa2ebe0 /grc | |
parent | ce21c31af563bc669085cb1a0a711f58f40c8231 (diff) |
grc: move gui prefs file to ~/.gnuradio/grc.conf
Diffstat (limited to 'grc')
-rw-r--r-- | grc/python/Constants.py | 25 | ||||
-rw-r--r-- | grc/python/Platform.py | 37 |
2 files changed, 42 insertions, 20 deletions
diff --git a/grc/python/Constants.py b/grc/python/Constants.py index 1df1fc492b..02be22a441 100644 --- a/grc/python/Constants.py +++ b/grc/python/Constants.py @@ -18,18 +18,21 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA """ import os +from os.path import expanduser import stat from gnuradio import gr _gr_prefs = gr.prefs() -#setup paths -PATH_SEP = {'/':':', '\\':';'}[os.path.sep] -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 +# setup paths +PATH_SEP = {'/': ':', '\\': ';'}[os.path.sep] + +HIER_BLOCKS_LIB_DIR = os.environ.get('GRC_HIER_PATH', expanduser('~/.grc_gnuradio')) + +PREFS_FILE = os.environ.get('GRC_PREFS_PATH', expanduser('~/.gnuradio/grc.conf')) +PREFS_FILE_OLD = os.environ.get('GRC_PREFS_PATH', expanduser('~/.grc')) + +BLOCKS_DIRS = filter( # filter blank strings lambda x: x, PATH_SEP.join([ os.environ.get('GRC_BLOCKS_PATH', ''), _gr_prefs.get_string('grc', 'local_blocks_path', ''), @@ -37,14 +40,14 @@ BLOCKS_DIRS = filter( #filter blank strings ]).split(PATH_SEP), ) + [HIER_BLOCKS_LIB_DIR] -#user settings +# user settings XTERM_EXECUTABLE = _gr_prefs.get_string('grc', 'xterm_executable', 'xterm') -#file creation modes +# file creation modes TOP_BLOCK_FILE_MODE = stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP | stat.S_IROTH HIER_BLOCK_FILE_MODE = stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IWGRP | stat.S_IROTH -#data files +# data files DATA_DIR = os.path.dirname(__file__) FLOW_GRAPH_TEMPLATE = os.path.join(DATA_DIR, 'flow_graph.tmpl') BLOCK_DTD = os.path.join(DATA_DIR, 'block.dtd') @@ -74,7 +77,7 @@ GRC_COLOR_GREY = '#BDBDBD' GRC_COLOR_WHITE = '#FFFFFF' -CORE_TYPES = ( #name, key, sizeof, color +CORE_TYPES = ( # name, key, sizeof, color ('Complex Float 64', 'fc64', 16, GRC_COLOR_BROWN), ('Complex Float 32', 'fc32', 8, GRC_COLOR_BLUE), ('Complex Integer 64', 'sc64', 16, GRC_COLOR_LIGHT_GREEN), diff --git a/grc/python/Platform.py b/grc/python/Platform.py index feea81dae1..1497099f3f 100644 --- a/grc/python/Platform.py +++ b/grc/python/Platform.py @@ -18,7 +18,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA """ import os +import sys + from gnuradio import gr + from .. base.Platform import Platform as _Platform from .. gui.Platform import Platform as _GUIPlatform from FlowGraph import FlowGraph as _FlowGraph @@ -27,21 +30,26 @@ from Block import Block as _Block from Port import Port as _Port from Param import Param as _Param from Generator import Generator -from Constants import \ - HIER_BLOCKS_LIB_DIR, BLOCK_DTD, \ - DEFAULT_FLOW_GRAPH, BLOCKS_DIRS, PREFS_FILE -import Constants +from Constants import ( + HIER_BLOCKS_LIB_DIR, BLOCK_DTD, DEFAULT_FLOW_GRAPH, BLOCKS_DIRS, + PREFS_FILE, PREFS_FILE_OLD, CORE_TYPES +) + + +COLORS = [(name, color) for name, key, sizeof, color in CORE_TYPES] -COLORS = [(name, color) for name, key, sizeof, color in Constants.CORE_TYPES] class Platform(_Platform, _GUIPlatform): def __init__(self): """ Make a platform for gnuradio. """ - #ensure hier dir - if not os.path.exists(HIER_BLOCKS_LIB_DIR): os.mkdir(HIER_BLOCKS_LIB_DIR) - #init + # ensure hier and conf directories + if not os.path.exists(HIER_BLOCKS_LIB_DIR): + os.mkdir(HIER_BLOCKS_LIB_DIR) + if not os.path.exists(os.path.dirname(PREFS_FILE)): + os.mkdir(os.path.dirname(PREFS_FILE)) + # init _Platform.__init__( self, name='GNU Radio Companion', @@ -55,12 +63,23 @@ class Platform(_Platform, _GUIPlatform): generator=Generator, colors=COLORS, ) - + self._move_old_pref_file() _GUIPlatform.__init__( self, prefs_file=PREFS_FILE ) + @staticmethod + def _move_old_pref_file(): + if PREFS_FILE == PREFS_FILE_OLD: + return # prefs file overridden with env var + if os.path.exists(PREFS_FILE_OLD) and not os.path.exists(PREFS_FILE): + try: + import shutil + shutil.move(PREFS_FILE_OLD, PREFS_FILE) + except Exception as e: + print >> sys.stderr, e + ############################################## # Constructors ############################################## |