summaryrefslogtreecommitdiff
path: root/grc/python/extract_docs.py
diff options
context:
space:
mode:
authormanojgudi2013-10-07 14:26:59 +0530
committermanojgudi2013-10-07 14:26:59 +0530
commit6bc92d66be9975d618ac4cd104e7f5ff6e8605f2 (patch)
tree3a77657667b4ef037f712ee68a5ec86c86cba5c5 /grc/python/extract_docs.py
parent452defdb4a78e9e826740ddf4b9673e926c568a4 (diff)
parente9576e44ef8f0ad67d8cd8a4e025a0f8da0727f8 (diff)
downloadgnuradio-6bc92d66be9975d618ac4cd104e7f5ff6e8605f2.tar.gz
gnuradio-6bc92d66be9975d618ac4cd104e7f5ff6e8605f2.tar.bz2
gnuradio-6bc92d66be9975d618ac4cd104e7f5ff6e8605f2.zip
merge from gr36_ni branch
Diffstat (limited to 'grc/python/extract_docs.py')
-rw-r--r--grc/python/extract_docs.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/grc/python/extract_docs.py b/grc/python/extract_docs.py
new file mode 100644
index 000000000..33c404362
--- /dev/null
+++ b/grc/python/extract_docs.py
@@ -0,0 +1,66 @@
+"""
+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
+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
+"""
+
+import re
+
+def _extract(key):
+ """
+ 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
+ """
+ #extract matches
+ try:
+ module_name, constructor_name = key.split('_', 1)
+ module = __import__('gnuradio.'+module_name)
+ module = getattr(module, module_name)
+ 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))
+ #combine all matches
+ doc_strs = list()
+ for match in matches:
+ try:
+ 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()
+def extract(key):
+ """
+ Call the private extract and cache the result.
+ @param key the block key
+ @return a string with documentation
+ """
+ if not _docs_cache.has_key(key):
+ _docs_cache[key] = _extract(key)
+ return _docs_cache[key]
+
+if __name__ == '__main__':
+ import sys
+ print extract(sys.argv[1])