summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/grit/grit/grd_reader.py45
-rwxr-xr-xtools/grit/grit_info.py6
2 files changed, 35 insertions, 16 deletions
diff --git a/tools/grit/grit/grd_reader.py b/tools/grit/grit/grd_reader.py
index 82d06d9..9e72e38 100644
--- a/tools/grit/grit/grd_reader.py
+++ b/tools/grit/grit/grd_reader.py
@@ -24,7 +24,8 @@ class StopParsingException(Exception):
class GrdContentHandler(xml.sax.handler.ContentHandler):
- def __init__(self, stop_after=None, debug=False, defines=None):
+ def __init__(self,
+ stop_after=None, debug=False, defines=None, tags_to_ignore=None):
# Invariant of data:
# 'root' is the root of the parse tree being created, or None if we haven't
# parsed out any elements.
@@ -36,17 +37,28 @@ class GrdContentHandler(xml.sax.handler.ContentHandler):
self.stop_after = stop_after
self.debug = debug
self.defines = defines
+ self.tags_to_ignore = tags_to_ignore or set()
+ self.ignore_depth = 0
def startElement(self, name, attrs):
assert not self.root or len(self.stack) > 0
+ if name in self.tags_to_ignore:
+ self.ignore_depth += 1
+ if self.debug:
+ print "Ignoring element %s and its children" % name
+
+ if self.ignore_depth != 0:
+ return
+
if self.debug:
attr_list = []
for attr in attrs.getNames():
attr_list.append('%s="%s"' % (attr, attrs.getValue(attr)))
if len(attr_list) == 0: attr_list = ['(none)']
attr_list = ' '.join(attr_list)
- print "Starting parsing of element %s with attributes %r" % (name, attr_list)
+ print ("Starting parsing of element %s with attributes %r" %
+ (name, attr_list))
typeattr = None
if 'type' in attrs.getNames():
@@ -72,18 +84,23 @@ class GrdContentHandler(xml.sax.handler.ContentHandler):
node.HandleAttribute(attr, attrs.getValue(attr))
def endElement(self, name):
- if self.debug:
- print "End parsing of element %s" % name
- # Pop
- self.stack[-1].EndParsing()
- assert len(self.stack) > 0
- self.stack = self.stack[:-1]
- if self.stop_after and name == self.stop_after:
- raise StopParsingException()
+ if self.ignore_depth == 0:
+ if self.debug:
+ print "End parsing of element %s" % name
+ # Pop
+ self.stack[-1].EndParsing()
+ assert len(self.stack) > 0
+ self.stack = self.stack[:-1]
+ if self.stop_after and name == self.stop_after:
+ raise StopParsingException()
+
+ if name in self.tags_to_ignore:
+ self.ignore_depth -= 1
def characters(self, content):
- if self.stack[-1]:
- self.stack[-1].AppendContent(content)
+ if self.ignore_depth == 0:
+ if self.stack[-1]:
+ self.stack[-1].AppendContent(content)
def ignorableWhitespace(self, whitespace):
# TODO(joi) This is not supported by expat. Should use a different XML parser?
@@ -92,7 +109,7 @@ class GrdContentHandler(xml.sax.handler.ContentHandler):
def Parse(filename_or_stream, dir=None, flexible_root=False,
stop_after=None, debug=False, first_id_filename=None,
- defines=None):
+ defines=None, tags_to_ignore=None):
'''Parses a GRD file into a tree of nodes (from grit.node).
If flexible_root is False, the root node must be a <grit> element. Otherwise
@@ -127,7 +144,7 @@ def Parse(filename_or_stream, dir=None, flexible_root=False,
grit.exception.Parsing
'''
handler = GrdContentHandler(stop_after=stop_after, debug=debug,
- defines=defines)
+ defines=defines, tags_to_ignore=tags_to_ignore)
try:
xml.sax.parse(filename_or_stream, handler)
except StopParsingException:
diff --git a/tools/grit/grit_info.py b/tools/grit/grit_info.py
index 55119ad..c0e0ed8 100755
--- a/tools/grit/grit_info.py
+++ b/tools/grit/grit_info.py
@@ -16,7 +16,8 @@ from grit import util
def Outputs(filename, defines):
- grd = grd_reader.Parse(filename, defines=defines)
+ grd = grd_reader.Parse(
+ filename, defines=defines, tags_to_ignore=set(['messages']))
target = []
lang_folders = {}
@@ -47,7 +48,8 @@ def Outputs(filename, defines):
def Inputs(filename, defines):
- grd = grd_reader.Parse(filename, debug=False, defines=defines)
+ grd = grd_reader.Parse(
+ filename, debug=False, defines=defines, tags_to_ignore=set(['messages']))
files = []
for node in grd:
if (node.name == 'structure' or node.name == 'skeleton' or