Merged changeset r9285:9377 from jblum/grc into trunk, with distcheck fixes
[debian/gnuradio] / grc / src / grc_gnuradio / 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 ##@package grc_gnuradio.Platform
20 #Gnuradio python specific platform.
21 #@author Josh Blum
22
23 import os
24 from grc.Constants import FLOW_GRAPH_FILE_EXTENSION
25 from grc.elements.Platform import Platform as _Platform
26 from FlowGraph import FlowGraph as _FlowGraph
27 from Connection import Connection as _Connection
28 from Block import Block as _Block
29 from Port import Source,Sink
30 from Param import Param as _Param
31 from Generator import Generator
32 from Constants import *
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
74