diff options
author | Josh Blum <josh@joshknows.com> | 2011-11-17 07:59:50 -0800 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2011-11-17 07:59:50 -0800 |
commit | 7b57dae20bb182561fcda78e5eeec44e44f0a9fb (patch) | |
tree | 8cffe26c338172ea9a9adbc953e199e048e77d30 /grc/python | |
parent | 11d58fe2e58c83fffae0153b3d541e9928f04411 (diff) |
grc: replaced doxygen extracted docs with python docstrings
Diffstat (limited to 'grc/python')
-rw-r--r-- | grc/python/Block.py | 3 | ||||
-rw-r--r-- | grc/python/CMakeLists.txt | 1 | ||||
-rw-r--r-- | grc/python/Constants.py | 1 | ||||
-rw-r--r-- | grc/python/Makefile.am | 1 | ||||
-rw-r--r-- | grc/python/extract_category.py | 61 | ||||
-rw-r--r-- | grc/python/extract_docs.py | 58 |
6 files changed, 13 insertions, 112 deletions
diff --git a/grc/python/Block.py b/grc/python/Block.py index 967a27ce94..2c334dfc2c 100644 --- a/grc/python/Block.py +++ b/grc/python/Block.py @@ -20,7 +20,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA from .. base.Block import Block as _Block from .. gui.Block import Block as _GUIBlock import extract_docs -import extract_category class Block(_Block, _GUIBlock): @@ -154,8 +153,6 @@ class Block(_Block, _GUIBlock): 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): diff --git a/grc/python/CMakeLists.txt b/grc/python/CMakeLists.txt index 2075d126db..0871c7bd10 100644 --- a/grc/python/CMakeLists.txt +++ b/grc/python/CMakeLists.txt @@ -21,7 +21,6 @@ GR_PYTHON_INSTALL(FILES convert_hier.py expr_utils.py - extract_category.py extract_docs.py Block.py Connection.py diff --git a/grc/python/Constants.py b/grc/python/Constants.py index ab547ea277..1a65caf1c0 100644 --- a/grc/python/Constants.py +++ b/grc/python/Constants.py @@ -25,7 +25,6 @@ _gr_prefs = gr.prefs() #setup paths PATH_SEP = {'/':':', '\\':';'}[os.path.sep] -DOCS_DIR = os.environ.get('GR_DOC_DIR', _gr_prefs.get_string('grc', 'doc_dir', '')) HIER_BLOCKS_LIB_DIR = os.path.join(os.path.expanduser('~'), '.grc_gnuradio') BLOCKS_DIRS = filter( #filter blank strings lambda x: x, PATH_SEP.join([ diff --git a/grc/python/Makefile.am b/grc/python/Makefile.am index 67b71bc472..eb35b6fc11 100644 --- a/grc/python/Makefile.am +++ b/grc/python/Makefile.am @@ -25,7 +25,6 @@ ourpythondir = $(pkgpythondir)/grc/python ourpython_PYTHON = \ convert_hier.py \ expr_utils.py \ - extract_category.py \ extract_docs.py \ Block.py \ Connection.py \ diff --git a/grc/python/extract_category.py b/grc/python/extract_category.py deleted file mode 100644 index f9358f6162..0000000000 --- a/grc/python/extract_category.py +++ /dev/null @@ -1,61 +0,0 @@ -""" -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 fe157a2216..a7e945c373 100644 --- a/grc/python/extract_docs.py +++ b/grc/python/extract_docs.py @@ -17,63 +17,31 @@ 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_NAME_XPATH = '/doxygen/compounddef/compoundname' -DOXYGEN_BRIEFDESC_GR_XPATH = '/doxygen/compounddef/briefdescription' -DOXYGEN_DETAILDESC_GR_XPATH = '/doxygen/compounddef/detaileddescription' - -GROUP_KEYS = "gr|trellis|noaa|vocoder|digital" - -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 '').replace('\n', '') - tail = (xml.tail or '').replace('\n', '') - if xml.tag == 'para': tail += '\n\n' - if xml.tag == 'linebreak': text += '\n' - if xml.tag == 'parametername': text += ': ' - return text + ''.join( - map(lambda x: extract_txt(x), xml) - ) + tail - def _extract(key): """ - Extract the documentation from the doxygen generated xml files. - If multiple files match, combine the docs. + Extract the documentation from the python __doc__ strings. + If multiple modules match, combine the docs. @param key the block key @return a string with documentation """ - docs_dir = os.path.join(DOCS_DIR, 'xml') - if not os.path.exists(docs_dir): return '' #extract matches - pattern = key.replace('_', '_*').replace('x', '\w') - 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)) + try: + module_name, constructor_name = key.split('_', 1) + module = __import__('gnuradio.'+module_name) + module = getattr(module, module_name) + except: return '' + pattern = constructor_name.replace('_', '_*').replace('x', '\w') + pattern_matcher = re.compile('^%s\w*$'%pattern) + matches = filter(lambda x: pattern_matcher.match(x), dir(module)) #combine all matches doc_strs = list() for match in matches: try: - xml_file = os.path.join(docs_dir, match) - xml = etree.parse(xml_file) - #extract descriptions - comp_name = extract_txt(xml.xpath(DOXYGEN_NAME_XPATH)[0]).strip() - comp_name = ' --- ' + comp_name + ' --- ' - if re.match(('(%s)_.*' % GROUP_KEYS), key): - brief_desc = extract_txt(xml.xpath(DOXYGEN_BRIEFDESC_GR_XPATH)[0]).strip() - detailed_desc = extract_txt(xml.xpath(DOXYGEN_DETAILDESC_GR_XPATH)[0]).strip() - else: - brief_desc = '' - detailed_desc = '' - #combine - doc_strs.append('\n\n'.join([comp_name, brief_desc, detailed_desc]).strip()) - except IndexError: pass #bad format + title = ' --- ' + match + ' --- ' + doc_strs.append('\n\n'.join([title, getattr(module, match).__doc__]).strip()) + except: pass return '\n\n'.join(doc_strs) _docs_cache = dict() |