commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r11099 - in gnuradio/trunk/grc: . src/platforms/python


From: jblum
Subject: [Commit-gnuradio] r11099 - in gnuradio/trunk/grc: . src/platforms/python/utils
Date: Sat, 23 May 2009 13:41:31 -0600 (MDT)

Author: jblum
Date: 2009-05-23 13:41:31 -0600 (Sat, 23 May 2009)
New Revision: 11099

Modified:
   gnuradio/trunk/grc/src/platforms/python/utils/extract_docs.py
   gnuradio/trunk/grc/todo.txt
Log:
Replaced the is_match function with regular expression.
Cache the results of the doc extraction.
Removed support for blks2 docs until that is sorted out.

The matching will handle any file extension,
as to also support .xml.gz files in the gnuradio-docs deb. 



Modified: gnuradio/trunk/grc/src/platforms/python/utils/extract_docs.py
===================================================================
--- gnuradio/trunk/grc/src/platforms/python/utils/extract_docs.py       
2009-05-23 18:45:35 UTC (rev 11098)
+++ gnuradio/trunk/grc/src/platforms/python/utils/extract_docs.py       
2009-05-23 19:41:31 UTC (rev 11099)
@@ -20,12 +20,11 @@
 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'
-DOXYGEN_BRIEFDESC_BLKS2_XPATH = 
'/doxygen/compounddef/address@hidden"public-func"]/memberdef/briefdescription'
-DOXYGEN_DETAILDESC_BLKS2_XPATH = 
'/doxygen/compounddef/address@hidden"public-func"]/memberdef/detaileddescription'
 
 def extract_txt(xml, parent_text=None):
        """
@@ -40,38 +39,8 @@
                map(lambda x: extract_txt(x, text), xml)
        ) + tail
 
-def is_match(key, file):
+def _extract(key):
        """
-       Is the block key a match for the given file name?
-       @param key block key
-       @param file the xml file name
-       @return true if matches
-       """
-       if not file.endswith('.xml'): return False
-       file = file.replace('.xml', '') #remove file ext
-       file = file.replace('__', '_') #doxygen xml files have 2 underscores
-       if key.startswith('gr_'):
-               if not file.startswith('classgr_'): return False
-               key = key.replace('gr_', 'classgr_')
-       elif key.startswith('trellis_'):
-               if not file.startswith('classtrellis_'): return False
-               key = key.replace('trellis_', 'classtrellis_')
-       elif key.startswith('blks2_'):
-               if not file.startswith('classgnuradio_'): return False
-               if 'blks2' not in file: return False
-               file = file.replace('_1_1', '_') #weird blks2 doxygen syntax
-               key = key.replace('blks2_', '')
-       else: return False
-       for k, f in zip(*map(reversed, map(lambda x: x.split('_'), [key, 
file]))):
-               if k == f: continue
-               ks = k.split('x')
-               if len(ks) == 2 and f.startswith(ks[0]) and f.endswith(ks[1]): 
continue
-               if len(ks) > 2 and all(ki in ('x', fi) for ki, fi in zip(k, 
f)): continue
-               return False
-       return True
-
-def extract(key):
-       """
        Extract the documentation from the doxygen generated xml files.
        If multiple files match, combine the docs.
        @param key the block key
@@ -82,7 +51,9 @@
        elif os.path.exists(UBUNTU_DOCS_DIR): docs_dir = UBUNTU_DOCS_DIR
        else: return ''
        #extract matches
-       matches = filter(lambda f: is_match(key, f), os.listdir(docs_dir))
+       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:
@@ -95,9 +66,6 @@
                        if key.startswith('gr_') or key.startswith('trellis_'):
                                brief_desc = 
extract_txt(xml.xpath(DOXYGEN_BRIEFDESC_GR_XPATH)[0]).strip('\n')
                                detailed_desc = 
extract_txt(xml.xpath(DOXYGEN_DETAILDESC_GR_XPATH)[0]).strip('\n')
-                       elif key.startswith('blks2_'):
-                               brief_desc = 
extract_txt(xml.xpath(DOXYGEN_BRIEFDESC_BLKS2_XPATH)[0]).strip('\n')
-                               detailed_desc = 
extract_txt(xml.xpath(DOXYGEN_DETAILDESC_BLKS2_XPATH)[0]).strip('\n')
                        else:
                                brief_desc = ''
                                detailed_desc = ''
@@ -106,6 +74,17 @@
                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])

Modified: gnuradio/trunk/grc/todo.txt
===================================================================
--- gnuradio/trunk/grc/todo.txt 2009-05-23 18:45:35 UTC (rev 11098)
+++ gnuradio/trunk/grc/todo.txt 2009-05-23 19:41:31 UTC (rev 11099)
@@ -25,4 +25,3 @@
 -save/restore cwd
 -threads dont die on exit in probe and variable sink
 -overloaded gui classes for each platform, move param input objects into 
overloaded
--update extract_docs.py for current doxygen setup





reply via email to

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