Reverting last change in alsa.
[debian/gnuradio] / grc / python / Generator.py
index cde7dc3d448a7692fe540fa099f5fbf69958a11b..acd98ef8414ef2a6ee1241451efd28d76f70e511 100644 (file)
@@ -1,5 +1,5 @@
 """
-Copyright 2008, 2009 Free Software Foundation, Inc.
+Copyright 2008, 2009, 2010 Free Software Foundation, Inc.
 This file is part of GNU Radio
 
 GNU Radio Companion is free software; you can redistribute it and/or
@@ -19,6 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 
 import os
 import subprocess
+import tempfile
 from Cheetah.Template import Template
 import expr_utils
 from Constants import \
@@ -45,6 +46,10 @@ class Generator(object):
                else:
                        self._mode = TOP_BLOCK_FILE_MODE
                        dirname = os.path.dirname(file_path)
+                       #handle the case where the directory is read-only
+                       #in this case, use the system's temp directory
+                       if not os.access(dirname, os.W_OK):
+                               dirname = tempfile.gettempdir()
                filename = self._flow_graph.get_option('id') + '.py'
                self._file_path = os.path.join(dirname, filename)
 
@@ -90,9 +95,16 @@ Add a Misc->Throttle block to your flow graph to avoid CPU congestion.''')
                #list of blocks not including variables and imports and parameters and disabled
                blocks = sorted(self._flow_graph.get_enabled_blocks(), lambda x, y: cmp(x.get_id(), y.get_id()))
                probes = filter(lambda b: b.get_key().startswith('probe_'), blocks) #ensure probes are last in the block list
-               blocks = filter(lambda b: b not in (imports + parameters + variables + probes), blocks) + probes
+               #get a list of notebooks and sort them according dependencies
+               notebooks = expr_utils.sort_objects(
+                       filter(lambda b: b.get_key() == 'notebook', blocks),
+                       lambda n: n.get_id(), lambda n: n.get_param('notebook').get_value(),
+               )
+               #list of regular blocks (all blocks minus the special ones)
+               blocks = filter(lambda b: b not in (imports + parameters + variables + probes + notebooks), blocks) + probes
                #list of connections where each endpoint is enabled
-               connections = self._flow_graph.get_enabled_connections()
+               connections = filter(lambda c: not c.is_msg(), self._flow_graph.get_enabled_connections())
+               messages = filter(lambda c: c.is_msg(), self._flow_graph.get_enabled_connections())
                #list of variable names
                var_ids = [var.get_id() for var in parameters + variables]
                #prepend self.
@@ -113,10 +125,12 @@ Add a Misc->Throttle block to your flow graph to avoid CPU congestion.''')
                        'imports': imports,
                        'flow_graph': self._flow_graph,
                        'variables': variables,
+                       'notebooks': notebooks,
                        'controls': controls,
                        'parameters': parameters,
                        'blocks': blocks,
                        'connections': connections,
+                       'messages': messages,
                        'generate_options': self._generate_options,
                        'var_id2cbs': var_id2cbs,
                }