1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
"""Copyright 2016 Free Software Foundation, Inc.
This file is part of GNU Radio
GNU Radio Companion is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
GNU Radio Companion is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
"""
from __future__ import absolute_import
import os
from os.path import expanduser, normpath, expandvars, exists
from . import Constants
class Config(object):
name = 'GNU Radio Companion (no gui)'
license = __doc__.strip()
website = 'http://gnuradio.org'
hier_block_lib_dir = os.environ.get('GRC_HIER_PATH', Constants.DEFAULT_HIER_BLOCK_LIB_DIR)
yml_block_cache = os.path.expanduser('~/.cache/grc_gnuradio') # FIXME: remove this as soon as converter is stable
def __init__(self, version, version_parts=None, name=None, prefs=None):
self._gr_prefs = prefs if prefs else DummyPrefs()
self.version = version
self.version_parts = version_parts or version[1:].split('-', 1)[0].split('.')[:3]
if name:
self.name = name
if not os.path.exists(self.yml_block_cache):
os.mkdir(self.yml_block_cache)
@property
def block_paths(self):
path_list_sep = {'/': ':', '\\': ';'}[os.path.sep]
paths_sources = (
self.hier_block_lib_dir,
os.environ.get('GRC_BLOCKS_PATH', ''),
self.yml_block_cache,
self._gr_prefs.get_string('grc', 'local_blocks_path', ''),
self._gr_prefs.get_string('grc', 'global_blocks_path', ''),
)
collected_paths = sum((paths.split(path_list_sep)
for paths in paths_sources), [])
valid_paths = [normpath(expanduser(expandvars(path)))
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._gr_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
class DummyPrefs(object):
def get_string(self, category, item, default):
return str(default)
def set_string(self, category, item, value):
pass
def get_long(self, category, item, default):
return int(default)
def save(self):
pass
|