]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Factor out the XML API so other scripts can use it.
authorbbahnsen <bbahnsen@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 5 Dec 2006 21:57:04 +0000 (21:57 +0000)
committerbbahnsen <bbahnsen@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 5 Dec 2006 21:57:04 +0000 (21:57 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2049 6f19259b-4bc3-4df7-8a09-765794883524

Tools/Python/XmlRoutines.py [new file with mode: 0755]
Tools/Python/calcdeps.py

diff --git a/Tools/Python/XmlRoutines.py b/Tools/Python/XmlRoutines.py
new file mode 100755 (executable)
index 0000000..20671ea
--- /dev/null
@@ -0,0 +1,50 @@
+#!/usr/bin/env python
+
+# This is an XML API that uses a syntax similar to XPath, but it is written in
+# standard python so that no extra python packages are required to use it.
+
+import xml.dom.minidom
+
+def XmlList(Dom, String):
+  """Get a list of XML Elements using XPath style syntax."""
+  if Dom.nodeType==Dom.DOCUMENT_NODE:
+    return XmlList(Dom.documentElement, String)
+  if String[0] == "/":
+    return XmlList(Dom, String[1:])
+  if String == "" :
+    return []
+  TagList = String.split('/')
+  nodes = []
+  if Dom.nodeType == Dom.ELEMENT_NODE and Dom.tagName.strip() == TagList[0]:
+    if len(TagList) == 1:
+      nodes = [Dom]
+    else:
+      restOfPath = "/".join(TagList[1:])
+      for child in Dom.childNodes:
+        nodes = nodes + XmlList(child, restOfPath)
+  return nodes
+
+def XmlElement (Dom, String):
+  """Return a single element that matches the String which is XPath style syntax."""
+  try:
+    return XmlList (Dom, String)[0].firstChild.data.strip(' ')
+  except:
+    return ''
+
+def XmlElementData (Dom):
+  """Get the text for this element."""
+  return Dom.firstChild.data.strip(' ')
+
+def XmlAttribute (Dom, String):
+  """Return a single attribute that named by String."""
+  try:
+    return Dom.getAttribute(String)
+  except:
+    return ''
+
+# This acts like the main() function for the script, unless it is 'import'ed into another
+# script.
+if __name__ == '__main__':
+
+  # Nothing to do here. Could do some unit tests.
+  pass
index 5372bcce1db8e94c32304c8a35b00f2c8a2e135c..a0afa3f432c15853ba01d167e2bd12e80fb1f03b 100755 (executable)
@@ -5,6 +5,7 @@ code to see what guids and functions are referenced to see which Packages and
 Library Classes need to be referenced. """
 
 import os, sys, re, getopt, string, glob, xml.dom.minidom, pprint
+from XmlRoutines import *
 
 # Map each function name back to the lib class that declares it.
 function_table = {}
@@ -12,43 +13,6 @@ function_table = {}
 # Map each guid name to a package name.
 cname_table = {}
 
-def XmlList(Dom, String):
-  """Get a list of XML Elements using XPath style syntax."""
-  if Dom.nodeType==Dom.DOCUMENT_NODE:
-    return XmlList(Dom.documentElement, String)
-  if String[0] == "/":
-    return XmlList(Dom, String[1:])
-  if String == "" :
-    return []
-  TagList = String.split('/')
-  nodes = []
-  if Dom.nodeType == Dom.ELEMENT_NODE and Dom.tagName.strip() == TagList[0]:
-    if len(TagList) == 1:
-      nodes = [Dom]
-    else:
-      restOfPath = "/".join(TagList[1:])
-      for child in Dom.childNodes:
-        nodes = nodes + XmlList(child, restOfPath)
-  return nodes
-
-def XmlElement (Dom, String):
-  """Return a single element that matches the String which is XPath style syntax."""
-  try:
-    return XmlList (Dom, String)[0].firstChild.data.strip(' ')
-  except:
-    return ''
-
-def XmlElementData (Dom):
-  """Get the text for this element."""
-  return Dom.firstChild.data.strip(' ')
-
-def XmlAttribute (Dom, String):
-  """Return a single attribute that named by String."""
-  try:
-    return Dom.getAttribute(String)
-  except:
-    return ''
-
 def inWorkspace(rel_path):
   """Treat the given path as relative to the workspace."""