2 # This file is used to parse a Package file of .PKG file
4 # Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
6 # This program and the accompanying materials are licensed and made available
7 # under the terms and conditions of the BSD License which accompanies this
8 # distribution. The full text of the license may be found at
9 # http://opensource.org/licenses/bsd-license.php
11 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 from xml
.dom
import minidom
20 from Library
.String
import GetStringOfList
21 from Library
.Xml
.XmlRoutines
import XmlElement
22 from Library
.Xml
.XmlRoutines
import XmlNode
23 from Library
.Xml
.XmlRoutines
import XmlList
24 from Library
.Xml
.XmlRoutines
import CreateXmlElement
25 from Object
.POM
.CommonObject
import IncludeObject
26 from Object
.POM
.CommonObject
import TextObject
27 from Object
.POM
.PackageObject
import PackageObject
28 from Xml
.CommonXml
import ClonedFromXml
29 from Xml
.CommonXml
import PackageHeaderXml
30 from Xml
.CommonXml
import HelpTextXml
31 from Xml
.CommonXml
import CommonDefinesXml
32 from Xml
.CommonXml
import LibraryClassXml
33 from Xml
.CommonXml
import UserExtensionsXml
34 from Xml
.CommonXml
import MiscellaneousFileXml
35 from Xml
.GuidProtocolPpiXml
import GuidXml
36 from Xml
.GuidProtocolPpiXml
import ProtocolXml
37 from Xml
.GuidProtocolPpiXml
import PpiXml
38 from Xml
.ModuleSurfaceAreaXml
import ModuleSurfaceAreaXml
39 from Xml
.PcdXml
import PcdEntryXml
42 # IndustryStandardHeaderXml
44 class IndustryStandardHeaderXml(object):
49 def FromXml(self
, Item
, Key
):
50 self
.HeaderFile
= XmlElement(Item
, '%s/HeaderFile' % Key
)
51 for HelpTextItem
in XmlList(Item
, '%s/HelpText' % Key
):
52 HelpTextObj
= HelpTextXml()
53 HelpTextObj
.FromXml(HelpTextItem
, '%s/HelpText' % Key
)
54 self
.HelpText
.append(HelpTextObj
)
56 Include
= IncludeObject()
57 Include
.SetFilePath(self
.HeaderFile
)
58 HelpTxt
= TextObject()
59 HelpTxt
.SetString(self
.HelpText
)
60 Include
.SetHelpText(HelpTxt
)
64 def ToXml(self
, IndustryStandardHeader
, Key
):
68 NodeList
= [['HeaderFile', IndustryStandardHeader
.GetFilePath()]]
69 Root
= CreateXmlElement('%s' % Key
, '', NodeList
, AttributeList
)
74 Str
= "HeaderFile = %s" % (self
.HeaderFile
)
75 for Item
in self
.HelpText
:
76 Str
= Str
+ "\n\t" + str(Item
)
79 # PackageIncludeHeaderXml
81 class PackageIncludeHeaderXml(object):
84 self
.CommonDefines
= CommonDefinesXml()
87 def FromXml(self
, Item
, Key
):
88 self
.HeaderFile
= XmlElement(Item
, '%s/HeaderFile' % Key
)
89 self
.CommonDefines
.FromXml(XmlNode(Item
, '%s/HeaderFile' % Key
), 'HeaderFile')
90 for HelpTextItem
in XmlList(Item
, '%s/HelpText' % Key
):
91 HelpTextObj
= HelpTextXml()
92 HelpTextObj
.FromXml(HelpTextItem
, '%s/HelpText' % Key
)
93 self
.HelpText
.append(HelpTextObj
)
95 Include
= IncludeObject()
96 Include
.SetFilePath(self
.HeaderFile
)
97 Include
.SetSupArchList(self
.CommonDefines
.SupArchList
)
98 HelpTxt
= TextObject()
99 HelpTxt
.SetString(self
.HelpText
)
100 Include
.SetHelpText(HelpTxt
)
104 def ToXml(self
, PackageIncludeHeader
, Key
):
107 AttributeList
= [['SupArchList', GetStringOfList(PackageIncludeHeader
.GetSupArchList())], \
108 ['SupModList', GetStringOfList(PackageIncludeHeader
.GetSupModuleList())], ]
110 HeaderFileNode
= CreateXmlElement('HeaderFile', PackageIncludeHeader
.FilePath
, [], AttributeList
)
112 NodeList
= [HeaderFileNode
]
113 for Item
in PackageIncludeHeader
.GetHelpTextList():
115 NodeList
.append(Tmp
.ToXml(Item
))
117 Root
= CreateXmlElement('%s' % Key
, '', NodeList
, [])
122 Str
= "HeaderFile = %s\n\t%s" % (self
.HeaderFile
, self
.CommonDefines
)
123 for Item
in self
.HelpText
:
124 Str
= Str
+ "\n\t" + str(Item
)
130 class PcdCheckXml(object):
134 def FromXml(self
, Item
, Key
):
137 self
.PcdCheck
= XmlElement(Item
, 'PcdCheck')
141 def ToXml(self
, PcdCheck
, Key
):
144 Root
= CreateXmlElement('%s' % Key
, PcdCheck
, [], [])
148 return "PcdCheck = %s" % (self
.PcdCheck
)
151 # PackageSurfaceAreaXml
153 class PackageSurfaceAreaXml(object):
157 def FromXml(self
, Item
, Key
):
161 # Create a package object
163 Package
= PackageObject()
167 Tmp
= PackageHeaderXml()
168 Tmp
.FromXml(XmlNode(Item
, '/PackageSurfaceArea/Header'), 'Header', Package
)
172 Tmp
= ClonedFromXml()
173 if XmlNode(Item
, '/PackageSurfaceArea/ClonedFrom'):
174 ClonedFrom
= Tmp
.FromXml(XmlNode(Item
, '/PackageSurfaceArea/ClonedFrom'), 'ClonedFrom')
175 Package
.SetClonedFromList([ClonedFrom
])
180 for SubItem
in XmlList(Item
, '/PackageSurfaceArea/LibraryClassDeclarations/LibraryClass'):
181 Tmp
= LibraryClassXml()
182 LibraryClass
= Tmp
.FromXml(SubItem
, 'LibraryClass')
183 Package
.SetLibraryClassList(Package
.GetLibraryClassList() + [LibraryClass
])
185 if XmlList(Item
, '/PackageSurfaceArea/LibraryClassDeclarations') and \
186 not XmlList(Item
, '/PackageSurfaceArea/LibraryClassDeclarations/LibraryClass'):
187 Package
.SetLibraryClassList([None])
190 # IndustryStandardHeader
192 for SubItem
in XmlList(Item
, '/PackageSurfaceArea/IndustryStandardIncludes/IndustryStandardHeader'):
193 Tmp
= IndustryStandardHeaderXml()
194 Include
= Tmp
.FromXml(SubItem
, 'IndustryStandardHeader')
195 Package
.SetStandardIncludeFileList(Package
.GetStandardIncludeFileList() + [Include
])
197 if XmlList(Item
, '/PackageSurfaceArea/IndustryStandardIncludes') and \
198 not XmlList(Item
, '/PackageSurfaceArea/IndustryStandardIncludes/IndustryStandardHeader'):
199 Package
.SetStandardIncludeFileList([None])
205 for SubItem
in XmlList(Item
, '/PackageSurfaceArea/PackageIncludes/PackageHeader'):
206 Tmp
= PackageIncludeHeaderXml()
207 Include
= Tmp
.FromXml(SubItem
, 'PackageHeader')
208 Package
.SetPackageIncludeFileList(Package
.GetPackageIncludeFileList() + [Include
])
210 if XmlList(Item
, '/PackageSurfaceArea/PackageIncludes') and not \
211 XmlList(Item
, '/PackageSurfaceArea/PackageIncludes/PackageHeader'):
212 Package
.SetPackageIncludeFileList([None])
217 for SubItem
in XmlList(Item
, '/PackageSurfaceArea/GuidDeclarations/Entry'):
218 Tmp
= GuidXml('Package')
219 GuidProtocolPpi
= Tmp
.FromXml(SubItem
, 'Entry')
220 Package
.SetGuidList(Package
.GetGuidList() + [GuidProtocolPpi
])
222 if XmlList(Item
, '/PackageSurfaceArea/GuidDeclarations') and not \
223 XmlList(Item
, '/PackageSurfaceArea/GuidDeclarations/Entry'):
224 Package
.SetGuidList([None])
229 for SubItem
in XmlList(Item
, '/PackageSurfaceArea/ProtocolDeclarations/Entry'):
230 Tmp
= ProtocolXml('Package')
231 GuidProtocolPpi
= Tmp
.FromXml(SubItem
, 'Entry')
232 Package
.SetProtocolList(Package
.GetProtocolList() + [GuidProtocolPpi
])
234 if XmlList(Item
, '/PackageSurfaceArea/ProtocolDeclarations') and not \
235 XmlList(Item
, '/PackageSurfaceArea/ProtocolDeclarations/Entry'):
236 Package
.SetProtocolList([None])
241 for SubItem
in XmlList(Item
, '/PackageSurfaceArea/PpiDeclarations/Entry'):
242 Tmp
= PpiXml('Package')
243 GuidProtocolPpi
= Tmp
.FromXml(SubItem
, 'Entry')
244 Package
.SetPpiList(Package
.GetPpiList() + [GuidProtocolPpi
])
246 if XmlList(Item
, '/PackageSurfaceArea/PpiDeclarations') and not \
247 XmlList(Item
, '/PackageSurfaceArea/PpiDeclarations/Entry'):
248 Package
.SetPpiList([None])
253 for SubItem
in XmlList(Item
, '/PackageSurfaceArea/PcdDeclarations/PcdEntry'):
255 PcdEntry
= Tmp
.FromXml2(SubItem
, 'PcdEntry')
256 Package
.SetPcdList(Package
.GetPcdList() + [PcdEntry
])
258 if XmlList(Item
, '/PackageSurfaceArea/PcdDeclarations') and not \
259 XmlList(Item
, '/PackageSurfaceArea/PcdDeclarations/PcdEntry'):
260 Package
.SetPcdList([None])
265 for SubItem
in XmlList(Item
, '/PackageSurfaceArea/PcdRelationshipChecks/PcdCheck'):
267 PcdCheck
= Tmp
.FromXml(SubItem
, 'PcdCheck')
268 Package
.PcdChecks
.append(PcdCheck
)
273 for SubItem
in XmlList(Item
, '/PackageSurfaceArea/Modules/ModuleSurfaceArea'):
274 Tmp
= ModuleSurfaceAreaXml()
275 Module
= Tmp
.FromXml(SubItem
, 'ModuleSurfaceArea')
276 Package
.ModuleDict
[(Module
.GetGuid(), Module
.GetVersion(), Module
.GetModulePath())] = Module
280 Tmp
= MiscellaneousFileXml()
281 MiscFileList
= Tmp
.FromXml(XmlNode(Item
, '/PackageSurfaceArea/MiscellaneousFiles'), 'MiscellaneousFiles')
283 Package
.SetMiscFileList([MiscFileList
])
285 Package
.SetMiscFileList([])
290 for Item
in XmlList(Item
, '/PackageSurfaceArea/UserExtensions'):
291 Tmp
= UserExtensionsXml()
292 UserExtension
= Tmp
.FromXml(Item
, 'UserExtensions')
293 Package
.UserExtensionList
.append(UserExtension
)
295 self
.Package
= Package
298 def ToXml(self
, Package
):
302 # Create PackageSurfaceArea node
304 DomPackage
= minidom
.Document().createElement('PackageSurfaceArea')
308 Tmp
= PackageHeaderXml()
309 DomPackage
.appendChild(Tmp
.ToXml(Package
, 'Header'))
313 Tmp
= ClonedFromXml()
314 if Package
.GetClonedFromList() != []:
315 DomPackage
.appendChild(Tmp
.ToXml(Package
.GetClonedFromList
[0], 'ClonedFrom'))
319 LibraryClassNode
= CreateXmlElement('LibraryClassDeclarations', '', [], [])
320 for LibraryClass
in Package
.GetLibraryClassList():
321 Tmp
= LibraryClassXml()
322 LibraryClassNode
.appendChild(Tmp
.ToXml(LibraryClass
, 'LibraryClass'))
323 DomPackage
.appendChild(LibraryClassNode
)
325 # IndustryStandardHeader
327 IndustryStandardHeaderNode
= CreateXmlElement('IndustryStandardIncludes', '', [], [])
328 for Include
in Package
.GetStandardIncludeFileList():
329 Tmp
= IndustryStandardHeaderXml()
330 IndustryStandardHeaderNode
.appendChild(Tmp
.ToXml(Include
, 'IndustryStandardHeader'))
331 DomPackage
.appendChild(IndustryStandardHeaderNode
)
335 PackageIncludeHeaderNode
= CreateXmlElement('PackageIncludes', '', [], [])
336 for Include
in Package
.GetPackageIncludeFileList():
337 Tmp
= PackageIncludeHeaderXml()
338 PackageIncludeHeaderNode
.appendChild(Tmp
.ToXml(Include
, 'PackageHeader'))
339 DomPackage
.appendChild(PackageIncludeHeaderNode
)
340 ModuleNode
= CreateXmlElement('Modules', '', [], [])
341 for Module
in Package
.GetModuleDict().values():
342 Tmp
= ModuleSurfaceAreaXml()
343 ModuleNode
.appendChild(Tmp
.ToXml(Module
))
344 DomPackage
.appendChild(ModuleNode
)
348 GuidProtocolPpiNode
= CreateXmlElement('GuidDeclarations', '', [], [])
349 for GuidProtocolPpi
in Package
.GetGuidList():
350 Tmp
= GuidXml('Package')
351 GuidProtocolPpiNode
.appendChild(Tmp
.ToXml\
352 (GuidProtocolPpi
, 'Entry'))
353 DomPackage
.appendChild(GuidProtocolPpiNode
)
357 GuidProtocolPpiNode
= \
358 CreateXmlElement('ProtocolDeclarations', '', [], [])
359 for GuidProtocolPpi
in Package
.GetProtocolList():
360 Tmp
= ProtocolXml('Package')
361 GuidProtocolPpiNode
.appendChild\
362 (Tmp
.ToXml(GuidProtocolPpi
, 'Entry'))
363 DomPackage
.appendChild(GuidProtocolPpiNode
)
367 GuidProtocolPpiNode
= CreateXmlElement('PpiDeclarations', '', [], [])
368 for GuidProtocolPpi
in Package
.GetPpiList():
369 Tmp
= PpiXml('Package')
370 GuidProtocolPpiNode
.appendChild\
371 (Tmp
.ToXml(GuidProtocolPpi
, 'Entry'))
372 DomPackage
.appendChild(GuidProtocolPpiNode
)
376 PcdEntryNode
= CreateXmlElement('PcdDeclarations', '', [], [])
377 for PcdEntry
in Package
.GetPcdList():
379 PcdEntryNode
.appendChild(Tmp
.ToXml2(PcdEntry
, 'PcdEntry'))
380 DomPackage
.appendChild(PcdEntryNode
)
385 Tmp
= MiscellaneousFileXml()
386 if Package
.GetMiscFileList():
387 DomPackage
.appendChild(Tmp
.ToXml(Package
.GetMiscFileList()[0], 'MiscellaneousFiles'))
392 if Package
.GetUserExtensionList():
393 for UserExtension
in Package
.GetUserExtensionList():
394 Tmp
= UserExtensionsXml()
395 DomPackage
.appendChild(Tmp
.ToXml(UserExtension
, 'UserExtensions'))