Added ability to extract category names from doxygen.
authorjblum <jblum@221aa14e-8319-0410-a670-987f0aec2ac5>
Mon, 29 Jun 2009 04:29:36 +0000 (04:29 +0000)
committerjblum <jblum@221aa14e-8319-0410-a670-987f0aec2ac5>
Mon, 29 Jun 2009 04:29:36 +0000 (04:29 +0000)
For now, this is commented out until the current block tree is overhauled.

git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@11304 221aa14e-8319-0410-a670-987f0aec2ac5

grc/base/Platform.py
grc/python/Block.py
grc/python/Makefile.am
grc/python/expr_utils.py
grc/python/extract_category.py [new file with mode: 0644]
grc/python/extract_docs.py

index 6cbe741ddd8222f87f285bdadcae992a6c3c60c9..3050e5e475cde8e9bfe3fb2fb1d92544fc7118a3 100644 (file)
@@ -19,7 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 
 import os
 import sys
-from .. base import ParseXML
+from .. base import ParseXML, odict
 from Element import Element as _Element
 from FlowGraph import FlowGraph as _FlowGraph
 from Connection import Connection as _Connection
@@ -66,11 +66,11 @@ class Platform(_Element):
                        if os.path.isfile(block_path): xml_files.append(block_path)
                        elif os.path.isdir(block_path):
                                for dirpath, dirnames, filenames in os.walk(block_path):
-                                       for filename in filter(lambda f: f.endswith('.xml'), filenames):
+                                       for filename in sorted(filter(lambda f: f.endswith('.xml'), filenames)):
                                                xml_files.append(os.path.join(dirpath, filename))
                #load the blocks
-               self._blocks = dict()
-               self._blocks_n = dict()
+               self._blocks = odict()
+               self._blocks_n = odict()
                self._block_tree_files = list()
                for xml_file in xml_files:
                        try: #try to add the xml file as a block wrapper
index a9e999491e7a1a34fb9ab2a2e1bcaa124f2c19b9..6d75957779ade30a7c38b254acb8e8b60465f287 100644 (file)
@@ -19,6 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 
 from .. base.Block import Block as _Block
 import extract_docs
+import extract_category
 
 class Block(_Block):
 
@@ -128,6 +129,11 @@ class Block(_Block):
                #merge custom doc with doxygen docs
                return '\n'.join([doc, extract_docs.extract(self.get_key())]).strip('\n')
 
+       def get_category(self):
+               #category = extract_category.extract(self.get_key())
+               #if category: return category
+               return _Block.get_category(self)
+
        def get_imports(self):
                """
                Resolve all import statements.
index e6d253f5c1383e362c99cc3d53dffd8028609a6a..0a62c08257a36e9ba3fef5294b899a0933243dd7 100644 (file)
@@ -25,6 +25,7 @@ ourpythondir = $(grc_src_prefix)/python
 ourpython_PYTHON = \
        convert_hier.py \
        expr_utils.py \
+       extract_category.py \
        extract_docs.py \
        Block.py \
        Connection.py \
index 1880c8f9ce90552bdec8e6067f64302913e2daaa..1bee2249704a6dc066bacc8cc2965ce6cdd61627 100644 (file)
@@ -1,5 +1,5 @@
 """
-Copyright 2008 Free Software Foundation, Inc.
+Copyright 2008, 2009 Free Software Foundation, Inc.
 This file is part of GNU Radio
 
 GNU Radio Companion is free software; you can redistribute it and/or
diff --git a/grc/python/extract_category.py b/grc/python/extract_category.py
new file mode 100644 (file)
index 0000000..f9358f6
--- /dev/null
@@ -0,0 +1,61 @@
+"""
+Copyright 2009 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
+"""
+
+from Constants import DOCS_DIR
+from lxml import etree
+import os
+import re
+
+DOXYGEN_TITLE_XPATH = '/doxygen/compounddef/title'
+DOXYGEN_CLASS_XPATH = '/doxygen/compounddef/innerclass'
+
+#map a group/category to a list of blocks
+_category_map = dict()
+
+#extract the group/category information
+docs_dir = os.path.join(DOCS_DIR, 'xml')
+if os.path.exists(docs_dir):
+       group_file_matcher = re.compile('^group__\w*\..*$') #xml or xml.gz
+       matches = filter(lambda f: group_file_matcher.match(f), os.listdir(docs_dir))
+       for match in matches:
+               try:
+                       xml_file = os.path.join(docs_dir, match)
+                       xml = etree.parse(xml_file)
+                       category = xml.xpath(DOXYGEN_TITLE_XPATH)[0].text
+                       blocks = map(lambda x: x.text, xml.xpath(DOXYGEN_CLASS_XPATH))
+                       _category_map[category] = blocks
+               except: pass
+
+def extract(key):
+       """
+       Match the given key to a key in an existing category.
+       If no match can be made, return an empty string.
+       @param key the block key
+       @return the category or empty string
+       """
+       pattern = key.replace('_', '_*').replace('x', '\w')
+       class_name_matcher = re.compile('^%s$'%pattern)
+       for category, blocks in _category_map.iteritems():
+               for block in blocks:
+                       if class_name_matcher.match(block): return category
+       return ''
+
+if __name__ == '__main__':
+       import sys
+       print extract(sys.argv[1])
index fa9140bdf87ba225fcd697f195034623fd06d9af..f0c1e749cec747b150593d3ce362b63aeb88b488 100644 (file)
@@ -52,8 +52,8 @@ def _extract(key):
        if not os.path.exists(docs_dir): return ''
        #extract matches
        pattern = key.replace('_', '_*').replace('x', '\w')
-       prog = re.compile('^class%s\..*$'%pattern)
-       matches = filter(lambda f: prog.match(f), os.listdir(docs_dir))
+       class_file_matcher = re.compile('^class%s\..*$'%pattern) #xml or xml.gz
+       matches = filter(lambda f: class_file_matcher.match(f), os.listdir(docs_dir))
        #combine all matches
        doc_strs = list()
        for match in matches: