Merged r9481:9518 on jblum/grc_reorganize into trunk. Reorganized grc source under...
[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.Constants import FLOW_GRAPH_FILE_EXTENSION
22 from .. base.Platform import Platform as _Platform
23 from FlowGraph import FlowGraph as _FlowGraph
24 from Connection import Connection as _Connection
25 from Block import Block as _Block
26 from Port import Source,Sink
27 from Param import Param as _Param
28 from Generator import Generator
29 from Constants import \
30         HIER_BLOCKS_LIB_DIR, BLOCK_DTD, \
31         BLOCK_TREE, DEFAULT_FLOW_GRAPH, \
32         BLOCKS_DIR
33
34 class Platform(_Platform):
35
36         def __init__(self, block_paths_internal_only=[], block_paths_external=[]):
37                 """
38                 Make a platform for gnuradio.
39                 The internal only list will replace the current block path.
40                 @param block_paths_internal_only a list of blocks internal to this platform
41                 @param block_paths_external a list of blocks to load in addition to the above blocks
42                 """
43                 #ensure hier dir
44                 if not os.path.exists(HIER_BLOCKS_LIB_DIR): os.mkdir(HIER_BLOCKS_LIB_DIR)
45                 #handle internal/only
46                 if block_paths_internal_only:
47                         block_paths = map(lambda b: os.path.join(BLOCKS_DIR, b), ['options.xml'] + block_paths_internal_only)
48                 else: block_paths = [BLOCKS_DIR]
49                 #handle external
50                 block_paths.extend(block_paths_external)
51                 #append custom hiers
52                 block_paths.append(HIER_BLOCKS_LIB_DIR)
53                 #init
54                 _Platform.__init__(
55                         self,
56                         name='GNURadio Python',
57                         key='gnuradio_python',
58                         block_paths=block_paths,
59                         block_dtd=BLOCK_DTD,
60                         block_tree=BLOCK_TREE,
61                         default_flow_graph=DEFAULT_FLOW_GRAPH,
62                         generator=Generator,
63                 )
64
65         ##############################################
66         # Constructors
67         ##############################################
68         FlowGraph = _FlowGraph
69         Connection = _Connection
70         Block = _Block
71         Source = Source
72         Sink = Sink
73         Param = _Param