Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Unified Diff: gclient.py

Issue 115040: Slowly start moving XML parsing function in gcl to glcient. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools/
Patch Set: Created 11 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gclient.py
===================================================================
--- gclient.py (revision 15439)
+++ gclient.py (working copy)
@@ -258,20 +258,6 @@
## 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):
try:
return xml.dom.minidom.parseString(output)
@@ -279,6 +265,22 @@
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):
"""gclient exception class."""
pass
@@ -565,18 +567,22 @@
Returns:
An object with fields corresponding to the output of 'svn info'
"""
- info = 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.
+ dom = ParseXML(CaptureSVN(options, ["info", "--xml", relpath], in_directory))
result = PrintableObject()
- result.root = str(getText(dom.getElementsByTagName('root')))
- result.url = str(getText(dom.getElementsByTagName('url')))
- result.uuid = str(getText(dom.getElementsByTagName('uuid')))
- result.revision = int(dom.getElementsByTagName('entry')[0].getAttribute(
- 'revision'))
+ if dom:
+ # /info/entry/
+ # url
+ # reposityory/(root|uuid)
+ # 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698