From 9988664127b367fa8fee4409f8460673d6f265e1 Mon Sep 17 00:00:00 2001 From: jblum Date: Tue, 23 Jun 2009 20:38:18 +0000 Subject: Merging r11186:11273 from grc branch. Fixes, features, and reorganization for grc. Minor fixes and features for wxgui forms. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@11274 221aa14e-8319-0410-a670-987f0aec2ac5 --- grc/python/extract_docs.py | 90 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 grc/python/extract_docs.py (limited to 'grc/python/extract_docs.py') diff --git a/grc/python/extract_docs.py b/grc/python/extract_docs.py new file mode 100644 index 000000000..fa9140bdf --- /dev/null +++ b/grc/python/extract_docs.py @@ -0,0 +1,90 @@ +""" +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 +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_NAME_XPATH = '/doxygen/compounddef/compoundname' +DOXYGEN_BRIEFDESC_GR_XPATH = '/doxygen/compounddef/briefdescription' +DOXYGEN_DETAILDESC_GR_XPATH = '/doxygen/compounddef/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 '').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. + @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') + prog = re.compile('^class%s\..*$'%pattern) + matches = filter(lambda f: prog.match(f), os.listdir(docs_dir)) + #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('(gr|usrp2|trellis)_.*', 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 + return '\n\n'.join(doc_strs) + +_docs_cache = dict() +def extract(key): + """ + Call the private extract and cache the result. + @param key the block key + @return a string with documentation + """ + try: assert _docs_cache.has_key(key) + except: _docs_cache[key] = _extract(key) + return _docs_cache[key] + +if __name__ == '__main__': + import sys + print extract(sys.argv[1]) -- cgit From 5762d01a3d45b8d500c5ad560c272692d7d46db2 Mon Sep 17 00:00:00 2001 From: jblum Date: Mon, 29 Jun 2009 04:29:36 +0000 Subject: 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 --- grc/python/extract_docs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'grc/python/extract_docs.py') 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: -- cgit From a9a81b990895b4cc19d7a0817ec9e4677f0a870b Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 7 Oct 2009 19:22:03 -0700 Subject: added noaa to extract doc matcher --- grc/python/extract_docs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'grc/python/extract_docs.py') diff --git a/grc/python/extract_docs.py b/grc/python/extract_docs.py index f0c1e749c..f41f415b2 100644 --- a/grc/python/extract_docs.py +++ b/grc/python/extract_docs.py @@ -63,7 +63,7 @@ def _extract(key): #extract descriptions comp_name = extract_txt(xml.xpath(DOXYGEN_NAME_XPATH)[0]).strip() comp_name = ' --- ' + comp_name + ' --- ' - if re.match('(gr|usrp2|trellis)_.*', key): + if re.match('(gr|usrp2|trellis|noaa)_.*', 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: -- cgit From 4cdd41c1046cef12601602bd38dc8ebf42d1550d Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 14 Apr 2011 10:05:33 -0700 Subject: grc: replaced asserts in python subdirectory --- grc/python/extract_docs.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'grc/python/extract_docs.py') diff --git a/grc/python/extract_docs.py b/grc/python/extract_docs.py index f41f415b2..aa85397f9 100644 --- a/grc/python/extract_docs.py +++ b/grc/python/extract_docs.py @@ -1,5 +1,5 @@ """ -Copyright 2008, 2009 Free Software Foundation, Inc. +Copyright 2008-2011 Free Software Foundation, Inc. This file is part of GNU Radio GNU Radio Companion is free software; you can redistribute it and/or @@ -81,8 +81,8 @@ def extract(key): @param key the block key @return a string with documentation """ - try: assert _docs_cache.has_key(key) - except: _docs_cache[key] = _extract(key) + if not _docs_cache.has_key(key): + _docs_cache[key] = _extract(key) return _docs_cache[key] if __name__ == '__main__': -- cgit From 68ac497f17af5af435b535d0dccbd930be0fc1d3 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Fri, 14 Oct 2011 13:05:25 -0400 Subject: docs: Updated some docs and made it so GRC can pull docs in from other components like vocoder and digital. --- grc/python/extract_docs.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'grc/python/extract_docs.py') diff --git a/grc/python/extract_docs.py b/grc/python/extract_docs.py index aa85397f9..be55fd239 100644 --- a/grc/python/extract_docs.py +++ b/grc/python/extract_docs.py @@ -26,6 +26,8 @@ DOXYGEN_NAME_XPATH = '/doxygen/compounddef/compoundname' DOXYGEN_BRIEFDESC_GR_XPATH = '/doxygen/compounddef/briefdescription' DOXYGEN_DETAILDESC_GR_XPATH = '/doxygen/compounddef/detaileddescription' +GROUP_KEYS = "gr|usrp2|trellis|noaa|vocoder|digital" + def extract_txt(xml): """ Recursivly pull the text out of an xml tree. @@ -63,7 +65,8 @@ def _extract(key): #extract descriptions comp_name = extract_txt(xml.xpath(DOXYGEN_NAME_XPATH)[0]).strip() comp_name = ' --- ' + comp_name + ' --- ' - if re.match('(gr|usrp2|trellis|noaa)_.*', key): +# if re.match('(gr|usrp2|trellis|noaa)_.*', key): + 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: -- cgit From e30b824e9165bff69f09121631c3d5a706cbbd39 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Wed, 19 Oct 2011 15:10:58 -0700 Subject: Removing usrp, usrp2, gr-usrp, gr-usrp2. Everything is moving to using UHD. Also removes related M4 and dependency requirements for USRP-related libs. --- grc/python/extract_docs.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'grc/python/extract_docs.py') diff --git a/grc/python/extract_docs.py b/grc/python/extract_docs.py index be55fd239..fe157a221 100644 --- a/grc/python/extract_docs.py +++ b/grc/python/extract_docs.py @@ -26,7 +26,7 @@ DOXYGEN_NAME_XPATH = '/doxygen/compounddef/compoundname' DOXYGEN_BRIEFDESC_GR_XPATH = '/doxygen/compounddef/briefdescription' DOXYGEN_DETAILDESC_GR_XPATH = '/doxygen/compounddef/detaileddescription' -GROUP_KEYS = "gr|usrp2|trellis|noaa|vocoder|digital" +GROUP_KEYS = "gr|trellis|noaa|vocoder|digital" def extract_txt(xml): """ @@ -65,7 +65,6 @@ def _extract(key): #extract descriptions comp_name = extract_txt(xml.xpath(DOXYGEN_NAME_XPATH)[0]).strip() comp_name = ' --- ' + comp_name + ' --- ' -# if re.match('(gr|usrp2|trellis|noaa)_.*', key): 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() -- cgit From 7b57dae20bb182561fcda78e5eeec44e44f0a9fb Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 17 Nov 2011 07:59:50 -0800 Subject: grc: replaced doxygen extracted docs with python docstrings --- grc/python/extract_docs.py | 58 +++++++++++----------------------------------- 1 file changed, 13 insertions(+), 45 deletions(-) (limited to 'grc/python/extract_docs.py') diff --git a/grc/python/extract_docs.py b/grc/python/extract_docs.py index fe157a221..a7e945c37 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() -- cgit From d2e8ec96084a26127907fe1cee2f15871d67b60d Mon Sep 17 00:00:00 2001 From: Julien Olivain Date: Mon, 18 Feb 2013 16:01:46 -0500 Subject: GRC: adds ability for grc to pull in documentation for blocks from other GR modules. --- grc/python/extract_docs.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'grc/python/extract_docs.py') diff --git a/grc/python/extract_docs.py b/grc/python/extract_docs.py index a7e945c37..33c404362 100644 --- a/grc/python/extract_docs.py +++ b/grc/python/extract_docs.py @@ -31,7 +31,13 @@ def _extract(key): module_name, constructor_name = key.split('_', 1) module = __import__('gnuradio.'+module_name) module = getattr(module, module_name) - except: return '' + except ImportError: + try: + module_name, constructor_name = key.split('_', 1) + module = __import__(module_name) + except: return '' + 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)) -- cgit