new preferences
[debian/gnuradio] / grc / src / platforms / python / Platform.py
1 """
2 Copyright 2008 Free Software Foundation, Inc.
3 This file is part of GNU Radio
4
5 GNU Radio Companion is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
10 GNU Radio Companion is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
18 """
19
20 import os
21 from .. base.Platform import Platform as _Platform
22 from FlowGraph import FlowGraph as _FlowGraph
23 from Connection import Connection as _Connection
24 from Block import Block as _Block
25 from Port import Source,Sink
26 from Param import Param as _Param
27 from Generator import Generator
28 from Constants import \
29         HIER_BLOCKS_LIB_DIR, BLOCK_DTD, \
30         BLOCK_TREE, DEFAULT_FLOW_GRAPH, \
31         BLOCKS_DIR
32
33 class Platform(_Platform):
34
35         def __init__(self, block_paths_internal_only=[], block_paths_external=[]):
36                 """
37                 Make a platform for gnuradio.
38                 The internal only list will replace the current block path.
39                 @param block_paths_internal_only a list of blocks internal to this platform
40                 @param block_paths_external a list of blocks to load in addition to the above blocks
41                 """
42                 #ensure hier dir
43                 if not os.path.exists(HIER_BLOCKS_LIB_DIR): os.mkdir(HIER_BLOCKS_LIB_DIR)
44                 #handle internal/only
45                 if block_paths_internal_only:
46                         block_paths = map(lambda b: os.path.join(BLOCKS_DIR, b), ['options.xml'] + block_paths_internal_only)
47                 else: block_paths = [BLOCKS_DIR]
48                 #handle external
49                 block_paths.extend(block_paths_external)
50                 #append custom hiers
51                 block_paths.append(HIER_BLOCKS_LIB_DIR)
52                 #init
53                 _Platform.__init__(
54                         self,
55                         name='GRC',
56                         key='grc',
57                         block_paths=block_paths,
58                         block_dtd=BLOCK_DTD,
59                         block_tree=BLOCK_TREE,
60                         default_flow_graph=DEFAULT_FLOW_GRAPH,
61                         generator=Generator,
62                 )
63
64         ##############################################
65         # Constructors
66         ##############################################
67         FlowGraph = _FlowGraph
68         Connection = _Connection
69         Block = _Block
70         Source = Source
71         Sink = Sink
72         Param = _Param