Skip to content

Commit ffe1a7a

Browse files
committed
Merge remote-tracking branch 'gnuradio-wg-grc/grc_block_and_prefs_path'
2 parents 8be0efd + 14625c6 commit ffe1a7a

File tree

6 files changed

+34
-10
lines changed

6 files changed

+34
-10
lines changed

grc/base/Platform.py

+1
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ def get_key(self): return self._key
196196
def get_license(self): return self._license
197197
def get_website(self): return self._website
198198
def get_colors(self): return self._colors
199+
def get_block_paths(self): return self._block_paths
199200

200201
##############################################
201202
# Constructors

grc/gui/Messages.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,16 @@ def send(message):
4848
# Special functions for specific program functionalities
4949
###########################################################################
5050
def send_init(platform):
51-
send("""<<< Welcome to %s %s >>>\n"""%(platform.get_name(), platform.get_version()))
51+
p = platform
52+
send('\n'.join([
53+
"<<< Welcome to %s %s >>>" % (p.get_name(), p.get_version()),
54+
"",
55+
"Preferences file: " + p.get_prefs_file(),
56+
"Block paths:"
57+
] + [
58+
"\t%s" % path + (" (%s)" % opath if opath != path else "")
59+
for path, opath in p.get_block_paths().iteritems()
60+
]) + "\n")
5261

5362
def send_page_switch(file_path):
5463
send('\nShowing: "%s"\n'%file_path)

grc/gui/Platform.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,9 @@
2020
from Element import Element
2121

2222
class Platform(Element):
23-
def __init__(self): Element.__init__(self)
23+
def __init__(self, prefs_file):
24+
Element.__init__(self)
25+
26+
self._prefs_file = prefs_file
27+
28+
def get_prefs_file(self): return self._prefs_file

grc/gui/Preferences.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,17 @@
2424
_config_parser = ConfigParser.ConfigParser()
2525

2626
def file_extension(): return '.'+_platform.get_key()
27-
def _prefs_file(): return os.path.join(os.path.expanduser('~'), file_extension())
2827

2928
def load(platform):
3029
global _platform
3130
_platform = platform
3231
#create sections
3332
_config_parser.add_section('main')
3433
_config_parser.add_section('files_open')
35-
try: _config_parser.read(_prefs_file())
34+
try: _config_parser.read(_platform.get_prefs_file())
3635
except: pass
3736
def save():
38-
try: _config_parser.write(open(_prefs_file(), 'w'))
37+
try: _config_parser.write(open(_platform.get_prefs_file(), 'w'))
3938
except: pass
4039

4140
###########################################################################

grc/python/Constants.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525

2626
#setup paths
2727
PATH_SEP = {'/':':', '\\':';'}[os.path.sep]
28-
HIER_BLOCKS_LIB_DIR = os.path.join(os.path.expanduser('~'), '.grc_gnuradio')
28+
HIER_BLOCKS_LIB_DIR = os.environ.get('GRC_HIER_PATH',
29+
os.path.expanduser('~/.grc_gnuradio'))
30+
PREFS_FILE = os.environ.get('GRC_PREFS_PATH',
31+
os.path.join(os.path.expanduser('~/.grc')))
2932
BLOCKS_DIRS = filter( #filter blank strings
3033
lambda x: x, PATH_SEP.join([
3134
os.environ.get('GRC_BLOCKS_PATH', ''),

grc/python/Platform.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"""
1919

2020
import os
21+
from collections import OrderedDict
2122
from gnuradio import gr
2223
from .. base.Platform import Platform as _Platform
2324
from .. gui.Platform import Platform as _GUIPlatform
@@ -29,7 +30,7 @@
2930
from Generator import Generator
3031
from Constants import \
3132
HIER_BLOCKS_LIB_DIR, BLOCK_DTD, \
32-
DEFAULT_FLOW_GRAPH, BLOCKS_DIRS
33+
DEFAULT_FLOW_GRAPH, BLOCKS_DIRS, PREFS_FILE
3334
import Constants
3435

3536
COLORS = [(name, color) for name, key, sizeof, color in Constants.CORE_TYPES]
@@ -42,8 +43,10 @@ def __init__(self):
4243
"""
4344
#ensure hier dir
4445
if not os.path.exists(HIER_BLOCKS_LIB_DIR): os.mkdir(HIER_BLOCKS_LIB_DIR)
45-
#convert block paths to absolute paths
46-
block_paths = set(map(os.path.abspath, BLOCKS_DIRS))
46+
# Convert block paths to absolute paths:
47+
# - Create a mapping from the absolute path to what was passed in
48+
# - Keep each unique absolute path and maintain order
49+
block_paths = OrderedDict(map(lambda x: (os.path.abspath(x), x), BLOCKS_DIRS))
4750
#init
4851
_Platform.__init__(
4952
self,
@@ -58,7 +61,11 @@ def __init__(self):
5861
generator=Generator,
5962
colors=COLORS,
6063
)
61-
_GUIPlatform.__init__(self)
64+
65+
_GUIPlatform.__init__(
66+
self,
67+
prefs_file=PREFS_FILE
68+
)
6269

6370
##############################################
6471
# Constructors

0 commit comments

Comments
 (0)