commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r11304 - in gnuradio/trunk/grc: base python


From: jblum
Subject: [Commit-gnuradio] r11304 - in gnuradio/trunk/grc: base python
Date: Sun, 28 Jun 2009 22:29:36 -0600 (MDT)

Author: jblum
Date: 2009-06-28 22:29:36 -0600 (Sun, 28 Jun 2009)
New Revision: 11304

Added:
   gnuradio/trunk/grc/python/extract_category.py
Modified:
   gnuradio/trunk/grc/base/Platform.py
   gnuradio/trunk/grc/python/Block.py
   gnuradio/trunk/grc/python/Makefile.am
   gnuradio/trunk/grc/python/expr_utils.py
   gnuradio/trunk/grc/python/extract_docs.py
Log:
Added ability to extract category names from doxygen.
For now, this is commented out until the current block tree is overhauled.



Modified: gnuradio/trunk/grc/base/Platform.py
===================================================================
--- gnuradio/trunk/grc/base/Platform.py 2009-06-28 21:24:44 UTC (rev 11303)
+++ gnuradio/trunk/grc/base/Platform.py 2009-06-29 04:29:36 UTC (rev 11304)
@@ -19,7 +19,7 @@
 
 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 @@
                        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

Modified: gnuradio/trunk/grc/python/Block.py
===================================================================
--- gnuradio/trunk/grc/python/Block.py  2009-06-28 21:24:44 UTC (rev 11303)
+++ gnuradio/trunk/grc/python/Block.py  2009-06-29 04:29:36 UTC (rev 11304)
@@ -19,6 +19,7 @@
 
 from .. base.Block import Block as _Block
 import extract_docs
+import extract_category
 
 class Block(_Block):
 
@@ -128,6 +129,11 @@
                #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.

Modified: gnuradio/trunk/grc/python/Makefile.am
===================================================================
--- gnuradio/trunk/grc/python/Makefile.am       2009-06-28 21:24:44 UTC (rev 
11303)
+++ gnuradio/trunk/grc/python/Makefile.am       2009-06-29 04:29:36 UTC (rev 
11304)
@@ -25,6 +25,7 @@
 ourpython_PYTHON = \
        convert_hier.py \
        expr_utils.py \
+       extract_category.py \
        extract_docs.py \
        Block.py \
        Connection.py \

Modified: gnuradio/trunk/grc/python/expr_utils.py
===================================================================
--- gnuradio/trunk/grc/python/expr_utils.py     2009-06-28 21:24:44 UTC (rev 
11303)
+++ gnuradio/trunk/grc/python/expr_utils.py     2009-06-29 04:29:36 UTC (rev 
11304)
@@ -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

Added: gnuradio/trunk/grc/python/extract_category.py
===================================================================
--- gnuradio/trunk/grc/python/extract_category.py                               
(rev 0)
+++ gnuradio/trunk/grc/python/extract_category.py       2009-06-29 04:29:36 UTC 
(rev 11304)
@@ -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])

Modified: gnuradio/trunk/grc/python/extract_docs.py
===================================================================
--- gnuradio/trunk/grc/python/extract_docs.py   2009-06-28 21:24:44 UTC (rev 
11303)
+++ gnuradio/trunk/grc/python/extract_docs.py   2009-06-29 04:29:36 UTC (rev 
11304)
@@ -52,8 +52,8 @@
        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:





reply via email to

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