mirror of https://github.com/acidanthera/audk.git
- Merged the local copy of XmlRoutines.py in buildgen into upper directory's XmlRoutines.py
- Removed the local copy of XmlRoutines.py in buildgen/AntTasks.pyc - Used the XmlNode to replace XmlElement in SurfaceAreaElement.py git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2310 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
253fca1de3
commit
2082f93671
|
@ -16,44 +16,70 @@ import xml.dom.minidom
|
||||||
|
|
||||||
def XmlList(Dom, String):
|
def XmlList(Dom, String):
|
||||||
"""Get a list of XML Elements using XPath style syntax."""
|
"""Get a list of XML Elements using XPath style syntax."""
|
||||||
if String == "" :
|
if String == None or String == "" or Dom == None or Dom == "":
|
||||||
return []
|
return []
|
||||||
if Dom.nodeType==Dom.DOCUMENT_NODE:
|
if Dom.nodeType==Dom.DOCUMENT_NODE:
|
||||||
return XmlList(Dom.documentElement, String)
|
Dom = Dom.documentElement
|
||||||
if String[0] == "/":
|
if String[0] == "/":
|
||||||
return XmlList(Dom, String[1:])
|
String = String[1:]
|
||||||
TagList = String.split('/')
|
tagList = String.split('/')
|
||||||
nodes = []
|
|
||||||
if Dom.nodeType == Dom.ELEMENT_NODE and Dom.tagName.strip() == TagList[0]:
|
|
||||||
if len(TagList) == 1:
|
|
||||||
nodes = [Dom]
|
nodes = [Dom]
|
||||||
|
index = 0
|
||||||
|
end = len(tagList) - 1
|
||||||
|
while index <= end:
|
||||||
|
childNodes = []
|
||||||
|
for node in nodes:
|
||||||
|
if node.nodeType == node.ELEMENT_NODE and node.tagName == tagList[index]:
|
||||||
|
if index < end:
|
||||||
|
childNodes.extend(node.childNodes)
|
||||||
else:
|
else:
|
||||||
restOfPath = "/".join(TagList[1:])
|
childNodes.append(node)
|
||||||
for child in Dom.childNodes:
|
nodes = childNodes
|
||||||
nodes = nodes + XmlList(child, restOfPath)
|
childNodes = []
|
||||||
|
index += 1
|
||||||
|
|
||||||
return nodes
|
return nodes
|
||||||
|
|
||||||
def XmlNode (Dom, String):
|
def XmlNode (Dom, String):
|
||||||
"""Return a single node that matches the String which is XPath style syntax."""
|
"""Return a single node that matches the String which is XPath style syntax."""
|
||||||
try:
|
if String == None or String == "" or Dom == None or Dom == "":
|
||||||
return XmlList (Dom, String)[0]
|
return ""
|
||||||
except:
|
if Dom.nodeType==Dom.DOCUMENT_NODE:
|
||||||
return None
|
Dom = Dom.documentElement
|
||||||
|
if String[0] == "/":
|
||||||
|
String = String[1:]
|
||||||
|
tagList = String.split('/')
|
||||||
|
index = 0
|
||||||
|
end = len(tagList) - 1
|
||||||
|
childNodes = [Dom]
|
||||||
|
while index <= end:
|
||||||
|
for node in childNodes:
|
||||||
|
if node.nodeType == node.ELEMENT_NODE and node.tagName == tagList[index]:
|
||||||
|
if index < end:
|
||||||
|
childNodes = node.childNodes
|
||||||
|
else:
|
||||||
|
return node
|
||||||
|
break
|
||||||
|
index += 1
|
||||||
|
return ""
|
||||||
|
|
||||||
def XmlElement (Dom, String):
|
def XmlElement (Dom, String):
|
||||||
"""Return a single element that matches the String which is XPath style syntax."""
|
"""Return a single element that matches the String which is XPath style syntax."""
|
||||||
try:
|
try:
|
||||||
return XmlList (Dom, String)[0].firstChild.data.strip()
|
return XmlNode (Dom, String).firstChild.data.strip()
|
||||||
except:
|
except:
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
def XmlElementData (Dom):
|
def XmlElementData (Dom):
|
||||||
"""Get the text for this element."""
|
"""Get the text for this element."""
|
||||||
|
if Dom == None or Dom == '' or Dom.firstChild == None:
|
||||||
|
return ''
|
||||||
return Dom.firstChild.data.strip()
|
return Dom.firstChild.data.strip()
|
||||||
|
|
||||||
def XmlAttribute (Dom, AttName):
|
def XmlAttribute (Dom, AttName):
|
||||||
"""Return a single attribute named AttName."""
|
"""Return a single attribute named AttName."""
|
||||||
|
if Dom == None or Dom == '':
|
||||||
|
return ''
|
||||||
try:
|
try:
|
||||||
return Dom.getAttribute(AttName)
|
return Dom.getAttribute(AttName)
|
||||||
except:
|
except:
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
#
|
#
|
||||||
# TODO: FFS layout, Flash, FV, PCD
|
# TODO: FFS layout, Flash, FV, PCD
|
||||||
#
|
#
|
||||||
import os, sys, re, getopt, string, glob, xml.dom.minidom, pprint, time, copy, shelve
|
import os, sys, re, getopt, string, glob, xml.dom.minidom, pprint, time, copy, shelve, pickle
|
||||||
from XmlRoutines import *
|
from XmlRoutines import *
|
||||||
import FrameworkElement
|
import FrameworkElement
|
||||||
import BuildConfig
|
import BuildConfig
|
||||||
|
@ -243,7 +243,7 @@ class LibraryDeclaration(FrameworkElement.LibraryInterface, SurfaceAreaElement):
|
||||||
def Parse(self):
|
def Parse(self):
|
||||||
dom = self._Root
|
dom = self._Root
|
||||||
self.Name = XmlAttribute(dom, "Name")
|
self.Name = XmlAttribute(dom, "Name")
|
||||||
self.Path = os.path.normpath(XmlElementData(XmlElement(dom, "/LibraryClass/IncludeHeader")))
|
self.Path = os.path.normpath(XmlElementData(XmlNode(dom, "/LibraryClass/IncludeHeader")))
|
||||||
self.Dir = os.path.dirname(self.Path)
|
self.Dir = os.path.dirname(self.Path)
|
||||||
|
|
||||||
attribute = XmlAttribute(dom, "RecommendedInstanceGuid")
|
attribute = XmlAttribute(dom, "RecommendedInstanceGuid")
|
||||||
|
@ -268,7 +268,7 @@ class LibraryClass(FrameworkElement.LibraryClass, SurfaceAreaElement):
|
||||||
def Parse(self):
|
def Parse(self):
|
||||||
dom = self._Root
|
dom = self._Root
|
||||||
|
|
||||||
self.Name = XmlElementData(XmlElement(dom, "/LibraryClass/Keyword"))
|
self.Name = XmlElementData(XmlNode(dom, "/LibraryClass/Keyword"))
|
||||||
self.Usage = self.GetUsage(dom)
|
self.Usage = self.GetUsage(dom)
|
||||||
self.Features = self.GetFeatureList(dom)
|
self.Features = self.GetFeatureList(dom)
|
||||||
self.Archs = self.GetArchList(dom)
|
self.Archs = self.GetArchList(dom)
|
||||||
|
@ -336,7 +336,7 @@ class Protocol(FrameworkElement.Protocol, SurfaceAreaElement):
|
||||||
|
|
||||||
def Parse(self):
|
def Parse(self):
|
||||||
dom = self._Root
|
dom = self._Root
|
||||||
self.CName = XmlElementData(XmlElement(dom, "/Protocol/ProtocolCName"))
|
self.CName = XmlElementData(XmlNode(dom, "/Protocol/ProtocolCName"))
|
||||||
self.Usage = self.GetUsage(dom)
|
self.Usage = self.GetUsage(dom)
|
||||||
self.Archs = self.GetArchList(dom)
|
self.Archs = self.GetArchList(dom)
|
||||||
self.Features = self.GetFeatureList(dom)
|
self.Features = self.GetFeatureList(dom)
|
||||||
|
@ -354,7 +354,7 @@ class ProtocolNotify(FrameworkElement.ProtocolNotify, SurfaceAreaElement):
|
||||||
def Parse(self):
|
def Parse(self):
|
||||||
dom = self._Root
|
dom = self._Root
|
||||||
|
|
||||||
self.CName = XmlElementData(XmlElement(dom, "/ProtocolNotify/ProtocolCName"))
|
self.CName = XmlElementData(XmlNode(dom, "/ProtocolNotify/ProtocolCName"))
|
||||||
self.Usage = self.GetUsage(dom)
|
self.Usage = self.GetUsage(dom)
|
||||||
self.Archs = self.GetArchList(dom)
|
self.Archs = self.GetArchList(dom)
|
||||||
self.Features = self.GetFeatureList(dom)
|
self.Features = self.GetFeatureList(dom)
|
||||||
|
@ -371,7 +371,7 @@ class Ppi(FrameworkElement.Ppi, SurfaceAreaElement):
|
||||||
|
|
||||||
def Parse(self):
|
def Parse(self):
|
||||||
dom = self._Root
|
dom = self._Root
|
||||||
self.CName = XmlElementData(XmlElement(dom, "/Ppi/PpiCName"))
|
self.CName = XmlElementData(XmlNode(dom, "/Ppi/PpiCName"))
|
||||||
self.Usage = self.GetUsage(dom)
|
self.Usage = self.GetUsage(dom)
|
||||||
self.Archs = self.GetArchList(dom)
|
self.Archs = self.GetArchList(dom)
|
||||||
self.Features = self.GetFeatureList(dom)
|
self.Features = self.GetFeatureList(dom)
|
||||||
|
@ -388,7 +388,7 @@ class PpiNotify(FrameworkElement.PpiNotify, SurfaceAreaElement):
|
||||||
|
|
||||||
def Parse(self):
|
def Parse(self):
|
||||||
dom = self._Root
|
dom = self._Root
|
||||||
self.CName = XmlElementData(XmlElement(dom, "/PpiNotify/PpiCName"))
|
self.CName = XmlElementData(XmlNode(dom, "/PpiNotify/PpiCName"))
|
||||||
self.Usage = self.GetUsage(dom)
|
self.Usage = self.GetUsage(dom)
|
||||||
self.Archs = self.GetArchList(dom)
|
self.Archs = self.GetArchList(dom)
|
||||||
self.Features = self.GetFeatureList(dom)
|
self.Features = self.GetFeatureList(dom)
|
||||||
|
@ -405,7 +405,7 @@ class Guid(FrameworkElement.Guid, SurfaceAreaElement):
|
||||||
|
|
||||||
def Parse(self):
|
def Parse(self):
|
||||||
dom = self._Root
|
dom = self._Root
|
||||||
self.CName = XmlElementData(XmlElement(dom, "/GuidCNames/GuidCName"))
|
self.CName = XmlElementData(XmlNode(dom, "/GuidCNames/GuidCName"))
|
||||||
self.Usage = self.GetUsage(dom)
|
self.Usage = self.GetUsage(dom)
|
||||||
self.Archs = self.GetArchList(dom)
|
self.Archs = self.GetArchList(dom)
|
||||||
self.Features = self.GetFeatureList(dom)
|
self.Features = self.GetFeatureList(dom)
|
||||||
|
@ -425,43 +425,43 @@ class Extern(FrameworkElement.Extern, SurfaceAreaElement):
|
||||||
self.Archs = self.GetArchList(dom)
|
self.Archs = self.GetArchList(dom)
|
||||||
self.Features = self.GetFeatureList(dom)
|
self.Features = self.GetFeatureList(dom)
|
||||||
|
|
||||||
extern = XmlElement(dom, "/Extern/ModuleEntryPoint")
|
extern = XmlNode(dom, "/Extern/ModuleEntryPoint")
|
||||||
if extern is not None and extern is not '':
|
if extern is not None and extern is not '':
|
||||||
self.ModuleEntryPoints.append(XmlElementData(extern))
|
self.ModuleEntryPoints.append(XmlElementData(extern))
|
||||||
|
|
||||||
extern = XmlElement(dom, "/Extern/ModuleUnloadImage")
|
extern = XmlNode(dom, "/Extern/ModuleUnloadImage")
|
||||||
if extern is not None and extern is not '':
|
if extern is not None and extern is not '':
|
||||||
self.ModuleUnloadImages.append(XmlElementData(extern))
|
self.ModuleUnloadImages.append(XmlElementData(extern))
|
||||||
|
|
||||||
extern = XmlElement(dom, "/Extern/Constructor")
|
extern = XmlNode(dom, "/Extern/Constructor")
|
||||||
if extern is not None and extern is not '':
|
if extern is not None and extern is not '':
|
||||||
self.Constructors.append(XmlElementData(extern))
|
self.Constructors.append(XmlElementData(extern))
|
||||||
|
|
||||||
extern = XmlElement(dom, "/Extern/Destructor")
|
extern = XmlNode(dom, "/Extern/Destructor")
|
||||||
if extern is not None and extern is not '':
|
if extern is not None and extern is not '':
|
||||||
self.Destructors.append(XmlElementData(extern))
|
self.Destructors.append(XmlElementData(extern))
|
||||||
|
|
||||||
extern = XmlElement(dom, "/Extern/DriverBinding")
|
extern = XmlNode(dom, "/Extern/DriverBinding")
|
||||||
if extern is not None and extern is not '':
|
if extern is not None and extern is not '':
|
||||||
self.DriverBindings.append(XmlElementData(extern))
|
self.DriverBindings.append(XmlElementData(extern))
|
||||||
|
|
||||||
extern = XmlElement(dom, "/Extern/ComponentName")
|
extern = XmlNode(dom, "/Extern/ComponentName")
|
||||||
if extern is not None and extern is not '':
|
if extern is not None and extern is not '':
|
||||||
self.ComponentNames.append(XmlElementData(extern))
|
self.ComponentNames.append(XmlElementData(extern))
|
||||||
|
|
||||||
extern = XmlElement(dom, "/Extern/DriverConfig")
|
extern = XmlNode(dom, "/Extern/DriverConfig")
|
||||||
if extern is not None and extern is not '':
|
if extern is not None and extern is not '':
|
||||||
self.DriverConfigs.append(XmlElementData(extern))
|
self.DriverConfigs.append(XmlElementData(extern))
|
||||||
|
|
||||||
extern = XmlElement(dom, "/Extern/DriverDiag")
|
extern = XmlNode(dom, "/Extern/DriverDiag")
|
||||||
if extern is not None and extern is not '':
|
if extern is not None and extern is not '':
|
||||||
self.DriverDiags.append(XmlElementData(extern))
|
self.DriverDiags.append(XmlElementData(extern))
|
||||||
|
|
||||||
extern = XmlElement(dom, "/Extern/SetVirtualAddressMapCallBacks")
|
extern = XmlNode(dom, "/Extern/SetVirtualAddressMapCallBacks")
|
||||||
if extern is not None and extern is not '':
|
if extern is not None and extern is not '':
|
||||||
self.SetVirtualAddressMapCallBacks.append(XmlElementData(extern))
|
self.SetVirtualAddressMapCallBacks.append(XmlElementData(extern))
|
||||||
|
|
||||||
extern = XmlElement(dom, "/Extern/ExitBootServicesCallBack")
|
extern = XmlNode(dom, "/Extern/ExitBootServicesCallBack")
|
||||||
if extern is not None and extern is not '':
|
if extern is not None and extern is not '':
|
||||||
self.ExitBootServicesCallBacks.append(XmlElementData(extern))
|
self.ExitBootServicesCallBacks.append(XmlElementData(extern))
|
||||||
|
|
||||||
|
@ -472,7 +472,7 @@ class IndustryStdHeader(FrameworkElement.IncludeFile, SurfaceAreaElement):
|
||||||
|
|
||||||
def Parse(self):
|
def Parse(self):
|
||||||
dom = self._Root
|
dom = self._Root
|
||||||
self.Path = os.path.normpath(XmlElementData(XmlElement(dom, "/IndustryStdHeader/IncludeHeader")))
|
self.Path = os.path.normpath(XmlElementData(XmlNode(dom, "/IndustryStdHeader/IncludeHeader")))
|
||||||
self.Dir = os.path.dirname(self.Path)
|
self.Dir = os.path.dirname(self.Path)
|
||||||
self.Archs = self.GetArchList(dom)
|
self.Archs = self.GetArchList(dom)
|
||||||
self.ModuleTypes = self.GetModuleTypeList(dom)
|
self.ModuleTypes = self.GetModuleTypeList(dom)
|
||||||
|
@ -495,8 +495,8 @@ class GuidDeclaration(FrameworkElement.Guid, SurfaceAreaElement):
|
||||||
|
|
||||||
def Parse(self):
|
def Parse(self):
|
||||||
dom = self._Root
|
dom = self._Root
|
||||||
self.CName = XmlElementData(XmlElement(dom, "/Entry/C_Name"))
|
self.CName = XmlElementData(XmlNode(dom, "/Entry/C_Name"))
|
||||||
self.GuidValue = XmlElementData(XmlElement(dom, "/Entry/GuidValue")).upper()
|
self.GuidValue = XmlElementData(XmlNode(dom, "/Entry/GuidValue")).upper()
|
||||||
self.Name = XmlAttribute(dom, "Name")
|
self.Name = XmlAttribute(dom, "Name")
|
||||||
self.Types = self.GetGuidTypeList(dom)
|
self.Types = self.GetGuidTypeList(dom)
|
||||||
self.Archs = self.GetArchList(dom)
|
self.Archs = self.GetArchList(dom)
|
||||||
|
@ -518,12 +518,12 @@ class PcdDeclaration(FrameworkElement.Pcd, SurfaceAreaElement):
|
||||||
|
|
||||||
def Parse(self):
|
def Parse(self):
|
||||||
dom = self._Root
|
dom = self._Root
|
||||||
self.Types = XmlElementData(XmlElement(dom, "/PcdEntry/ValidUsage")).split()
|
self.Types = XmlElementData(XmlNode(dom, "/PcdEntry/ValidUsage")).split()
|
||||||
self.CName = XmlElementData(XmlElement(dom, "/PcdEntry/C_Name"))
|
self.CName = XmlElementData(XmlNode(dom, "/PcdEntry/C_Name"))
|
||||||
self.Token = XmlElementData(XmlElement(dom, "/PcdEntry/Token"))
|
self.Token = XmlElementData(XmlNode(dom, "/PcdEntry/Token"))
|
||||||
self.TokenSpace = XmlElementData(XmlElement(dom, "/PcdEntry/TokenSpaceGuidCName"))
|
self.TokenSpace = XmlElementData(XmlNode(dom, "/PcdEntry/TokenSpaceGuidCName"))
|
||||||
self.DatumType = XmlElementData(XmlElement(dom, "/PcdEntry/DatumType"))
|
self.DatumType = XmlElementData(XmlNode(dom, "/PcdEntry/DatumType"))
|
||||||
self.Default = XmlElementData(XmlElement(dom, "/PcdEntry/DefaultValue"))
|
self.Default = XmlElementData(XmlNode(dom, "/PcdEntry/DefaultValue"))
|
||||||
self.Archs = self.GetArchList(dom)
|
self.Archs = self.GetArchList(dom)
|
||||||
self.ModuleTypes= self.GetModuleTypeList(dom)
|
self.ModuleTypes= self.GetModuleTypeList(dom)
|
||||||
|
|
||||||
|
@ -566,10 +566,10 @@ class PlatformModule(FrameworkElement.PlatformModule, SurfaceAreaElement):
|
||||||
for lib in libraryList:
|
for lib in libraryList:
|
||||||
self.Libraries.append(LibraryInstance(self._Workspace, self, lib))
|
self.Libraries.append(LibraryInstance(self._Workspace, self, lib))
|
||||||
|
|
||||||
dom = XmlElement(dom, "/ModuleSA/ModuleSaBuildOptions")
|
dom = XmlNode(dom, "/ModuleSA/ModuleSaBuildOptions")
|
||||||
self.FvBindings = self.GetFvBindingList(XmlElement(dom, "/ModuleSaBuildOptions/FvBinding"))
|
self.FvBindings = self.GetFvBindingList(XmlNode(dom, "/ModuleSaBuildOptions/FvBinding"))
|
||||||
self.FfsLayouts = XmlElementData(XmlElement(dom, "/ModuleSaBuildOptions/FfsFormatKey")).split()
|
self.FfsLayouts = XmlElementData(XmlNode(dom, "/ModuleSaBuildOptions/FfsFormatKey")).split()
|
||||||
self.BuildOptions = self.GetBuildOptionList(XmlElement(dom, "/ModuleSaBuildOptions/Options"))
|
self.BuildOptions = self.GetBuildOptionList(XmlNode(dom, "/ModuleSaBuildOptions/Options"))
|
||||||
|
|
||||||
def Postprocess(self):
|
def Postprocess(self):
|
||||||
self.Module = self._Workspace.GetModule(self.GuidValue, self.Version,
|
self.Module = self._Workspace.GetModule(self.GuidValue, self.Version,
|
||||||
|
@ -602,22 +602,22 @@ class ModuleSurfaceArea(FrameworkElement.Module, SurfaceAreaElement):
|
||||||
SurfaceAreaElement.__init__(self, workspace, package)
|
SurfaceAreaElement.__init__(self, workspace, package)
|
||||||
|
|
||||||
def _MsaHeader(self, xpath):
|
def _MsaHeader(self, xpath):
|
||||||
dom = XmlElement(self._Root, xpath)
|
dom = XmlNode(self._Root, xpath)
|
||||||
if dom == '': return
|
if dom == '': return
|
||||||
self.Name = XmlElementData(XmlElement(dom, "/MsaHeader/ModuleName"))
|
self.Name = XmlElementData(XmlNode(dom, "/MsaHeader/ModuleName"))
|
||||||
self.Type = XmlElementData(XmlElement(dom, "/MsaHeader/ModuleType"))
|
self.Type = XmlElementData(XmlNode(dom, "/MsaHeader/ModuleType"))
|
||||||
self.GuidValue = XmlElementData(XmlElement(dom, "/MsaHeader/GuidValue")).upper()
|
self.GuidValue = XmlElementData(XmlNode(dom, "/MsaHeader/GuidValue")).upper()
|
||||||
self.Version = XmlElementData(XmlElement(dom, "/MsaHeader/Version"))
|
self.Version = XmlElementData(XmlNode(dom, "/MsaHeader/Version"))
|
||||||
|
|
||||||
def _ModuleDefinitions(self, xpath):
|
def _ModuleDefinitions(self, xpath):
|
||||||
dom = XmlElement(self._Root, xpath)
|
dom = XmlNode(self._Root, xpath)
|
||||||
if dom == '': return
|
if dom == '': return
|
||||||
self.Archs = XmlElementData(XmlElement(dom, "/ModuleDefinitions/SupportedArchitectures")).split()
|
self.Archs = XmlElementData(XmlNode(dom, "/ModuleDefinitions/SupportedArchitectures")).split()
|
||||||
self.IsBinary = self.GetBoolean(XmlElement(dom, "/ModuleDefinitions/BinaryModule"))
|
self.IsBinary = self.GetBoolean(XmlNode(dom, "/ModuleDefinitions/BinaryModule"))
|
||||||
self.BaseName = XmlElementData(XmlElement(dom, "/ModuleDefinitions/OutputFileBasename"))
|
self.BaseName = XmlElementData(XmlNode(dom, "/ModuleDefinitions/OutputFileBasename"))
|
||||||
|
|
||||||
def _LibraryClassDefinitions(self, xpath):
|
def _LibraryClassDefinitions(self, xpath):
|
||||||
dom = XmlElement(self._Root, xpath)
|
dom = XmlNode(self._Root, xpath)
|
||||||
if dom == '': return
|
if dom == '': return
|
||||||
lcList = []
|
lcList = []
|
||||||
for lc in XmlList(dom, "/LibraryClassDefinitions/LibraryClass"):
|
for lc in XmlList(dom, "/LibraryClassDefinitions/LibraryClass"):
|
||||||
|
@ -625,7 +625,7 @@ class ModuleSurfaceArea(FrameworkElement.Module, SurfaceAreaElement):
|
||||||
self._Elements["LibraryClassDefinitions"] = lcList
|
self._Elements["LibraryClassDefinitions"] = lcList
|
||||||
|
|
||||||
def _SourceFiles(self, xpath):
|
def _SourceFiles(self, xpath):
|
||||||
dom = XmlElement(self._Root, xpath)
|
dom = XmlNode(self._Root, xpath)
|
||||||
if dom == '': return
|
if dom == '': return
|
||||||
srcList = []
|
srcList = []
|
||||||
for f in XmlList(dom, "/SourceFiles/Filename"):
|
for f in XmlList(dom, "/SourceFiles/Filename"):
|
||||||
|
@ -633,13 +633,13 @@ class ModuleSurfaceArea(FrameworkElement.Module, SurfaceAreaElement):
|
||||||
self._Elements["SourceFiles"] = srcList
|
self._Elements["SourceFiles"] = srcList
|
||||||
|
|
||||||
def _NonProcessedFiles(self, xpath):
|
def _NonProcessedFiles(self, xpath):
|
||||||
dom = XmlElement(self._Root, xpath)
|
dom = XmlNode(self._Root, xpath)
|
||||||
if dom == '': return
|
if dom == '': return
|
||||||
for f in XmlList(dom, "/NonProcessedFiles/Filename"):
|
for f in XmlList(dom, "/NonProcessedFiles/Filename"):
|
||||||
self.NonProcessedFiles.append(SourceFile(self._Workspace, self, f))
|
self.NonProcessedFiles.append(SourceFile(self._Workspace, self, f))
|
||||||
|
|
||||||
def _PackageDependencies(self, xpath):
|
def _PackageDependencies(self, xpath):
|
||||||
dom = XmlElement(self._Root, xpath)
|
dom = XmlNode(self._Root, xpath)
|
||||||
if dom == '': return
|
if dom == '': return
|
||||||
pdList = []
|
pdList = []
|
||||||
for pkg in XmlList(dom, "/PackageDependencies/Package"):
|
for pkg in XmlList(dom, "/PackageDependencies/Package"):
|
||||||
|
@ -647,7 +647,7 @@ class ModuleSurfaceArea(FrameworkElement.Module, SurfaceAreaElement):
|
||||||
self._Elements["PackageDependencies"] = pdList
|
self._Elements["PackageDependencies"] = pdList
|
||||||
|
|
||||||
def _Protocols(self, xpath):
|
def _Protocols(self, xpath):
|
||||||
dom = XmlElement(self._Root, xpath)
|
dom = XmlNode(self._Root, xpath)
|
||||||
if dom == '': return
|
if dom == '': return
|
||||||
|
|
||||||
protocolList = []
|
protocolList = []
|
||||||
|
@ -659,7 +659,7 @@ class ModuleSurfaceArea(FrameworkElement.Module, SurfaceAreaElement):
|
||||||
self._Elements["Protocols"] = protocolList
|
self._Elements["Protocols"] = protocolList
|
||||||
|
|
||||||
def _Ppis(self, xpath):
|
def _Ppis(self, xpath):
|
||||||
dom = XmlElement(self._Root, xpath)
|
dom = XmlNode(self._Root, xpath)
|
||||||
if dom == '': return
|
if dom == '': return
|
||||||
|
|
||||||
ppiList = []
|
ppiList = []
|
||||||
|
@ -671,7 +671,7 @@ class ModuleSurfaceArea(FrameworkElement.Module, SurfaceAreaElement):
|
||||||
self._Elements["PPIs"] = ppiList
|
self._Elements["PPIs"] = ppiList
|
||||||
|
|
||||||
def _Guids(self, xpath):
|
def _Guids(self, xpath):
|
||||||
dom = XmlElement(self._Root, xpath)
|
dom = XmlNode(self._Root, xpath)
|
||||||
if dom == '': return
|
if dom == '': return
|
||||||
guidList = []
|
guidList = []
|
||||||
for g in XmlList(dom, "/Guids/GuidCNames"):
|
for g in XmlList(dom, "/Guids/GuidCNames"):
|
||||||
|
@ -679,10 +679,10 @@ class ModuleSurfaceArea(FrameworkElement.Module, SurfaceAreaElement):
|
||||||
self._Elements["Guids"] = guidList
|
self._Elements["Guids"] = guidList
|
||||||
|
|
||||||
def _Externs(self, xpath):
|
def _Externs(self, xpath):
|
||||||
dom = XmlElement(self._Root, xpath)
|
dom = XmlNode(self._Root, xpath)
|
||||||
if dom == '': return
|
if dom == '': return
|
||||||
self.PcdIsDriver = self.GetBoolean(XmlElement(dom, "/Externs/PcdIsDriver"))
|
self.PcdIsDriver = self.GetBoolean(XmlNode(dom, "/Externs/PcdIsDriver"))
|
||||||
self.NeedsFlashMap_h = self.GetBoolean(XmlElement(dom, "/Externs/TianoR8FlashMap_h"))
|
self.NeedsFlashMap_h = self.GetBoolean(XmlNode(dom, "/Externs/TianoR8FlashMap_h"))
|
||||||
|
|
||||||
externList = []
|
externList = []
|
||||||
specs = FrameworkElement.Extern()
|
specs = FrameworkElement.Extern()
|
||||||
|
@ -695,9 +695,9 @@ class ModuleSurfaceArea(FrameworkElement.Module, SurfaceAreaElement):
|
||||||
self._Elements["Externs"] = externList
|
self._Elements["Externs"] = externList
|
||||||
|
|
||||||
def _ModuleBuildOptions(self, xpath):
|
def _ModuleBuildOptions(self, xpath):
|
||||||
dom = XmlElement(self._Root, xpath)
|
dom = XmlNode(self._Root, xpath)
|
||||||
if dom == '': return
|
if dom == '': return
|
||||||
self.BuildOptions = self.GetBuildOptionList(XmlElement(dom, "/ModuleBuildOptions/Options"))
|
self.BuildOptions = self.GetBuildOptionList(XmlNode(dom, "/ModuleBuildOptions/Options"))
|
||||||
|
|
||||||
def _UserExtensions(self, xpath):
|
def _UserExtensions(self, xpath):
|
||||||
domList = XmlList(self._Root, xpath)
|
domList = XmlList(self._Root, xpath)
|
||||||
|
@ -837,14 +837,14 @@ class Workspace(FrameworkElement.Workspace, SurfaceAreaElement):
|
||||||
self.Postprocess()
|
self.Postprocess()
|
||||||
|
|
||||||
def _FdbHeader(self, xpath):
|
def _FdbHeader(self, xpath):
|
||||||
dom = XmlElement(self._Root, xpath)
|
dom = XmlNode(self._Root, xpath)
|
||||||
if dom == '': return
|
if dom == '': return
|
||||||
self.Name = XmlElementData(XmlElement(dom, "/FdbHeader/DatabaseName"))
|
self.Name = XmlElementData(XmlNode(dom, "/FdbHeader/DatabaseName"))
|
||||||
self.GuidValue = XmlElementData(XmlElement(dom, "/FdbHeader/GuidValue")).upper()
|
self.GuidValue = XmlElementData(XmlNode(dom, "/FdbHeader/GuidValue")).upper()
|
||||||
self.Version = XmlElementData(XmlElement(dom, "/FdbHeader/Version"))
|
self.Version = XmlElementData(XmlNode(dom, "/FdbHeader/Version"))
|
||||||
|
|
||||||
def _PackageList(self, xpath):
|
def _PackageList(self, xpath):
|
||||||
dom = XmlElement(self._Root, xpath)
|
dom = XmlNode(self._Root, xpath)
|
||||||
if dom == '': return
|
if dom == '': return
|
||||||
|
|
||||||
fileList = XmlList(dom, "/PackageList/Filename")
|
fileList = XmlList(dom, "/PackageList/Filename")
|
||||||
|
@ -857,7 +857,7 @@ class Workspace(FrameworkElement.Workspace, SurfaceAreaElement):
|
||||||
if len(self._Elements["PlatformList"]) > 0:
|
if len(self._Elements["PlatformList"]) > 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
dom = XmlElement(self._Root, xpath)
|
dom = XmlNode(self._Root, xpath)
|
||||||
if dom == '': return
|
if dom == '': return
|
||||||
|
|
||||||
fileList = XmlList(dom, "/PlatformList/Filename")
|
fileList = XmlList(dom, "/PlatformList/Filename")
|
||||||
|
@ -867,7 +867,7 @@ class Workspace(FrameworkElement.Workspace, SurfaceAreaElement):
|
||||||
self._Elements["PlatformList"] = platforms
|
self._Elements["PlatformList"] = platforms
|
||||||
|
|
||||||
def _FarList(self, xpath):
|
def _FarList(self, xpath):
|
||||||
dom = XmlElement(self._Root, xpath)
|
dom = XmlNode(self._Root, xpath)
|
||||||
if dom == '': return
|
if dom == '': return
|
||||||
|
|
||||||
fileList = XmlList(dom, "/FarList/Filename")
|
fileList = XmlList(dom, "/FarList/Filename")
|
||||||
|
@ -1199,18 +1199,18 @@ class PackageSurfaceArea(FrameworkElement.Package, SurfaceAreaElement):
|
||||||
SurfaceAreaElement.__init__(self, workspace, workspace, None, True, True)
|
SurfaceAreaElement.__init__(self, workspace, workspace, None, True, True)
|
||||||
|
|
||||||
def _SpdHeader(self, xpath):
|
def _SpdHeader(self, xpath):
|
||||||
dom = XmlElement(self._Root, xpath)
|
dom = XmlNode(self._Root, xpath)
|
||||||
self.Name = XmlElementData(XmlElement(dom, "/SpdHeader/PackageName"))
|
self.Name = XmlElementData(XmlNode(dom, "/SpdHeader/PackageName"))
|
||||||
self.GuidValue = XmlElementData(XmlElement(dom, "/SpdHeader/GuidValue")).upper()
|
self.GuidValue = XmlElementData(XmlNode(dom, "/SpdHeader/GuidValue")).upper()
|
||||||
self.Version = XmlElementData(XmlElement(dom, "/SpdHeader/Version"))
|
self.Version = XmlElementData(XmlNode(dom, "/SpdHeader/Version"))
|
||||||
|
|
||||||
def _PackageDefinitions(self, xpath):
|
def _PackageDefinitions(self, xpath):
|
||||||
dom = XmlElement(self._Root, xpath)
|
dom = XmlNode(self._Root, xpath)
|
||||||
self.ReadOnly = XmlElementData(XmlElement(dom, "/PackageDefinitions/ReadOnly"))
|
self.ReadOnly = XmlElementData(XmlNode(dom, "/PackageDefinitions/ReadOnly"))
|
||||||
self.Repackage = XmlElementData(XmlElement(dom, "/PackageDefinitions/RePackage"))
|
self.Repackage = XmlElementData(XmlNode(dom, "/PackageDefinitions/RePackage"))
|
||||||
|
|
||||||
def _LibraryClassDeclarations(self, xpath):
|
def _LibraryClassDeclarations(self, xpath):
|
||||||
dom = XmlElement(self._Root, xpath)
|
dom = XmlNode(self._Root, xpath)
|
||||||
lcdList = XmlList(dom, "/LibraryClassDeclarations/LibraryClass")
|
lcdList = XmlList(dom, "/LibraryClassDeclarations/LibraryClass")
|
||||||
lcds = []
|
lcds = []
|
||||||
for lc in lcdList:
|
for lc in lcdList:
|
||||||
|
@ -1218,7 +1218,7 @@ class PackageSurfaceArea(FrameworkElement.Package, SurfaceAreaElement):
|
||||||
self._Elements["LibraryClassDeclarations"] = lcds
|
self._Elements["LibraryClassDeclarations"] = lcds
|
||||||
|
|
||||||
def _IndustryStdIncludes(self, xpath):
|
def _IndustryStdIncludes(self, xpath):
|
||||||
dom = XmlElement(self._Root, xpath)
|
dom = XmlNode(self._Root, xpath)
|
||||||
headerList = XmlList(dom, "/IndustryStdIncludes/IndustryStdHeader")
|
headerList = XmlList(dom, "/IndustryStdIncludes/IndustryStdHeader")
|
||||||
headers = []
|
headers = []
|
||||||
for h in headerList:
|
for h in headerList:
|
||||||
|
@ -1226,7 +1226,7 @@ class PackageSurfaceArea(FrameworkElement.Package, SurfaceAreaElement):
|
||||||
self._Elements["IndustryStdIncludes"] = headers
|
self._Elements["IndustryStdIncludes"] = headers
|
||||||
|
|
||||||
def _MsaFiles(self, xpath):
|
def _MsaFiles(self, xpath):
|
||||||
dom = XmlElement(self._Root, xpath)
|
dom = XmlNode(self._Root, xpath)
|
||||||
msaFileList = XmlList(dom, "/MsaFiles/Filename")
|
msaFileList = XmlList(dom, "/MsaFiles/Filename")
|
||||||
msaFiles = []
|
msaFiles = []
|
||||||
for msa in msaFileList:
|
for msa in msaFileList:
|
||||||
|
@ -1235,7 +1235,7 @@ class PackageSurfaceArea(FrameworkElement.Package, SurfaceAreaElement):
|
||||||
self._Elements["MsaFiles"] = msaFiles
|
self._Elements["MsaFiles"] = msaFiles
|
||||||
|
|
||||||
def _PackageHeaders(self, xpath):
|
def _PackageHeaders(self, xpath):
|
||||||
dom = XmlElement(self._Root, xpath)
|
dom = XmlNode(self._Root, xpath)
|
||||||
headerList = XmlList(dom, "/PackageHeaders/IncludePkgHeader")
|
headerList = XmlList(dom, "/PackageHeaders/IncludePkgHeader")
|
||||||
headers = []
|
headers = []
|
||||||
for h in headerList:
|
for h in headerList:
|
||||||
|
@ -1243,7 +1243,7 @@ class PackageSurfaceArea(FrameworkElement.Package, SurfaceAreaElement):
|
||||||
self._Elements["PackageHeaders"] = headers
|
self._Elements["PackageHeaders"] = headers
|
||||||
|
|
||||||
def _GuidDeclarations(self, xpath):
|
def _GuidDeclarations(self, xpath):
|
||||||
dom = XmlElement(self._Root, xpath)
|
dom = XmlNode(self._Root, xpath)
|
||||||
guidList = XmlList(dom, "/GuidDeclarations/Entry")
|
guidList = XmlList(dom, "/GuidDeclarations/Entry")
|
||||||
guids = []
|
guids = []
|
||||||
for guid in guidList:
|
for guid in guidList:
|
||||||
|
@ -1251,7 +1251,7 @@ class PackageSurfaceArea(FrameworkElement.Package, SurfaceAreaElement):
|
||||||
self._Elements["GuidDeclarations"] = guids
|
self._Elements["GuidDeclarations"] = guids
|
||||||
|
|
||||||
def _ProtocolDeclarations(self, xpath):
|
def _ProtocolDeclarations(self, xpath):
|
||||||
dom = XmlElement(self._Root, xpath)
|
dom = XmlNode(self._Root, xpath)
|
||||||
protocolList = XmlList(dom, "/ProtocolDeclarations/Entry")
|
protocolList = XmlList(dom, "/ProtocolDeclarations/Entry")
|
||||||
protocols = []
|
protocols = []
|
||||||
for p in protocolList:
|
for p in protocolList:
|
||||||
|
@ -1259,7 +1259,7 @@ class PackageSurfaceArea(FrameworkElement.Package, SurfaceAreaElement):
|
||||||
self._Elements["ProtocolDeclarations"] = protocols
|
self._Elements["ProtocolDeclarations"] = protocols
|
||||||
|
|
||||||
def _PpiDeclarations(self, xpath):
|
def _PpiDeclarations(self, xpath):
|
||||||
dom = XmlElement(self._Root, xpath)
|
dom = XmlNode(self._Root, xpath)
|
||||||
ppiList = XmlList(dom, "/PpiDeclarations/Entry")
|
ppiList = XmlList(dom, "/PpiDeclarations/Entry")
|
||||||
ppis = []
|
ppis = []
|
||||||
for p in ppiList:
|
for p in ppiList:
|
||||||
|
@ -1267,7 +1267,7 @@ class PackageSurfaceArea(FrameworkElement.Package, SurfaceAreaElement):
|
||||||
self._Elements["PpiDeclarations"] = ppis
|
self._Elements["PpiDeclarations"] = ppis
|
||||||
|
|
||||||
def _PcdDeclarations(self, xpath):
|
def _PcdDeclarations(self, xpath):
|
||||||
dom = XmlElement(self._Root, xpath)
|
dom = XmlNode(self._Root, xpath)
|
||||||
pcdList = XmlList(dom, "/PcdDeclarations/PcdEntry")
|
pcdList = XmlList(dom, "/PcdDeclarations/PcdEntry")
|
||||||
pcds = []
|
pcds = []
|
||||||
for p in pcdList:
|
for p in pcdList:
|
||||||
|
@ -1339,27 +1339,27 @@ class PlatformSurfaceArea(FrameworkElement.Platform, SurfaceAreaElement):
|
||||||
SurfaceAreaElement.__init__(self, workspace)
|
SurfaceAreaElement.__init__(self, workspace)
|
||||||
|
|
||||||
def _PlatformHeader(self, xpath):
|
def _PlatformHeader(self, xpath):
|
||||||
dom = XmlElement(self._Root, xpath)
|
dom = XmlNode(self._Root, xpath)
|
||||||
if dom == '': return
|
if dom == '': return
|
||||||
self.Name = XmlElementData(XmlElement(dom, "/PlatformHeader/PlatformName"))
|
self.Name = XmlElementData(XmlNode(dom, "/PlatformHeader/PlatformName"))
|
||||||
self.GuidValue = XmlElementData(XmlElement(dom, "/PlatformHeader/GuidValue")).upper()
|
self.GuidValue = XmlElementData(XmlNode(dom, "/PlatformHeader/GuidValue")).upper()
|
||||||
self.Version = XmlElementData(XmlElement(dom, "/PlatformHeader/Version"))
|
self.Version = XmlElementData(XmlNode(dom, "/PlatformHeader/Version"))
|
||||||
|
|
||||||
def _PlatformDefinitions(self, xpath):
|
def _PlatformDefinitions(self, xpath):
|
||||||
dom = XmlElement(self._Root, xpath)
|
dom = XmlNode(self._Root, xpath)
|
||||||
if dom == '': return
|
if dom == '': return
|
||||||
self.Archs = XmlElementData(XmlElement(dom, "/PlatformDefinitions/SupportedArchitectures")).split()
|
self.Archs = XmlElementData(XmlNode(dom, "/PlatformDefinitions/SupportedArchitectures")).split()
|
||||||
if self.Archs == []:
|
if self.Archs == []:
|
||||||
raise Exception("No ARCH specified in platform " + self.Path)
|
raise Exception("No ARCH specified in platform " + self.Path)
|
||||||
self.Targets = XmlElementData(XmlElement(dom, "/PlatformDefinitions/BuildTargets")).split()
|
self.Targets = XmlElementData(XmlNode(dom, "/PlatformDefinitions/BuildTargets")).split()
|
||||||
self.OutputPath = os.path.normpath(XmlElementData(XmlElement(dom, "/PlatformDefinitions/OutputDirectory")))
|
self.OutputPath = os.path.normpath(XmlElementData(XmlNode(dom, "/PlatformDefinitions/OutputDirectory")))
|
||||||
|
|
||||||
def _Flash(self, xpath):
|
def _Flash(self, xpath):
|
||||||
dom = XmlElement(self._Root, xpath)
|
dom = XmlNode(self._Root, xpath)
|
||||||
if dom == '': return
|
if dom == '': return
|
||||||
|
|
||||||
def _FrameworkModules(self, xpath):
|
def _FrameworkModules(self, xpath):
|
||||||
dom = XmlElement(self._Root, xpath)
|
dom = XmlNode(self._Root, xpath)
|
||||||
if dom == '': return
|
if dom == '': return
|
||||||
moduleList = XmlList(dom, "/FrameworkModules/ModuleSA")
|
moduleList = XmlList(dom, "/FrameworkModules/ModuleSA")
|
||||||
modules = []
|
modules = []
|
||||||
|
@ -1368,13 +1368,13 @@ class PlatformSurfaceArea(FrameworkElement.Platform, SurfaceAreaElement):
|
||||||
self._Elements["FrameworkModules"] = modules
|
self._Elements["FrameworkModules"] = modules
|
||||||
|
|
||||||
def _DynamicPcdBuildDefinitions(self, xpath):
|
def _DynamicPcdBuildDefinitions(self, xpath):
|
||||||
dom = XmlElement(self._Root, xpath)
|
dom = XmlNode(self._Root, xpath)
|
||||||
if dom == '': return
|
if dom == '': return
|
||||||
|
|
||||||
def _BuildOptions(self, xpath):
|
def _BuildOptions(self, xpath):
|
||||||
dom = XmlElement(self._Root, xpath)
|
dom = XmlNode(self._Root, xpath)
|
||||||
if dom == '': return
|
if dom == '': return
|
||||||
self.BuildOptions = self.GetBuildOptionList(XmlElement(dom, "/BuildOptions/Options"))
|
self.BuildOptions = self.GetBuildOptionList(XmlNode(dom, "/BuildOptions/Options"))
|
||||||
# print self.BuildOptions
|
# print self.BuildOptions
|
||||||
|
|
||||||
def _UserExtensions(self, xpath):
|
def _UserExtensions(self, xpath):
|
||||||
|
@ -1519,6 +1519,7 @@ def PrintWorkspace(ws):
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# os.environ["WORKSPACE"]
|
# os.environ["WORKSPACE"]
|
||||||
workspacePath = os.getenv("WORKSPACE", os.getcwd())
|
workspacePath = os.getenv("WORKSPACE", os.getcwd())
|
||||||
|
workspacePath = "C:\\home\\src\\R9\\pbuild"
|
||||||
saFile = ""
|
saFile = ""
|
||||||
if len(sys.argv) <= 1:
|
if len(sys.argv) <= 1:
|
||||||
saFile = os.path.join(workspacePath, "Tools/Conf/FrameworkDatabase.db")
|
saFile = os.path.join(workspacePath, "Tools/Conf/FrameworkDatabase.db")
|
||||||
|
@ -1529,16 +1530,6 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
startTime = time.clock()
|
startTime = time.clock()
|
||||||
sa = Workspace(workspacePath, [], [])
|
sa = Workspace(workspacePath, [], [])
|
||||||
## dbak = None
|
|
||||||
## if os.path.exists("workspace.bak"):
|
|
||||||
## dbak = shelve.open("workspace.bak", protocol=2)
|
|
||||||
## sa = dbak.db
|
|
||||||
## dbak.close()
|
|
||||||
## else:
|
|
||||||
## sa = FrameworkDatabase(saFile)
|
|
||||||
## dbak = shelve.open("workspace.bak", protocol=2)
|
|
||||||
## dbak.db = sa
|
|
||||||
## dbak.close()
|
|
||||||
# sa = PackageSurfaceArea(saFile)
|
# sa = PackageSurfaceArea(saFile)
|
||||||
# sa = PlatformSurfaceArea(saFile)
|
# sa = PlatformSurfaceArea(saFile)
|
||||||
# sa = ModuleSurfaceArea(saFile)
|
# sa = ModuleSurfaceArea(saFile)
|
||||||
|
|
|
@ -1,104 +0,0 @@
|
||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
# Copyright (c) 2007, Intel Corporation
|
|
||||||
# All rights reserved. This program and the accompanying materials
|
|
||||||
# are licensed and made available under the terms and conditions of the BSD License
|
|
||||||
# which accompanies this distribution. The full text of the license may be found at
|
|
||||||
# http://opensource.org/licenses/bsd-license.php
|
|
||||||
#
|
|
||||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
||||||
|
|
||||||
"""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 String == "" or Dom == None or not isinstance(Dom, xml.dom.Node):
|
|
||||||
return []
|
|
||||||
|
|
||||||
if String[0] == "/":
|
|
||||||
String = String[1:]
|
|
||||||
|
|
||||||
if Dom.nodeType==Dom.DOCUMENT_NODE:
|
|
||||||
Dom = Dom.documentElement
|
|
||||||
|
|
||||||
tagList = String.split('/')
|
|
||||||
nodes = [Dom]
|
|
||||||
childNodes = []
|
|
||||||
index = 0
|
|
||||||
end = len(tagList) - 1
|
|
||||||
while index <= end:
|
|
||||||
for node in nodes:
|
|
||||||
if node.nodeType == node.ELEMENT_NODE and node.tagName == tagList[index]:
|
|
||||||
if index < end:
|
|
||||||
childNodes.extend(node.childNodes)
|
|
||||||
else:
|
|
||||||
childNodes.append(node)
|
|
||||||
|
|
||||||
nodes = childNodes
|
|
||||||
childNodes = []
|
|
||||||
index += 1
|
|
||||||
|
|
||||||
return nodes
|
|
||||||
|
|
||||||
def XmlElement (Dom, String):
|
|
||||||
"""Return a single element that matches the String which is XPath style syntax."""
|
|
||||||
if String == "" or Dom == None or not isinstance(Dom, xml.dom.Node):
|
|
||||||
return ""
|
|
||||||
|
|
||||||
if String[0] == "/":
|
|
||||||
String = String[1:]
|
|
||||||
|
|
||||||
if Dom.nodeType==Dom.DOCUMENT_NODE:
|
|
||||||
Dom = Dom.documentElement
|
|
||||||
|
|
||||||
tagList = String.split('/')
|
|
||||||
childNodes = [Dom]
|
|
||||||
index = 0
|
|
||||||
end = len(tagList) - 1
|
|
||||||
while index <= end:
|
|
||||||
for node in childNodes:
|
|
||||||
if node.nodeType == node.ELEMENT_NODE and node.tagName == tagList[index]:
|
|
||||||
if index < end:
|
|
||||||
childNodes = node.childNodes
|
|
||||||
else:
|
|
||||||
return node
|
|
||||||
break
|
|
||||||
|
|
||||||
index += 1
|
|
||||||
|
|
||||||
return ""
|
|
||||||
|
|
||||||
def XmlElementData (Dom):
|
|
||||||
"""Get the text for this element."""
|
|
||||||
if Dom == None or Dom == '' or Dom.firstChild == None:
|
|
||||||
return ''
|
|
||||||
|
|
||||||
return Dom.firstChild.data.strip(' ')
|
|
||||||
|
|
||||||
def XmlAttribute (Dom, String):
|
|
||||||
"""Return a single attribute that named by String."""
|
|
||||||
if Dom == None or Dom == '':
|
|
||||||
return ''
|
|
||||||
|
|
||||||
try:
|
|
||||||
return Dom.getAttribute(String).strip(' ')
|
|
||||||
except:
|
|
||||||
return ''
|
|
||||||
|
|
||||||
def XmlTopTag(Dom):
|
|
||||||
"""Return the name of the Root or top tag in the XML tree."""
|
|
||||||
if Dom == None or Dom == '' or Dom.firstChild == None:
|
|
||||||
return ''
|
|
||||||
return Dom.firstChild.nodeName
|
|
||||||
|
|
||||||
|
|
||||||
# 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
|
|
Loading…
Reference in New Issue