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 ModuleDictKey
= (Module
.GetGuid(), Module
.GetVersion(), Module
.GetName(), Module
.GetModulePath())
277 Package
.ModuleDict
[ModuleDictKey
] = Module
281 Tmp
= MiscellaneousFileXml()
282 MiscFileList
= Tmp
.FromXml(XmlNode(Item
, '/PackageSurfaceArea/MiscellaneousFiles'), 'MiscellaneousFiles')
284 Package
.SetMiscFileList([MiscFileList
])
286 Package
.SetMiscFileList([])
291 for Item
in XmlList(Item
, '/PackageSurfaceArea/UserExtensions'):
292 Tmp
= UserExtensionsXml()
293 UserExtension
= Tmp
.FromXml(Item
, 'UserExtensions')
294 Package
.UserExtensionList
.append(UserExtension
)
296 self
.Package
= Package
299 def ToXml(self
, Package
):
303 # Create PackageSurfaceArea node
305 DomPackage
= minidom
.Document().createElement('PackageSurfaceArea')
309 Tmp
= PackageHeaderXml()
310 DomPackage
.appendChild(Tmp
.ToXml(Package
, 'Header'))
314 Tmp
= ClonedFromXml()
315 if Package
.GetClonedFromList() != []:
316 DomPackage
.appendChild(Tmp
.ToXml(Package
.GetClonedFromList
[0], 'ClonedFrom'))
320 LibraryClassNode
= CreateXmlElement('LibraryClassDeclarations', '', [], [])
321 for LibraryClass
in Package
.GetLibraryClassList():
322 Tmp
= LibraryClassXml()
323 LibraryClassNode
.appendChild(Tmp
.ToXml(LibraryClass
, 'LibraryClass'))
324 DomPackage
.appendChild(LibraryClassNode
)
326 # IndustryStandardHeader
328 IndustryStandardHeaderNode
= CreateXmlElement('IndustryStandardIncludes', '', [], [])
329 for Include
in Package
.GetStandardIncludeFileList():
330 Tmp
= IndustryStandardHeaderXml()
331 IndustryStandardHeaderNode
.appendChild(Tmp
.ToXml(Include
, 'IndustryStandardHeader'))
332 DomPackage
.appendChild(IndustryStandardHeaderNode
)
336 PackageIncludeHeaderNode
= CreateXmlElement('PackageIncludes', '', [], [])
337 for Include
in Package
.GetPackageIncludeFileList():
338 Tmp
= PackageIncludeHeaderXml()
339 PackageIncludeHeaderNode
.appendChild(Tmp
.ToXml(Include
, 'PackageHeader'))
340 DomPackage
.appendChild(PackageIncludeHeaderNode
)
341 ModuleNode
= CreateXmlElement('Modules', '', [], [])
342 for Module
in Package
.GetModuleDict().values():
343 Tmp
= ModuleSurfaceAreaXml()
344 ModuleNode
.appendChild(Tmp
.ToXml(Module
))
345 DomPackage
.appendChild(ModuleNode
)
349 GuidProtocolPpiNode
= CreateXmlElement('GuidDeclarations', '', [], [])
350 for GuidProtocolPpi
in Package
.GetGuidList():
351 Tmp
= GuidXml('Package')
352 GuidProtocolPpiNode
.appendChild(Tmp
.ToXml\
353 (GuidProtocolPpi
, 'Entry'))
354 DomPackage
.appendChild(GuidProtocolPpiNode
)
358 GuidProtocolPpiNode
= \
359 CreateXmlElement('ProtocolDeclarations', '', [], [])
360 for GuidProtocolPpi
in Package
.GetProtocolList():
361 Tmp
= ProtocolXml('Package')
362 GuidProtocolPpiNode
.appendChild\
363 (Tmp
.ToXml(GuidProtocolPpi
, 'Entry'))
364 DomPackage
.appendChild(GuidProtocolPpiNode
)
368 GuidProtocolPpiNode
= CreateXmlElement('PpiDeclarations', '', [], [])
369 for GuidProtocolPpi
in Package
.GetPpiList():
370 Tmp
= PpiXml('Package')
371 GuidProtocolPpiNode
.appendChild\
372 (Tmp
.ToXml(GuidProtocolPpi
, 'Entry'))
373 DomPackage
.appendChild(GuidProtocolPpiNode
)
377 PcdEntryNode
= CreateXmlElement('PcdDeclarations', '', [], [])
378 for PcdEntry
in Package
.GetPcdList():
380 PcdEntryNode
.appendChild(Tmp
.ToXml2(PcdEntry
, 'PcdEntry'))
381 DomPackage
.appendChild(PcdEntryNode
)
386 Tmp
= MiscellaneousFileXml()
387 if Package
.GetMiscFileList():
388 DomPackage
.appendChild(Tmp
.ToXml(Package
.GetMiscFileList()[0], 'MiscellaneousFiles'))
393 if Package
.GetUserExtensionList():
394 for UserExtension
in Package
.GetUserExtensionList():
395 Tmp
= UserExtensionsXml()
396 DomPackage
.appendChild(Tmp
.ToXml(UserExtension
, 'UserExtensions'))