[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r8434 - in grc/trunk/src: grc grc/elements grc_gnuradi
From: |
jblum |
Subject: |
[Commit-gnuradio] r8434 - in grc/trunk/src: grc grc/elements grc_gnuradio |
Date: |
Fri, 16 May 2008 11:43:00 -0600 (MDT) |
Author: jblum
Date: 2008-05-16 11:42:58 -0600 (Fri, 16 May 2008)
New Revision: 8434
Modified:
grc/trunk/src/grc/Constants.py
grc/trunk/src/grc/ParseXML.py
grc/trunk/src/grc/elements/Block.py
grc/trunk/src/grc/elements/Platform.py
grc/trunk/src/grc_gnuradio/extract_docs.py
Log:
updated extract docs to lxml and xpath
Modified: grc/trunk/src/grc/Constants.py
===================================================================
--- grc/trunk/src/grc/Constants.py 2008-05-16 17:29:29 UTC (rev 8433)
+++ grc/trunk/src/grc/Constants.py 2008-05-16 17:42:58 UTC (rev 8434)
@@ -75,7 +75,7 @@
address@hidden
##dialog constraints @{
-MIN_DIALOG_WIDTH = 400
+MIN_DIALOG_WIDTH = 500
MIN_DIALOG_HEIGHT = 500
address@hidden
Modified: grc/trunk/src/grc/ParseXML.py
===================================================================
--- grc/trunk/src/grc/ParseXML.py 2008-05-16 17:29:29 UTC (rev 8433)
+++ grc/trunk/src/grc/ParseXML.py 2008-05-16 17:42:58 UTC (rev 8434)
@@ -22,6 +22,8 @@
from lxml import etree
from Utils import odict
+
+XMLSyntaxError = etree.XMLSyntaxError
def validate_dtd(xml_file, dtd_file=None):
"""!
@@ -34,7 +36,7 @@
dtd = etree.DTD(dtd_file)
xml = etree.parse(xml_file)
if not dtd.validate(xml.getroot()):
- raise Exception, '\n'.join(map(str,
dtd.error_log.filter_from_errors()))
+ raise XMLSyntaxError, '\n'.join(map(str,
dtd.error_log.filter_from_errors()))
else:
parser = etree.XMLParser(dtd_validation=True)
xml = etree.parse(xml_file, parser=parser)
Modified: grc/trunk/src/grc/elements/Block.py
===================================================================
--- grc/trunk/src/grc/elements/Block.py 2008-05-16 17:29:29 UTC (rev 8433)
+++ grc/trunk/src/grc/elements/Block.py 2008-05-16 17:42:58 UTC (rev 8434)
@@ -135,8 +135,8 @@
try:
check_eval =
self.get_parent().evaluate(check_res)
try: assert(check_eval)
- except AssertionError:
self._add_error_message('Check "%s" failed.'%check_res)
- except: self._add_error_message('Check "%s" did not
evaluate.'%check_res)
+ except AssertionError:
self._add_error_message('Check "%s" failed.'%check)
+ except: self._add_error_message('Check "%s" did not
evaluate.'%check)
def __str__(self): return 'Block - %s - %s(%s)'%(self.get_id(),
self.get_name(), self.get_key())
Modified: grc/trunk/src/grc/elements/Platform.py
===================================================================
--- grc/trunk/src/grc/elements/Platform.py 2008-05-16 17:29:29 UTC (rev
8433)
+++ grc/trunk/src/grc/elements/Platform.py 2008-05-16 17:42:58 UTC (rev
8434)
@@ -64,7 +64,7 @@
def _load_block(self, f):
try: ParseXML.validate_dtd(f)
- except Exception, e: self._exit_with_error('Block definition
"%s" failed: \n\t%s'%(f, e))
+ except ParseXML.XMLSyntaxError, e: self._exit_with_error('Block
definition "%s" failed: \n\t%s'%(f, e))
n = ParseXML.from_file(f)['block']
block = self.Block(self.flow_graph, n)
key = block.get_key()
@@ -84,7 +84,7 @@
def get_block_tree(self):
f = self._block_tree
try: ParseXML.validate_dtd(f, DATA_DIR + '/block_tree.dtd')
- except Exception, e: self._exit_with_error('Block tree "%s"
failed: \n\t%s'%(f, e))
+ except ParseXML.XMLSyntaxError, e: self._exit_with_error('Block
tree "%s" failed: \n\t%s'%(f, e))
n = ParseXML.from_file(f)['block_tree']
return n
Modified: grc/trunk/src/grc_gnuradio/extract_docs.py
===================================================================
--- grc/trunk/src/grc_gnuradio/extract_docs.py 2008-05-16 17:29:29 UTC (rev
8433)
+++ grc/trunk/src/grc_gnuradio/extract_docs.py 2008-05-16 17:42:58 UTC (rev
8434)
@@ -20,52 +20,25 @@
#Extract documentation from the gnuradio doxygen files.
address@hidden Josh Blum
-from grc import ParseXML
+from lxml import etree
import os
DOCS_DIR = '/usr/local/share/doc/grc_gnuradio_docs/'
-DOXYGEN_NAME_INST = ('doxygen', 'compounddef', 'compoundname')
-DOXYGEN_BRIEFDESC_GR_INST = ('doxygen', 'compounddef', 'briefdescription')
-DOXYGEN_DETAILDESC_GR_INST = ('doxygen', 'compounddef', 'detaileddescription')
-DOXYGEN_BRIEFDESC_BLKS2_INST = ('doxygen', 'compounddef', ('sectiondef',
{'kind': 'public-func'}), 'memberdef', 'briefdescription')
-DOXYGEN_DETAILDESC_BLKS2_INST = ('doxygen', 'compounddef', ('sectiondef',
{'kind': 'public-func'}), 'memberdef', 'detaileddescription')
+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 get_xml_entity(xml_file, instructions):
+def extract_txt(xml):
"""!
- Get an xml entity from the file by following the given path.
- @param xml_file the path to the xml file
- @param instructions the specification to search the xml doc
- @return the xml entity or None if not found
- """
- doc = ParseXML.from_file(xml_file)
- for inst in instructions:
- #split up the intruction if it is a tuple or list
- if isinstance(inst, (tuple, list)): tag, attrs = inst
- else: tag, attrs = inst, {}
- #look through each child node
- childMatch = None
- for childNode in doc.childNodes:
- if str(childNode.localName) == str(tag):
- #if child node has no attributes, attrs must be
empty
- if not childNode.hasAttributes():
- if attrs: continue
- childMatch = childNode
- break
- if all(str(childNode.getAttribute(k)) == str(v)
for k,v in attrs.iteritems()):
- childMatch = childNode
- break
- if not childMatch: return None
- doc = childMatch
- return doc
-
-def extract_txt(doc):
- """!
- Recursivly pull the text out of an xml document.
- @param doc the xml document
+ Recursivly pull the text out of an xml tree.
+ @param xml the xml tree
@return a string
"""
- if len(doc.childNodes) == 0: return str(doc.nodeValue)
- return ''.join(map(extract_txt, doc.childNodes)).strip('\n')
+ text = xml.text or ''
+ if not len(xml): return text
+ return ''.join([text] + map(extract_txt, xml))
def is_match(key, file):
"""!
@@ -94,7 +67,7 @@
If multiple files match, combine the docs.
@param key the block key
@return a string with documentation
- """
+ """
#get potential xml file matches for the key
if os.path.exists(DOCS_DIR) and os.path.isdir(DOCS_DIR):
matches = filter(lambda f: is_match(key, f),
os.listdir(DOCS_DIR))
@@ -103,15 +76,16 @@
doc_strs = list()
for match in matches:
xml_file = DOCS_DIR + '/' + match
+ xml = etree.parse(xml_file)
#extract descriptions
- comp_name = extract_txt(get_xml_entity(xml_file,
DOXYGEN_NAME_INST))
+ comp_name =
extract_txt(xml.xpath(DOXYGEN_NAME_XPATH)[0]).strip('\n')
comp_name = ' --- ' + comp_name + ' --- '
if key.startswith('gr_'):
- brief_desc = extract_txt(get_xml_entity(xml_file,
DOXYGEN_BRIEFDESC_GR_INST))
- detailed_desc = extract_txt(get_xml_entity(xml_file,
DOXYGEN_DETAILDESC_GR_INST))
+ 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(get_xml_entity(xml_file,
DOXYGEN_BRIEFDESC_BLKS2_INST))
- detailed_desc = extract_txt(get_xml_entity(xml_file,
DOXYGEN_DETAILDESC_BLKS2_INST))
+ 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 = ''
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r8434 - in grc/trunk/src: grc grc/elements grc_gnuradio,
jblum <=