commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r9011 - in grc/trunk: . scripts src/grc src/grc/gui sr


From: jblum
Subject: [Commit-gnuradio] r9011 - in grc/trunk: . scripts src/grc src/grc/gui src/grc_gnuradio src/grc_gnuradio/utils
Date: Thu, 24 Jul 2008 18:13:12 -0600 (MDT)

Author: jblum
Date: 2008-07-24 18:13:12 -0600 (Thu, 24 Jul 2008)
New Revision: 9011

Added:
   grc/trunk/src/grc_gnuradio/utils/
   grc/trunk/src/grc_gnuradio/utils/__init__.py
   grc/trunk/src/grc_gnuradio/utils/convert_hier.py
   grc/trunk/src/grc_gnuradio/utils/expr_utils.py
   grc/trunk/src/grc_gnuradio/utils/extract_docs.py
Removed:
   grc/trunk/src/grc_gnuradio/expr_utils.py
   grc/trunk/src/grc_gnuradio/extract_docs.py
Modified:
   grc/trunk/scripts/grc
   grc/trunk/setup.py
   grc/trunk/src/grc/Constants.py
   grc/trunk/src/grc/converter.py
   grc/trunk/src/grc/gui/NotebookPage.py
   grc/trunk/src/grc_gnuradio/Block.py
   grc/trunk/src/grc_gnuradio/FlowGraph.py
   grc/trunk/src/grc_gnuradio/Generator.py
   grc/trunk/src/grc_gnuradio/Param.py
   grc/trunk/src/grc_gnuradio/Platform.py
Log:
initial attempt at hier

Modified: grc/trunk/scripts/grc
===================================================================
--- grc/trunk/scripts/grc       2008-07-25 00:02:47 UTC (rev 9010)
+++ grc/trunk/scripts/grc       2008-07-25 00:13:12 UTC (rev 9011)
@@ -26,7 +26,7 @@
 from optparse import OptionParser
 
 if __name__ == "__main__":
-       usage = 'usage: %%prog 
[optional_flow_graphs%s]'%FLOW_GRAPH_FILE_EXTENSION
+       usage = 'usage: %%prog [options] 
[optional_flow_graphs%s]'%FLOW_GRAPH_FILE_EXTENSION
        version = """
 GNU Radio Companion %s
 
@@ -36,6 +36,7 @@
 and you are welcome to redistribute it.
 """%VERSION
        parser = OptionParser(usage=usage, version=version)
+       parser.add_option("-H", "--hier", dest="hier", help="path to hier 
blocks", default="", type="string")
        (options, args) = parser.parse_args()
        #"test" import modules that this program will use
        error = False
@@ -50,5 +51,6 @@
        #end import of modules
        from grc_gnuradio.Platform import Platform
        from grc.ActionHandler import ActionHandler
-       ActionHandler(args, Platform())
+       block_paths_external = options.hier and [options.hier] or []
+       ActionHandler(args, Platform(block_paths_external=block_paths_external))
 

Modified: grc/trunk/setup.py
===================================================================
--- grc/trunk/setup.py  2008-07-25 00:02:47 UTC (rev 9010)
+++ grc/trunk/setup.py  2008-07-25 00:13:12 UTC (rev 9011)
@@ -32,6 +32,7 @@
        'grc_gnuradio',
        'grc_gnuradio.blks2',
        'grc_gnuradio.usrp',
+       'grc_gnuradio.utils',
        'grc_gnuradio.wxgui',
 ]
 

Modified: grc/trunk/src/grc/Constants.py
===================================================================
--- grc/trunk/src/grc/Constants.py      2008-07-25 00:02:47 UTC (rev 9010)
+++ grc/trunk/src/grc/Constants.py      2008-07-25 00:13:12 UTC (rev 9011)
@@ -137,6 +137,9 @@
 ##Location of external data files.
 DATA_DIR = os.path.join(SRC_DIR, 'data')
 
+##DTD validator for saved flow graphs.
+FLOW_GRAPH_DTD = os.path.join(DATA_DIR, 'flow_graph.dtd')
+
 ##The default file extension for flow graphs.
 FLOW_GRAPH_FILE_EXTENSION = '.grc'
 

Modified: grc/trunk/src/grc/converter.py
===================================================================
--- grc/trunk/src/grc/converter.py      2008-07-25 00:02:47 UTC (rev 9010)
+++ grc/trunk/src/grc/converter.py      2008-07-25 00:13:12 UTC (rev 9011)
@@ -20,7 +20,7 @@
 #convert old flow graph file format to new format
 address@hidden Josh Blum
 
-from grc.Constants import DATA_DIR
+from grc.Constants import FLOW_GRAPH_DTD
 from grc import ParseXML, Utils
 from grc.Utils import odict
 import difflib
@@ -76,7 +76,7 @@
        @param platform the grc gnuradio platform
        """
        try: #return if file passes validation
-               ParseXML.validate_dtd(file_path, os.path.join(DATA_DIR, 
'flow_graph.dtd'))
+               ParseXML.validate_dtd(file_path, FLOW_GRAPH_DTD)
                return
        except: pass #convert
        ############################################################

Modified: grc/trunk/src/grc/gui/NotebookPage.py
===================================================================
--- grc/trunk/src/grc/gui/NotebookPage.py       2008-07-25 00:02:47 UTC (rev 
9010)
+++ grc/trunk/src/grc/gui/NotebookPage.py       2008-07-25 00:13:12 UTC (rev 
9011)
@@ -26,7 +26,7 @@
 import gtk
 from grc import ParseXML
 from grc.StateCache import StateCache
-from grc.Constants import DATA_DIR
+from grc.Constants import FLOW_GRAPH_DTD
 import os
 
 ############################################################
@@ -52,7 +52,7 @@
                from grc import converter
                converter.convert(file_path, flow_graph.get_parent())
                ############################################################
-               ParseXML.validate_dtd(file_path, os.path.join(DATA_DIR, 
'flow_graph.dtd'))
+               ParseXML.validate_dtd(file_path, FLOW_GRAPH_DTD)
                initial_state = ParseXML.from_file(file_path)
                self.state_cache = StateCache(initial_state)
                self.set_saved(True)

Modified: grc/trunk/src/grc_gnuradio/Block.py
===================================================================
--- grc/trunk/src/grc_gnuradio/Block.py 2008-07-25 00:02:47 UTC (rev 9010)
+++ grc/trunk/src/grc_gnuradio/Block.py 2008-07-25 00:13:12 UTC (rev 9011)
@@ -22,7 +22,7 @@
 
 from grc.elements.Block import Block as _Block
 from grc import Utils
-import extract_docs
+from utils import extract_docs
 
 class Block(_Block):
 

Modified: grc/trunk/src/grc_gnuradio/FlowGraph.py
===================================================================
--- grc/trunk/src/grc_gnuradio/FlowGraph.py     2008-07-25 00:02:47 UTC (rev 
9010)
+++ grc/trunk/src/grc_gnuradio/FlowGraph.py     2008-07-25 00:13:12 UTC (rev 
9011)
@@ -20,7 +20,7 @@
 #Primative flow graph.
 address@hidden Josh Blum
 
-import expr_utils
+from utils import expr_utils
 from grc.elements.FlowGraph import FlowGraph as _FlowGraph
 from Block import Block
 from Connection import Connection
@@ -44,9 +44,9 @@
                pad = pads[0] #take only the first, user should not have more 
than 1
                #load io signature
                return {
-                       'nports': pad.get_param('nports').to_code(),
-                       'type': pad.get_param('type').to_code(),
-                       'vlen': pad.get_param('vlen').to_code(),
+                       'nports': str(pad.get_param('nports').evaluate()),
+                       'type': str(pad.get_param('type').evaluate()),
+                       'vlen': str(pad.get_param('vlen').evaluate()),
                        'size': pad.get_param('type').get_opt('size'),
                }
 

Modified: grc/trunk/src/grc_gnuradio/Generator.py
===================================================================
--- grc/trunk/src/grc_gnuradio/Generator.py     2008-07-25 00:02:47 UTC (rev 
9010)
+++ grc/trunk/src/grc_gnuradio/Generator.py     2008-07-25 00:13:12 UTC (rev 
9011)
@@ -25,7 +25,7 @@
 import sys
 import stat
 from Cheetah.Template import Template
-import expr_utils
+from utils import expr_utils
 
 ##The default binary to execute python files.
 PYEXEC = 'python'

Modified: grc/trunk/src/grc_gnuradio/Param.py
===================================================================
--- grc/trunk/src/grc_gnuradio/Param.py 2008-07-25 00:02:47 UTC (rev 9010)
+++ grc/trunk/src/grc_gnuradio/Param.py 2008-07-25 00:13:12 UTC (rev 9011)
@@ -20,7 +20,7 @@
 #Flow graph block parameters.
 address@hidden Josh Blum
 
-import expr_utils
+from utils import expr_utils
 from grc.elements.Param import Param as _Param
 import os
 

Modified: grc/trunk/src/grc_gnuradio/Platform.py
===================================================================
--- grc/trunk/src/grc_gnuradio/Platform.py      2008-07-25 00:02:47 UTC (rev 
9010)
+++ grc/trunk/src/grc_gnuradio/Platform.py      2008-07-25 00:13:12 UTC (rev 
9011)
@@ -21,6 +21,7 @@
 address@hidden Josh Blum
 
 import os
+from grc.Constants import FLOW_GRAPH_FILE_EXTENSION
 from grc.elements.Platform import Platform as _Platform
 from FlowGraph import FlowGraph as _FlowGraph
 from Connection import Connection as _Connection
@@ -49,7 +50,20 @@
                        block_paths = map(lambda b: os.path.join(BLOCK_PATH, 
b), ['options.xml'] + block_paths_internal_only)
                else: block_paths = [BLOCK_PATH]
                #handle external
-               block_paths.extend(block_paths_external)
+               if block_paths_external:
+                       from utils import convert_hier
+                       def _load_block(file_path):
+                               try:
+                                       output_file_path = file_path+'.hier'
+                                       convert_hier.convert_hier(file_path, 
output_file_path)
+                                       block_paths.append(output_file_path)
+                               except: print 'Error converting: %s'%file_path
+                       for block_path_external in block_paths_external:
+                               if os.path.isfile(block_path_external): 
_load_block(block_path_external)
+                               elif os.path.isdir(block_path_external):
+                                       for dirpath,dirnames,filenames in 
os.walk(block_path_external):
+                                               for filename in filter(lambda 
f: f.endswith(FLOW_GRAPH_FILE_EXTENSION), filenames):
+                                                       
_load_block(os.path.join(dirpath, filename))
                #init
                _Platform.__init__(
                        self,

Deleted: grc/trunk/src/grc_gnuradio/expr_utils.py

Deleted: grc/trunk/src/grc_gnuradio/extract_docs.py

Added: grc/trunk/src/grc_gnuradio/utils/__init__.py
===================================================================
--- grc/trunk/src/grc_gnuradio/utils/__init__.py                                
(rev 0)
+++ grc/trunk/src/grc_gnuradio/utils/__init__.py        2008-07-25 00:13:12 UTC 
(rev 9011)
@@ -0,0 +1,22 @@
+"""
+Copyright 2008 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
+"""
address@hidden grc_gnuradio.utils
+#utility functions and classes
address@hidden Josh Blum
+

Added: grc/trunk/src/grc_gnuradio/utils/convert_hier.py
===================================================================
--- grc/trunk/src/grc_gnuradio/utils/convert_hier.py                            
(rev 0)
+++ grc/trunk/src/grc_gnuradio/utils/convert_hier.py    2008-07-25 00:13:12 UTC 
(rev 9011)
@@ -0,0 +1,91 @@
+"""
+Copyright 2008 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
+"""
address@hidden grc_gnuradio.utils.convert_hier
+#Utility functions to convert a grc hier block to an xml wrapper
address@hidden Josh Blum
+
+from grc.Constants import FLOW_GRAPH_DTD
+from grc import ParseXML
+from grc_gnuradio.Platform import Platform, BLOCK_DTD
+from grc.Utils import odict
+
+PLATFORM = Platform()
+
+def convert_hier(input_file_path, output_file_path):
+       #get the flow graph
+       ParseXML.validate_dtd(input_file_path, FLOW_GRAPH_DTD)
+       initial_state = ParseXML.from_file(input_file_path)
+       flow_graph = PLATFORM.get_new_flow_graph()
+       flow_graph.import_data(initial_state)
+       #extract info from the flow graph
+       input_sig = flow_graph.get_input_signature()
+       output_sig = flow_graph.get_output_signature()
+       parameters = flow_graph.get_parameters()
+       block_key = flow_graph.get_option('id')
+       block_name = flow_graph.get_option('title')
+       block_category = flow_graph.get_option('category')
+       block_desc = flow_graph.get_option('description')
+       #build the nested data
+       block_n = odict()
+       block_n['name'] = block_name
+       block_n['key'] = block_key
+       block_n['category'] = block_category
+       block_n['import'] = 'import %s'%block_key
+       #make data
+       block_n['make'] = '%s.%s(\n\t%s,\n)'%(
+               block_key, block_key,
+               ',\n\t'.join(['%s=$%s'%(param.get_id(), param.get_id()) for 
param in parameters]),
+       )
+       #callback data
+       block_n['callback'] = ['set_%s($%s)'%(param.get_id(), param.get_id()) 
for param in parameters]
+       #param data
+       params_n = list()
+       for param in parameters:
+               param_n = odict()
+               param_n['name'] = param.get_param('label').get_value() or 
param.get_id()
+               param_n['key'] = param.get_id()
+               param_n['value'] = param.get_param('value').get_value()
+               param_n['type'] = 'raw'
+               params_n.append(param_n)
+       block_n['param'] = params_n
+       #sink data
+       if int(input_sig['nports']):
+               sink_n = odict()
+               sink_n['name'] = 'in'
+               sink_n['type'] = input_sig['type']
+               sink_n['vlen'] = input_sig['vlen']
+               sink_n['nports'] = input_sig['nports']
+               block_n['sink'] = sink_n
+       #source data
+       if int(output_sig['nports']):
+               source_n = odict()
+               source_n['name'] = 'out'
+               source_n['type'] = output_sig['type']
+               source_n['vlen'] = output_sig['vlen']
+               source_n['nports'] = output_sig['nports']
+               block_n['source'] = source_n
+       #doc data
+       block_n['doc'] = block_desc
+       #write the block_n to file
+       ParseXML.to_file({'block': block_n}, output_file_path)
+       ParseXML.validate_dtd(output_file_path, BLOCK_DTD)
+
+if __name__ == '__main__':
+       import sys
+       convert_hier(sys.argv[1], sys.argv[2])

Copied: grc/trunk/src/grc_gnuradio/utils/expr_utils.py (from rev 8995, 
grc/trunk/src/grc_gnuradio/expr_utils.py)
===================================================================
--- grc/trunk/src/grc_gnuradio/utils/expr_utils.py                              
(rev 0)
+++ grc/trunk/src/grc_gnuradio/utils/expr_utils.py      2008-07-25 00:13:12 UTC 
(rev 9011)
@@ -0,0 +1,140 @@
+"""
+Copyright 2008 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
+"""
address@hidden grc_gnuradio.utils.expr_utils
+#Utility functions to comprehend variable expressions.
address@hidden Josh Blum
+
+import string
+VAR_CHARS = string.letters + string.digits + '_'
+
+class graph(object):
+       """!
+       Simple graph structure held in a dictionary.
+       """
+
+       def __init__(self): self._graph = dict()
+
+       def __str__(self): return str(self._graph)
+
+       def add_node(self, node_key):
+               if self._graph.has_key(node_key): return
+               self._graph[node_key] = set()
+
+       def remove_node(self, node_key):
+               if not self._graph.has_key(node_key): return
+               for edges in self._graph.values():
+                       if node_key in edges: edges.remove(node_key)
+               self._graph.pop(node_key)
+
+       def add_edge(self, src_node_key, dest_node_key):
+               self._graph[src_node_key].add(dest_node_key)
+
+       def remove_edge(self, src_node_key, dest_node_key):
+               self._graph[src_node_key].remove(dest_node_key)
+
+       def get_nodes(self): return self._graph.keys()
+
+       def get_edges(self, node_key): return self._graph[node_key]
+
+def expr_split(expr):
+       """!
+       Split up an expression by non alphanumeric characters, including 
underscore.
+       Leave strings in-tact.
+       #TODO ignore escaped quotes, use raw strings.
+       @param expr an expression string
+       @return a list of string tokens that form expr
+       """
+       toks = list()
+       tok = ''
+       quote = ''
+       for char in expr:
+               if quote or char in VAR_CHARS:
+                       if char == quote: quote = ''
+                       tok += char
+               elif char in ("'", '"'):
+                       toks.append(tok)
+                       tok = char
+                       quote = char
+               else:
+                       toks.append(tok)
+                       toks.append(char)
+                       tok = ''
+       toks.append(tok)
+       return filter(lambda t: t, toks)
+
+def expr_prepend(expr, vars, prepend):
+       """!
+       Search for vars in the expression and add the prepend.
+       @param expr an expression string
+       @param vars a list of variable names
+       @param prepend the prepend string
+       @return a new expression with the prepend
+       """
+       expr_splits = expr_split(expr)
+       for i, es in enumerate(expr_splits):
+               if es in vars: expr_splits[i] = prepend + es
+       return ''.join(expr_splits)
+
+def get_variable_dependencies(expr, vars):
+       """!
+       Return a set of variables used in this expression.
+       @param expr an expression string
+       @param vars a list of variable names
+       @return a subset of vars used in the expression
+       """
+       expr_toks = expr_split(expr)
+       return set(filter(lambda v: v in expr_toks, vars))
+
+def get_graph(exprs):
+       """!
+       Get a graph representing the variable dependencies
+       @param exprs a mapping of variable name to expression
+       @return a graph of variable deps
+       """
+       vars = exprs.keys()
+       #get dependencies for each expression, load into graph
+       var_graph = graph()
+       for var in vars: var_graph.add_node(var)
+       for var, expr in exprs.iteritems():
+               for dep in get_variable_dependencies(expr, vars):
+                       var_graph.add_edge(dep, var)
+       return var_graph
+
+def sort_variables(exprs):
+       """!
+       Get a list of variables in order of dependencies.
+       @param exprs a mapping of variable name to expression
+       @return a list of variable names
+       @throws AssertionError circular dependencies
+       """
+       var_graph = get_graph(exprs)
+       sorted_vars = list()
+       #determine dependency order
+       while var_graph.get_nodes():
+               #get a list of nodes with no edges
+               indep_vars = filter(lambda var: not var_graph.get_edges(var), 
var_graph.get_nodes())
+               assert indep_vars
+               #add the indep vars to the end of the list
+               sorted_vars.extend(sorted(indep_vars))
+               #remove each edge-less node from the graph
+               for var in indep_vars: var_graph.remove_node(var)
+       return reversed(sorted_vars)
+
+if __name__ == '__main__':
+       for i in sort_variables({'x':'1', 'y':'x+1', 'a':'x+y', 'b':'y+1', 
'c':'a+b+x+y'}): print i

Copied: grc/trunk/src/grc_gnuradio/utils/extract_docs.py (from rev 8995, 
grc/trunk/src/grc_gnuradio/extract_docs.py)
===================================================================
--- grc/trunk/src/grc_gnuradio/utils/extract_docs.py                            
(rev 0)
+++ grc/trunk/src/grc_gnuradio/utils/extract_docs.py    2008-07-25 00:13:12 UTC 
(rev 9011)
@@ -0,0 +1,98 @@
+"""
+Copyright 2008 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
+"""
address@hidden grc_gnuradio.utils.extract_docs
+#Extract documentation from the gnuradio doxygen files.
address@hidden Josh Blum
+
+from lxml import etree
+import os
+
+DOCS_DIR = '/usr/local/share/doc/grc_gnuradio_docs/'
+DOXYGEN_NAME_XPATH = '/doxygen/compounddef/compoundname'
+DOXYGEN_BRIEFDESC_GR_XPATH = '/doxygen/compounddef/briefdescription'
+DOXYGEN_DETAILDESC_GR_XPATH = '/doxygen/compounddef/detaileddescription'
+DOXYGEN_BRIEFDESC_BLKS2_XPATH = 
'/doxygen/compounddef/address@hidden"public-func"]/memberdef/briefdescription'
+DOXYGEN_DETAILDESC_BLKS2_XPATH = 
'/doxygen/compounddef/address@hidden"public-func"]/memberdef/detaileddescription'
+
+def extract_txt(xml):
+       """!
+       Recursivly pull the text out of an xml tree.
+       @param xml the xml tree
+       @return a string
+       """
+       text = xml.text or ''
+       if not len(xml): return text
+       return ''.join([text] + map(extract_txt, xml))
+       
+def is_match(key, file):
+       """!
+       Is the block key a match for the given file name?
+       @param key block key
+       @param file the xml file name
+       @return true if matches
+       """
+       file = file.replace('.xml', '') #remove file ext
+       file = file.replace('__', '_') #doxygen xml files have 2 underscores
+       file = file.replace('_1_1', '_') #weird blks2 doxygen syntax
+       if key.startswith('gr_'): key = key.replace('gr_', 'classgr_')
+       elif key.startswith('trellis_'): key = key.replace('trellis_', 
'classtrellis_')
+       elif key.startswith('blks2_'): key = key.replace('blks2_', '')
+       else: return False
+       for k, f in zip(*map(reversed, map(lambda x: x.split('_'), [key, 
file]))):
+               if k == f: continue
+               ks = k.split('x')
+               if len(ks) == 2 and f.startswith(ks[0]) and f.endswith(ks[1]): 
continue
+               if len(ks) > 2 and all(ki in ('x', fi) for ki, fi in zip(k, 
f)): continue
+               return False
+       return True     
+
+def extract(key):
+       """!
+       Extract the documentation from the doxygen generated xml files.
+       If multiple files match, combine the docs.
+       @param key the block key
+       @return a string with documentation
+       """
+       #get potential xml file matches for the key
+       if os.path.exists(DOCS_DIR) and os.path.isdir(DOCS_DIR):
+               matches = filter(lambda f: is_match(key, f), 
os.listdir(DOCS_DIR))
+       else: matches = list()
+       #combine all matches
+       doc_strs = list()
+       for match in matches:
+               try:
+                       xml_file = DOCS_DIR + '/' + match
+                       xml = etree.parse(xml_file)
+                       #extract descriptions
+                       comp_name = 
extract_txt(xml.xpath(DOXYGEN_NAME_XPATH)[0]).strip('\n')
+                       comp_name = '   ---   ' + comp_name + '   ---   '
+                       if key.startswith('gr_') or key.startswith('trellis_'):
+                               brief_desc = 
extract_txt(xml.xpath(DOXYGEN_BRIEFDESC_GR_XPATH)[0]).strip('\n')
+                               detailed_desc = 
extract_txt(xml.xpath(DOXYGEN_DETAILDESC_GR_XPATH)[0]).strip('\n')
+                       elif key.startswith('blks2_'):
+                               brief_desc = 
extract_txt(xml.xpath(DOXYGEN_BRIEFDESC_BLKS2_XPATH)[0]).strip('\n')
+                               detailed_desc = 
extract_txt(xml.xpath(DOXYGEN_DETAILDESC_BLKS2_XPATH)[0]).strip('\n')
+                       else:
+                               brief_desc = ''
+                               detailed_desc = ''
+                       #combine
+                       doc_strs.append('\n'.join([comp_name, brief_desc, 
detailed_desc]).strip('\n'))  
+               except IndexError: pass #bad format
+       return '\n\n'.join(doc_strs)
+





reply via email to

[Prev in Thread] Current Thread [Next in Thread]