Commit 483b0089 authored by maruel@chromium.org's avatar maruel@chromium.org

Slowly start moving XML parsing function in gcl to glcient.

Review URL: http://codereview.chromium.org/115040

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@15497 0039d316-1c4b-4281-b951-d872f2087c98
parent cf1e53b6
...@@ -258,20 +258,6 @@ solutions = [ ...@@ -258,20 +258,6 @@ solutions = [
## Generic utils ## Generic utils
def getText(nodelist):
"""
Return the concatenated text for the children of a list of DOM nodes.
"""
rc = []
for node in nodelist:
if node.nodeType == node.TEXT_NODE:
rc.append(node.data)
else:
rc.append(getText(node.childNodes))
return ''.join(rc)
def ParseXML(output): def ParseXML(output):
try: try:
return xml.dom.minidom.parseString(output) return xml.dom.minidom.parseString(output)
...@@ -279,6 +265,22 @@ def ParseXML(output): ...@@ -279,6 +265,22 @@ def ParseXML(output):
return None return None
def GetNamedNodeText(node, node_name):
child_nodes = node.getElementsByTagName(node_name)
if not child_nodes:
return None
assert len(child_nodes) == 1 and child_nodes[0].childNodes.length == 1
return child_nodes[0].firstChild.nodeValue
def GetNodeNamedAttributeText(node, node_name, attribute_name):
child_nodes = node.getElementsByTagName(node_name)
if not child_nodes:
return None
assert len(child_nodes) == 1
return child_nodes[0].getAttribute(attribute_name)
class Error(Exception): class Error(Exception):
"""gclient exception class.""" """gclient exception class."""
pass pass
...@@ -565,18 +567,22 @@ def CaptureSVNInfo(options, relpath, in_directory): ...@@ -565,18 +567,22 @@ def CaptureSVNInfo(options, relpath, in_directory):
Returns: Returns:
An object with fields corresponding to the output of 'svn info' An object with fields corresponding to the output of 'svn info'
""" """
info = CaptureSVN(options, ["info", "--xml", relpath], in_directory) dom = ParseXML(CaptureSVN(options, ["info", "--xml", relpath], in_directory))
dom = xml.dom.minidom.parseString(info)
# str() the getText() results because they may be returned as
# Unicode, which interferes with the higher layers matching up
# things in the deps dictionary.
result = PrintableObject() result = PrintableObject()
result.root = str(getText(dom.getElementsByTagName('root'))) if dom:
result.url = str(getText(dom.getElementsByTagName('url'))) # /info/entry/
result.uuid = str(getText(dom.getElementsByTagName('uuid'))) # url
result.revision = int(dom.getElementsByTagName('entry')[0].getAttribute( # reposityory/(root|uuid)
'revision')) # wc-info/(schedule|depth)
# commit/(author|date)
# str() the results because they may be returned as Unicode, which
# interferes with the higher layers matching up things in the deps
# dictionary.
result = PrintableObject()
result.root = str(GetNamedNodeText(dom, 'root'))
result.url = str(GetNamedNodeText(dom, 'url'))
result.uuid = str(GetNamedNodeText(dom, 'uuid'))
result.revision = int(GetNodeNamedAttributeText(dom, 'entry', 'revision'))
return result return result
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment