diff options
author | jblum | 2009-06-29 04:29:36 +0000 |
---|---|---|
committer | jblum | 2009-06-29 04:29:36 +0000 |
commit | 5762d01a3d45b8d500c5ad560c272692d7d46db2 (patch) | |
tree | eeb126eb6ae592ac97bddd4c216eb830f817b280 /grc/python | |
parent | f728f2dd61af00b02525d078bbb748bfb75800e1 (diff) | |
download | gnuradio-5762d01a3d45b8d500c5ad560c272692d7d46db2.tar.gz gnuradio-5762d01a3d45b8d500c5ad560c272692d7d46db2.tar.bz2 gnuradio-5762d01a3d45b8d500c5ad560c272692d7d46db2.zip |
Added ability to extract category names from doxygen.
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
Diffstat (limited to 'grc/python')
-rw-r--r-- | grc/python/Block.py | 6 | ||||
-rw-r--r-- | grc/python/Makefile.am | 1 | ||||
-rw-r--r-- | grc/python/expr_utils.py | 2 | ||||
-rw-r--r-- | grc/python/extract_category.py | 61 | ||||
-rw-r--r-- | grc/python/extract_docs.py | 4 |
5 files changed, 71 insertions, 3 deletions
diff --git a/grc/python/Block.py b/grc/python/Block.py index a9e999491..6d7595777 100644 --- a/grc/python/Block.py +++ b/grc/python/Block.py @@ -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. diff --git a/grc/python/Makefile.am b/grc/python/Makefile.am index e6d253f5c..0a62c0825 100644 --- a/grc/python/Makefile.am +++ b/grc/python/Makefile.am @@ -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 \ diff --git a/grc/python/expr_utils.py b/grc/python/expr_utils.py index 1880c8f9c..1bee22497 100644 --- a/grc/python/expr_utils.py +++ b/grc/python/expr_utils.py @@ -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 index 000000000..f9358f616 --- /dev/null +++ b/grc/python/extract_category.py @@ -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]) diff --git a/grc/python/extract_docs.py b/grc/python/extract_docs.py index fa9140bdf..f0c1e749c 100644 --- a/grc/python/extract_docs.py +++ b/grc/python/extract_docs.py @@ -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: |