def ToXml(self, DistP): if self.DistP: pass if DistP is not None: # # Parse DistributionPackageHeader # Attrs = [ ['xmlns', 'http://www.uefi.org/2011/1.1'], ['xmlns:xsi', 'http:/www.w3.org/2001/XMLSchema-instance'], ] Root = CreateXmlElement('DistributionPackage', '', [], Attrs) Tmp = DistributionPackageHeaderXml() Root.appendChild(Tmp.ToXml(DistP.Header, 'DistributionHeader')) # # Parse each PackageSurfaceArea # for Package in DistP.PackageSurfaceArea.values(): Psa = PackageSurfaceAreaXml() DomPackage = Psa.ToXml(Package) Root.appendChild(DomPackage) # # Parse each ModuleSurfaceArea # for Module in DistP.ModuleSurfaceArea.values(): Msa = ModuleSurfaceAreaXml() DomModule = Msa.ToXml(Module) Root.appendChild(DomModule) # # Parse Tools # Tmp = MiscellaneousFileXml() ToolNode = Tmp.ToXml2(DistP.Tools, 'Tools') if ToolNode is not None: Root.appendChild(ToolNode) # # Parse MiscFiles # Tmp = MiscellaneousFileXml() MiscFileNode = Tmp.ToXml2(DistP.MiscellaneousFiles, 'MiscellaneousFiles') if MiscFileNode is not None: Root.appendChild(MiscFileNode) XmlContent = Root.toprettyxml(indent=' ') # # Remove empty element # XmlContent = re.sub(r'[\s\r\n]*<[^<>=]*/>', '', XmlContent) # # Remove empty help text element # XmlContent = re.sub(r'[\s\r\n]*<HelpText Lang="en-US"/>', '', XmlContent) # # Remove SupArchList="COMMON" or "common" # XmlContent = \ re.sub(r'[\s\r\n]*SupArchList[\s\r\n]*=[\s\r\n]*"[\s\r\n]*COMMON' '[\s\r\n]*"', '', XmlContent) XmlContent = \ re.sub(r'[\s\r\n]*SupArchList[\s\r\n]*=[\s\r\n]*"[\s\r\n]*common' '[\s\r\n]*"', '', XmlContent) # # Remove <SupArchList> COMMON </SupArchList> # XmlContent = \ re.sub(r'[\s\r\n]*<SupArchList>[\s\r\n]*COMMON[\s\r\n]*' '</SupArchList>[\s\r\n]*', '', XmlContent) # # Remove <SupArchList> common </SupArchList> # XmlContent = \ re.sub(r'[\s\r\n]*<SupArchList>[\s\r\n]*' 'common[\s\r\n]*</SupArchList>[\s\r\n]*', '', XmlContent) # # Remove SupModList="COMMON" or "common" # XmlContent = \ re.sub(r'[\s\r\n]*SupModList[\s\r\n]*=[\s\r\n]*"[\s\r\n]*COMMON' '[\s\r\n]*"', '', XmlContent) XmlContent = \ re.sub(r'[\s\r\n]*SupModList[\s\r\n]*=[\s\r\n]*"[\s\r\n]*common' '[\s\r\n]*"', '', XmlContent) return XmlContent return ''
def FromXml(self, Filename=None): if Filename is not None: self.DistP = DistributionPackageClass() # # Load to XML # self.Pkg = XmlParseFile(Filename) # # Parse Header information # Tmp = DistributionPackageHeaderXml() DistributionPackageHeader = \ Tmp.FromXml(XmlNode(self.Pkg, '/DistributionPackage/DistributionHeader'), 'DistributionHeader') self.DistP.Header = DistributionPackageHeader # # Parse each PackageSurfaceArea # for Item in XmlList(self.Pkg, '/DistributionPackage/PackageSurfaceArea'): Psa = PackageSurfaceAreaXml() Package = Psa.FromXml(Item, 'PackageSurfaceArea') self.DistP.PackageSurfaceArea[(Package.GetGuid(), \ Package.GetVersion(), \ Package.GetPackagePath())] = \ Package # # Parse each ModuleSurfaceArea # for Item in XmlList(self.Pkg, '/DistributionPackage/ModuleSurfaceArea'): Msa = ModuleSurfaceAreaXml() Module = Msa.FromXml(Item, 'ModuleSurfaceArea', True) ModuleKey = (Module.GetGuid(), Module.GetVersion(), Module.GetName(), Module.GetModulePath()) self.DistP.ModuleSurfaceArea[ModuleKey] = Module # # Parse Tools # Tmp = MiscellaneousFileXml() self.DistP.Tools = Tmp.FromXml2( XmlNode(self.Pkg, '/DistributionPackage/Tools'), 'Tools') # # Parse MiscFiles # Tmp = MiscellaneousFileXml() self.DistP.MiscellaneousFiles = \ Tmp.FromXml2(XmlNode(self.Pkg, \ '/DistributionPackage/MiscellaneousFiles'), \ 'MiscellaneousFiles') # # Parse UserExtensions # for Item in XmlList(self.Pkg, '/DistributionPackage/UserExtensions'): Tmp = UserExtensionsXml() self.DistP.UserExtensions.append( Tmp.FromXml2(Item, 'UserExtensions')) # # Check Required Items for XML # self.ValidateDistributionPackage() return self.DistP