]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/UPT/Xml/CommonXml.py
BaseTools: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / BaseTools / Source / Python / UPT / Xml / CommonXml.py
1 ## @file
2 # This file is used to parse a PCD file of .PKG file
3 #
4 # Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
5 #
6 # SPDX-License-Identifier: BSD-2-Clause-Patent
7 #
8
9 '''
10 CommonXml
11 '''
12
13 ##
14 # Import Modules
15 #
16
17 from Core.DistributionPackageClass import DistributionPackageHeaderObject
18 from Library.StringUtils import ConvertNEToNOTEQ
19 from Library.StringUtils import ConvertNOTEQToNE
20 from Library.StringUtils import GetSplitValueList
21 from Library.StringUtils import GetStringOfList
22 from Library.Xml.XmlRoutines import XmlElement
23 from Library.Xml.XmlRoutines import XmlElement2
24 from Library.Xml.XmlRoutines import XmlAttribute
25 from Library.Xml.XmlRoutines import XmlNode
26 from Library.Xml.XmlRoutines import XmlList
27 from Library.Xml.XmlRoutines import CreateXmlElement
28 from Library.UniClassObject import ConvertSpecialUnicodes
29 from Library.UniClassObject import GetLanguageCode1766
30 from Object.POM.CommonObject import FileObject
31 from Object.POM.CommonObject import MiscFileObject
32 from Object.POM.CommonObject import UserExtensionObject
33 from Object.POM.CommonObject import ClonedRecordObject
34 from Object.POM.CommonObject import LibraryClassObject
35 from Object.POM.CommonObject import FileNameObject
36 from Object.POM.ModuleObject import ModuleObject
37 from Xml.XmlParserMisc import IsRequiredItemListNull
38 from Xml.XmlParserMisc import GetHelpTextList
39 import Library.DataType as DataType
40
41 ##
42 # ClonedFromXml
43 #
44 class ClonedFromXml(object):
45 def __init__(self):
46 self.GUID = ''
47 self.Version = ''
48
49 def FromXml(self, Item, Key):
50 self.GUID = XmlElement(Item, '%s/GUID' % Key)
51 self.Version = XmlAttribute(XmlNode(Item, '%s/GUID' % Key), 'Version')
52 if self.GUID == '' and self.Version == '':
53 return None
54 ClonedFrom = ClonedRecordObject()
55 ClonedFrom.SetPackageGuid(self.GUID)
56 ClonedFrom.SetPackageVersion(self.Version)
57 return ClonedFrom
58
59 def ToXml(self, ClonedFrom, Key):
60 if self.GUID:
61 pass
62 Element1 = CreateXmlElement('GUID', ClonedFrom.GetPackageGuid(), [],
63 [['Version', ClonedFrom.GetPackageVersion()]])
64 AttributeList = []
65 NodeList = [Element1]
66 Root = CreateXmlElement('%s' % Key, '', NodeList, AttributeList)
67 return Root
68
69 def __str__(self):
70 return "GUID = %s Version = %s" % (self.GUID, self.Version)
71
72
73 ##
74 # CommonDefinesXml
75 #
76 class CommonDefinesXml(object):
77 def __init__(self):
78 self.Usage = ''
79 self.SupArchList = []
80 self.SupModList = []
81 self.FeatureFlag = ''
82
83 def FromXml(self, Item, Key):
84 if Key:
85 pass
86 self.Usage = XmlAttribute(Item, 'Usage')
87 self.SupArchList = \
88 [Arch for Arch in GetSplitValueList(XmlAttribute(Item, 'SupArchList'), DataType.TAB_SPACE_SPLIT) if Arch]
89 self.SupModList = \
90 [Mod for Mod in GetSplitValueList(XmlAttribute(Item, 'SupModList'), DataType.TAB_SPACE_SPLIT) if Mod]
91 self.FeatureFlag = ConvertNOTEQToNE(XmlAttribute(Item, 'FeatureFlag'))
92
93 def ToXml(self):
94 pass
95
96 def __str__(self):
97 return "Usage = %s SupArchList = %s SupModList = %s FeatureFlag = %s" \
98 % (self.Usage, self.SupArchList, self.SupModList, self.FeatureFlag)
99
100 ##
101 # PromptXml
102 #
103 class PromptXml(object):
104 def __init__(self):
105 self.Prompt = ''
106 self.Lang = ''
107
108 def FromXml(self, Item, Key):
109 if Key:
110 pass
111 self.Prompt = XmlElement2(Item, 'Prompt')
112 self.Lang = XmlAttribute(Item, 'Lang')
113
114 def ToXml(self, Prompt, Key='Prompt'):
115 if self.Prompt:
116 pass
117 return CreateXmlElement('%s' % Key, Prompt.GetString(), [], [['Lang', Prompt.GetLang()]])
118 def __str__(self):
119 return "Prompt = %s Lang = %s" % (self.Prompt, self.Lang)
120
121 ##
122 # HelpTextXml
123 #
124 class HelpTextXml(object):
125 def __init__(self):
126 self.HelpText = ''
127 self.Lang = ''
128
129 def FromXml(self, Item, Key):
130 if Key:
131 pass
132 self.HelpText = XmlElement2(Item, 'HelpText')
133 self.Lang = XmlAttribute(Item, 'Lang')
134
135 def ToXml(self, HelpText, Key='HelpText'):
136 if self.HelpText:
137 pass
138 return CreateXmlElement('%s' % Key, HelpText.GetString(), [], [['Lang', HelpText.GetLang()]])
139 def __str__(self):
140 return "HelpText = %s Lang = %s" % (self.HelpText, self.Lang)
141
142 ##
143 # HeaderXml
144 #
145 class HeaderXml(object):
146 def __init__(self):
147 self.Name = ''
148 self.BaseName = ''
149 self.GUID = ''
150 self.Version = ''
151 self.CopyrightList = []
152 self.LicenseList = []
153 self.AbstractList = []
154 self.DescriptionList = []
155
156 def FromXml(self, Item, Key, IsRequiredCheck=False, IsStandAlongModule=False):
157 if not Item and IsRequiredCheck:
158 XmlTreeLevel = []
159 if IsStandAlongModule:
160 XmlTreeLevel = ['DistributionPackage', 'ModuleSurfaceArea']
161 else:
162 XmlTreeLevel = ['DistributionPackage', 'PackageSurfaceArea', 'ModuleSurfaceArea']
163 CheckDict = {'Header':''}
164 IsRequiredItemListNull(CheckDict, XmlTreeLevel)
165 self.Name = XmlElement(Item, '%s/Name' % Key)
166 self.BaseName = XmlAttribute(XmlNode(Item, '%s/Name' % Key), 'BaseName')
167 self.GUID = XmlElement(Item, '%s/GUID' % Key)
168 self.Version = XmlAttribute(XmlNode(Item, '%s/GUID' % Key), 'Version')
169
170 for SubItem in XmlList(Item, '%s/Abstract' % Key):
171 HeaderAbstractLang = XmlAttribute(SubItem, 'Lang')
172 self.AbstractList.append((HeaderAbstractLang, XmlElement(SubItem, '%s/Abstract' % Key)))
173 for SubItem in XmlList(Item, '%s/Description' % Key):
174 HeaderDescriptionLang = XmlAttribute(SubItem, 'Lang')
175 self.DescriptionList.append((HeaderDescriptionLang, XmlElement(SubItem, '%s/Description' % Key)))
176 for SubItem in XmlList(Item, '%s/Copyright' % Key):
177 HeaderCopyrightLang = XmlAttribute(SubItem, 'Lang')
178 self.CopyrightList.append((HeaderCopyrightLang, XmlElement(SubItem, '%s/Copyright' % Key)))
179 for SubItem in XmlList(Item, '%s/License' % Key):
180 HeaderLicenseLang = XmlAttribute(SubItem, 'Lang')
181 self.LicenseList.append((HeaderLicenseLang, XmlElement(SubItem, '%s/License' % Key)))
182 ModuleHeader = ModuleObject()
183 ModuleHeader.SetName(self.Name)
184 ModuleHeader.SetBaseName(self.BaseName)
185 ModuleHeader.SetGuid(self.GUID)
186 ModuleHeader.SetVersion(self.Version)
187 ModuleHeader.SetCopyright(self.CopyrightList)
188 ModuleHeader.SetLicense(self.LicenseList)
189 ModuleHeader.SetAbstract(self.AbstractList)
190 ModuleHeader.SetDescription(self.DescriptionList)
191 return ModuleHeader
192
193 def ToXml(self, Header, Key):
194 if self.GUID:
195 pass
196 Element1 = CreateXmlElement('Name', Header.GetName(), [], [['BaseName', Header.GetBaseName()]])
197 Element2 = CreateXmlElement('GUID', Header.GetGuid(), [], [['Version', Header.GetVersion()]])
198 NodeList = [Element1,
199 Element2,
200 ]
201
202 UNIInfAbstractList = []
203 UNIInfDescriptionList = []
204 # Get Abstract and Description from Uni File
205 # if the Uni File exists
206 if Header.UniFileClassObject is not None:
207 UniStrDict = Header.UniFileClassObject.OrderedStringList
208 for Lang in UniStrDict:
209 for StringDefClassObject in UniStrDict[Lang]:
210 if not StringDefClassObject.StringValue:
211 continue
212 if StringDefClassObject.StringName == DataType.TAB_INF_ABSTRACT:
213 UNIInfAbstractList.append((GetLanguageCode1766(Lang),
214 ConvertSpecialUnicodes(StringDefClassObject.StringValue)))
215
216 if StringDefClassObject.StringName == DataType.TAB_INF_DESCRIPTION:
217 UNIInfDescriptionList.append((GetLanguageCode1766(Lang),
218 ConvertSpecialUnicodes(StringDefClassObject.StringValue)))
219
220 # Get Abstract and Description from INF File Header
221 for (Lang, Value) in Header.GetCopyright():
222 if Value:
223 NodeList.append(CreateXmlElement('Copyright', Value, [], []))
224 for (Lang, Value) in Header.GetLicense():
225 if Value:
226 NodeList.append(CreateXmlElement('License', Value, [], []))
227 for (Lang, Value) in Header.GetAbstract() + UNIInfAbstractList:
228 if Value:
229 NodeList.append(CreateXmlElement('Abstract', Value, [], [['Lang', Lang]]))
230 for (Lang, Value) in Header.GetDescription() + UNIInfDescriptionList:
231 if Value:
232 NodeList.append(CreateXmlElement('Description', Value, [], [['Lang', Lang]]))
233
234 AttributeList = []
235 Root = CreateXmlElement('%s' % Key, '', NodeList, AttributeList)
236 return Root
237
238 def __str__(self):
239 return "Name = %s BaseName = %s GUID = %s Version = %s Copyright = %s \
240 License = %s Abstract = %s Description = %s" % \
241 (self.Name, self.BaseName, self.GUID, self.Version, self.CopyrightList, \
242 self.LicenseList, self.AbstractList, self.DescriptionList)
243 ##
244 # DistributionPackageHeaderXml
245 #
246 class DistributionPackageHeaderXml(object):
247 def __init__(self):
248 self.Header = HeaderXml()
249 self.ReadOnly = ''
250 self.RePackage = ''
251 self.Vendor = ''
252 self.Date = ''
253 self.Signature = ''
254 self.XmlSpecification = ''
255
256 def FromXml(self, Item, Key):
257 if not Item:
258 return None
259 self.ReadOnly = XmlAttribute(XmlNode(Item, '%s' % Key), 'ReadOnly')
260 self.RePackage = XmlAttribute(XmlNode(Item, '%s' % Key), 'RePackage')
261 self.Vendor = XmlElement(Item, '%s/Vendor' % Key)
262 self.Date = XmlElement(Item, '%s/Date' % Key)
263 self.Signature = XmlElement(Item, '%s/Signature' % Key)
264 self.XmlSpecification = XmlElement(Item, '%s/XmlSpecification' % Key)
265 self.Header.FromXml(Item, Key)
266 DistributionPackageHeader = DistributionPackageHeaderObject()
267 if self.ReadOnly.upper() == 'TRUE':
268 DistributionPackageHeader.ReadOnly = True
269 elif self.ReadOnly.upper() == 'FALSE':
270 DistributionPackageHeader.ReadOnly = False
271 if self.RePackage.upper() == 'TRUE':
272 DistributionPackageHeader.RePackage = True
273 elif self.RePackage.upper() == 'FALSE':
274 DistributionPackageHeader.RePackage = False
275 DistributionPackageHeader.Vendor = self.Vendor
276 DistributionPackageHeader.Date = self.Date
277 DistributionPackageHeader.Signature = self.Signature
278 DistributionPackageHeader.XmlSpecification = self.XmlSpecification
279 DistributionPackageHeader.SetName(self.Header.Name)
280 DistributionPackageHeader.SetBaseName(self.Header.BaseName)
281 DistributionPackageHeader.SetGuid(self.Header.GUID)
282 DistributionPackageHeader.SetVersion(self.Header.Version)
283 DistributionPackageHeader.SetCopyright(self.Header.CopyrightList)
284 DistributionPackageHeader.SetLicense(self.Header.LicenseList)
285 DistributionPackageHeader.SetAbstract(self.Header.AbstractList)
286 DistributionPackageHeader.SetDescription(self.Header.DescriptionList)
287 return DistributionPackageHeader
288
289 def ToXml(self, DistributionPackageHeader, Key):
290 if self.Header:
291 pass
292 Element1 = CreateXmlElement('Name', \
293 DistributionPackageHeader.GetName(), [], \
294 [['BaseName', \
295 DistributionPackageHeader.GetBaseName()]])
296 Element2 = CreateXmlElement('GUID', \
297 DistributionPackageHeader.GetGuid(), [], \
298 [['Version', \
299 DistributionPackageHeader.GetVersion()]])
300 AttributeList = []
301 if DistributionPackageHeader.ReadOnly != '':
302 AttributeList.append(['ReadOnly', str(DistributionPackageHeader.ReadOnly).lower()])
303 if DistributionPackageHeader.RePackage != '':
304 AttributeList.append(['RePackage', str(DistributionPackageHeader.RePackage).lower()])
305 if DistributionPackageHeader.GetAbstract():
306 DPAbstract = DistributionPackageHeader.GetAbstract()[0][1]
307 else:
308 DPAbstract = ''
309 if DistributionPackageHeader.GetDescription():
310 DPDescription = DistributionPackageHeader.GetDescription()[0][1]
311 else:
312 DPDescription = ''
313 if DistributionPackageHeader.GetCopyright():
314 DPCopyright = DistributionPackageHeader.GetCopyright()[0][1]
315 else:
316 DPCopyright = ''
317 if DistributionPackageHeader.GetLicense():
318 DPLicense = DistributionPackageHeader.GetLicense()[0][1]
319 else:
320 DPLicense = ''
321 NodeList = [Element1,
322 Element2,
323 ['Vendor', DistributionPackageHeader.Vendor],
324 ['Date', DistributionPackageHeader.Date],
325 ['Copyright', DPCopyright],
326 ['License', DPLicense],
327 ['Abstract', DPAbstract],
328 ['Description', DPDescription],
329 ['Signature', DistributionPackageHeader.Signature],
330 ['XmlSpecification', \
331 DistributionPackageHeader.XmlSpecification],
332 ]
333 Root = CreateXmlElement('%s' % Key, '', NodeList, AttributeList)
334 return Root
335
336 def __str__(self):
337 return "ReadOnly = %s RePackage = %s Vendor = %s Date = %s \
338 Signature = %s XmlSpecification = %s %s" % \
339 (self.ReadOnly, self.RePackage, self.Vendor, self.Date, \
340 self.Signature, self.XmlSpecification, self.Header)
341 ##
342 # PackageHeaderXml
343 #
344 class PackageHeaderXml(object):
345 def __init__(self):
346 self.Header = HeaderXml()
347 self.PackagePath = ''
348
349 def FromXml(self, Item, Key, PackageObject2):
350 if not Item:
351 XmlTreeLevel = ['DistributionPackage', 'PackageSurfaceArea']
352 CheckDict = {'PackageHeader': None, }
353 IsRequiredItemListNull(CheckDict, XmlTreeLevel)
354 self.PackagePath = XmlElement(Item, '%s/PackagePath' % Key)
355 self.Header.FromXml(Item, Key)
356 PackageObject2.SetName(self.Header.Name)
357 PackageObject2.SetBaseName(self.Header.BaseName)
358 PackageObject2.SetGuid(self.Header.GUID)
359 PackageObject2.SetVersion(self.Header.Version)
360 PackageObject2.SetCopyright(self.Header.CopyrightList)
361 PackageObject2.SetLicense(self.Header.LicenseList)
362 PackageObject2.SetAbstract(self.Header.AbstractList)
363 PackageObject2.SetDescription(self.Header.DescriptionList)
364 PackageObject2.SetPackagePath(self.PackagePath)
365
366 def ToXml(self, PackageObject2, Key):
367 if self.PackagePath:
368 pass
369 Element1 = CreateXmlElement('Name', PackageObject2.GetName(), [], \
370 [['BaseName', PackageObject2.GetBaseName()]])
371 Element2 = CreateXmlElement('GUID', PackageObject2.GetGuid(), [], \
372 [['Version', PackageObject2.GetVersion()]])
373 NodeList = [Element1,
374 Element2
375 ]
376
377 UNIPackageAbrstractList = []
378 UNIPackageDescriptionList = []
379 # Get Abstract and Description from Uni File
380 # if the Uni File exists
381 if PackageObject2.UniFileClassObject is not None:
382 UniStrDict = PackageObject2.UniFileClassObject.OrderedStringList
383 for Lang in UniStrDict:
384 for StringDefClassObject in UniStrDict[Lang]:
385 if not StringDefClassObject.StringValue:
386 continue
387 if StringDefClassObject.StringName == DataType.TAB_DEC_PACKAGE_ABSTRACT:
388 UNIPackageAbrstractList.append((GetLanguageCode1766(Lang),
389 ConvertSpecialUnicodes(StringDefClassObject.StringValue)))
390
391 if StringDefClassObject.StringName == DataType.TAB_DEC_PACKAGE_DESCRIPTION:
392 UNIPackageDescriptionList.append((GetLanguageCode1766(Lang),
393 ConvertSpecialUnicodes(StringDefClassObject.StringValue)))
394
395 # Get Abstract and Description from DEC File Header
396 for (Lang, Value) in PackageObject2.GetCopyright():
397 if Value:
398 NodeList.append(CreateXmlElement(DataType.TAB_HEADER_COPYRIGHT, Value, [], []))
399 for (Lang, Value) in PackageObject2.GetLicense():
400 if Value:
401 NodeList.append(CreateXmlElement(DataType.TAB_HEADER_LICENSE, Value, [], []))
402 for (Lang, Value) in PackageObject2.GetAbstract() + UNIPackageAbrstractList:
403 if Value:
404 NodeList.append(CreateXmlElement(DataType.TAB_HEADER_ABSTRACT, Value, [], [['Lang', Lang]]))
405 for (Lang, Value) in PackageObject2.GetDescription() + UNIPackageDescriptionList:
406 if Value:
407 NodeList.append(CreateXmlElement(DataType.TAB_HEADER_DESCRIPTION, Value, [], [['Lang', Lang]]))
408
409
410 NodeList.append(['PackagePath', PackageObject2.GetPackagePath()])
411 AttributeList = []
412 Root = CreateXmlElement('%s' % Key, '', NodeList, AttributeList)
413 return Root
414
415 def __str__(self):
416 return "PackagePath = %s %s" \
417 % (self.PackagePath, self.Header)
418
419 ##
420 # MiscellaneousFileXml
421 #
422 class MiscellaneousFileXml(object):
423 def __init__(self):
424 self.Header = HeaderXml()
425 self.Files = []
426 ##
427 # This API is used for Package or Module's MiscellaneousFile section
428 #
429 def FromXml(self, Item, Key):
430 if not Item:
431 return None
432 self.Header.FromXml(Item, Key)
433 NewItem = XmlNode(Item, '%s/Header' % Key)
434 self.Header.FromXml(NewItem, 'Header')
435 for SubItem in XmlList(Item, '%s/Filename' % Key):
436 Filename = XmlElement(SubItem, '%s/Filename' % Key)
437 Executable = XmlAttribute(XmlNode(SubItem, '%s/Filename' % Key), 'Executable')
438 if Executable.upper() == "TRUE":
439 Executable = True
440 elif Executable.upper() == "FALSE":
441 Executable = False
442 else:
443 Executable = ''
444 self.Files.append([Filename, Executable])
445 MiscFile = MiscFileObject()
446 MiscFile.SetCopyright(self.Header.CopyrightList)
447 MiscFile.SetLicense(self.Header.LicenseList)
448 MiscFile.SetAbstract(self.Header.AbstractList)
449 MiscFile.SetDescription(self.Header.DescriptionList)
450 MiscFileList = []
451 for File in self.Files:
452 FileObj = FileObject()
453 FileObj.SetURI(File[0])
454 FileObj.SetExecutable(File[1])
455 MiscFileList.append(FileObj)
456 MiscFile.SetFileList(MiscFileList)
457 return MiscFile
458 ##
459 # This API is used for DistP's tool section
460 #
461 def FromXml2(self, Item, Key):
462 if Item is None:
463 return None
464 NewItem = XmlNode(Item, '%s/Header' % Key)
465 self.Header.FromXml(NewItem, 'Header')
466 for SubItem in XmlList(Item, '%s/Filename' % Key):
467 Filename = XmlElement(SubItem, '%s/Filename' % Key)
468 Executable = \
469 XmlAttribute(XmlNode(SubItem, '%s/Filename' % Key), 'Executable')
470 OsType = XmlAttribute(XmlNode(SubItem, '%s/Filename' % Key), 'OS')
471 if Executable.upper() == "TRUE":
472 Executable = True
473 elif Executable.upper() == "FALSE":
474 Executable = False
475 else:
476 Executable = ''
477 self.Files.append([Filename, Executable, OsType])
478 MiscFile = MiscFileObject()
479 MiscFile.SetName(self.Header.Name)
480 MiscFile.SetCopyright(self.Header.CopyrightList)
481 MiscFile.SetLicense(self.Header.LicenseList)
482 MiscFile.SetAbstract(self.Header.AbstractList)
483 MiscFile.SetDescription(self.Header.DescriptionList)
484 MiscFileList = []
485 for File in self.Files:
486 FileObj = FileObject()
487 FileObj.SetURI(File[0])
488 FileObj.SetExecutable(File[1])
489 FileObj.SetOS(File[2])
490 MiscFileList.append(FileObj)
491 MiscFile.SetFileList(MiscFileList)
492 return MiscFile
493
494 ##
495 # This API is used for Package or Module's MiscellaneousFile section
496 #
497 def ToXml(self, MiscFile, Key):
498 if self.Header:
499 pass
500 if MiscFile:
501 if MiscFile.GetAbstract():
502 DPAbstract = MiscFile.GetAbstract()[0][1]
503 else:
504 DPAbstract = ''
505 if MiscFile.GetDescription():
506 DPDescription = MiscFile.GetDescription()[0][1]
507 else:
508 DPDescription = ''
509 if MiscFile.GetCopyright():
510 DPCopyright = MiscFile.GetCopyright()[0][1]
511 else:
512 DPCopyright = ''
513 if MiscFile.GetLicense():
514 DPLicense = MiscFile.GetLicense()[0][1]
515 else:
516 DPLicense = ''
517 NodeList = [['Copyright', DPCopyright],
518 ['License', DPLicense],
519 ['Abstract', DPAbstract],
520 ['Description', DPDescription],
521 ]
522 for File in MiscFile.GetFileList():
523 NodeList.append\
524 (CreateXmlElement\
525 ('Filename', File.GetURI(), [], \
526 [['Executable', str(File.GetExecutable()).lower()]]))
527 Root = CreateXmlElement('%s' % Key, '', NodeList, [])
528 return Root
529 ##
530 # This API is used for DistP's tool section
531 #
532 def ToXml2(self, MiscFile, Key):
533 if self.Header:
534 pass
535 if MiscFile:
536 if MiscFile.GetAbstract():
537 DPAbstract = MiscFile.GetAbstract()[0][1]
538 else:
539 DPAbstract = ''
540 if MiscFile.GetDescription():
541 DPDescription = MiscFile.GetDescription()[0][1]
542 else:
543 DPDescription = ''
544 if MiscFile.GetCopyright():
545 DPCopyright = MiscFile.GetCopyright()[0][1]
546 else:
547 DPCopyright = ''
548 if MiscFile.GetLicense():
549 DPLicense = MiscFile.GetLicense()[0][1]
550 else:
551 DPLicense = ''
552 NodeList = [['Name', MiscFile.GetName()],
553 ['Copyright', DPCopyright],
554 ['License', DPLicense],
555 ['Abstract', DPAbstract],
556 ['Description', DPDescription],
557 ]
558 HeaderNode = CreateXmlElement('Header', '', NodeList, [])
559 NodeList = [HeaderNode]
560 for File in MiscFile.GetFileList():
561 NodeList.append\
562 (CreateXmlElement\
563 ('Filename', File.GetURI(), [], \
564 [['Executable', str(File.GetExecutable()).lower()], \
565 ['OS', File.GetOS()]]))
566 Root = CreateXmlElement('%s' % Key, '', NodeList, [])
567 return Root
568
569 def __str__(self):
570 Str = str(self.Header)
571 for Item in self.Files:
572 Str = Str + '\n\tFilename:' + str(Item)
573 return Str
574 ##
575 # UserExtensionsXml
576 #
577 class UserExtensionsXml(object):
578 def __init__(self):
579 self.UserId = ''
580 self.Identifier = ''
581 self.BinaryAbstractList = []
582 self.BinaryDescriptionList = []
583 self.BinaryCopyrightList = []
584 self.BinaryLicenseList = []
585 self.LangDefsList = []
586 self.DefineDict = {}
587 self.BuildOptionDict = {}
588 self.IncludesDict = {}
589 self.SourcesDict = {}
590 self.BinariesDict = {}
591 self.SupArchList = []
592 self.Statement = ''
593 self.Defines = ''
594 self.BuildOptions = ''
595
596 def FromXml2(self, Item, Key):
597 self.UserId = XmlAttribute(XmlNode(Item, '%s' % Key), 'UserId')
598 self.Identifier = XmlAttribute(XmlNode(Item, '%s' % Key), 'Identifier')
599 UserExtension = UserExtensionObject()
600 UserExtension.SetUserID(self.UserId)
601 UserExtension.SetIdentifier(self.Identifier)
602 return UserExtension
603
604 def FromXml(self, Item, Key):
605 self.UserId = XmlAttribute(XmlNode(Item, '%s' % Key), 'UserId')
606 self.Identifier = XmlAttribute(XmlNode(Item, '%s' % Key), 'Identifier')
607 if self.UserId == DataType.TAB_BINARY_HEADER_USERID \
608 and self.Identifier == DataType.TAB_BINARY_HEADER_IDENTIFIER:
609 for SubItem in XmlList(Item, '%s/BinaryAbstract' % Key):
610 BinaryAbstractLang = XmlAttribute(SubItem, 'Lang')
611 self.BinaryAbstractList.append((BinaryAbstractLang, XmlElement(SubItem, '%s/BinaryAbstract' % Key)))
612 for SubItem in XmlList(Item, '%s/BinaryDescription' % Key):
613 BinaryDescriptionLang = XmlAttribute(SubItem, 'Lang')
614 self.BinaryDescriptionList.append((BinaryDescriptionLang,
615 XmlElement(SubItem, '%s/BinaryDescription' % Key)))
616 for SubItem in XmlList(Item, '%s/BinaryCopyright' % Key):
617 BinaryCopyrightLang = XmlAttribute(SubItem, 'Lang')
618 self.BinaryCopyrightList.append((BinaryCopyrightLang,
619 XmlElement(SubItem, '%s/BinaryCopyright' % Key)))
620 for SubItem in XmlList(Item, '%s/BinaryLicense' % Key):
621 BinaryLicenseLang = XmlAttribute(SubItem, 'Lang')
622 self.BinaryLicenseList.append((BinaryLicenseLang,
623 XmlElement(SubItem, '%s/BinaryLicense' % Key)))
624
625 DefineItem = XmlNode(Item, '%s/Define' % Key)
626 for SubItem in XmlList(DefineItem, 'Define/Statement'):
627 Statement = XmlElement(SubItem, '%s/Statement' % Key)
628 self.DefineDict[Statement] = ""
629 BuildOptionItem = XmlNode(Item, '%s/BuildOption' % Key)
630 for SubItem in XmlList(BuildOptionItem, 'BuildOption/Statement'):
631 Statement = XmlElement(SubItem, '%s/Statement' % Key)
632 Arch = XmlAttribute(XmlNode(SubItem, '%s/Statement' % Key), 'SupArchList')
633 self.BuildOptionDict[Arch] = Statement
634 IncludesItem = XmlNode(Item, '%s/Includes' % Key)
635 for SubItem in XmlList(IncludesItem, 'Includes/Statement'):
636 Statement = XmlElement(SubItem, '%s/Statement' % Key)
637 Arch = XmlAttribute(XmlNode(SubItem, '%s/Statement' % Key), 'SupArchList')
638 self.IncludesDict[Statement] = Arch
639 SourcesItem = XmlNode(Item, '%s/Sources' % Key)
640 Tmp = UserExtensionSourceXml()
641 SourceDict = Tmp.FromXml(SourcesItem, 'Sources')
642 self.SourcesDict = SourceDict
643 BinariesItem = XmlNode(Item, '%s/Binaries' % Key)
644 Tmp = UserExtensionBinaryXml()
645 BinariesDict = Tmp.FromXml(BinariesItem, 'Binaries')
646 self.BinariesDict = BinariesDict
647 self.Statement = XmlElement(Item, 'UserExtensions')
648 SupArch = XmlAttribute(XmlNode(Item, '%s' % Key), 'SupArchList')
649 self.SupArchList = [Arch for Arch in GetSplitValueList(SupArch, DataType.TAB_SPACE_SPLIT) if Arch]
650 UserExtension = UserExtensionObject()
651 UserExtension.SetUserID(self.UserId)
652 UserExtension.SetIdentifier(self.Identifier)
653 UserExtension.SetBinaryAbstract(self.BinaryAbstractList)
654 UserExtension.SetBinaryDescription(self.BinaryDescriptionList)
655 UserExtension.SetBinaryCopyright(self.BinaryCopyrightList)
656 UserExtension.SetBinaryLicense(self.BinaryLicenseList)
657 UserExtension.SetStatement(self.Statement)
658 UserExtension.SetSupArchList(self.SupArchList)
659 UserExtension.SetDefinesDict(self.DefineDict)
660 UserExtension.SetBuildOptionDict(self.BuildOptionDict)
661 UserExtension.SetIncludesDict(self.IncludesDict)
662 UserExtension.SetSourcesDict(self.SourcesDict)
663 UserExtension.SetBinariesDict(self.BinariesDict)
664 return UserExtension
665
666 def ToXml(self, UserExtension, Key):
667 if self.UserId:
668 pass
669 AttributeList = [['UserId', str(UserExtension.GetUserID())],
670 ['Identifier', str(UserExtension.GetIdentifier())],
671 ['SupArchList', \
672 GetStringOfList(UserExtension.GetSupArchList())],
673 ]
674 Root = CreateXmlElement('%s' % Key, UserExtension.GetStatement(), [], \
675 AttributeList)
676 if UserExtension.GetIdentifier() == DataType.TAB_BINARY_HEADER_IDENTIFIER and \
677 UserExtension.GetUserID() == DataType.TAB_BINARY_HEADER_USERID:
678 for (Lang, Value) in UserExtension.GetBinaryAbstract():
679 if Value:
680 ChildElement = CreateXmlElement('BinaryAbstract', Value, [], [['Lang', Lang]])
681 Root.appendChild(ChildElement)
682 for (Lang, Value) in UserExtension.GetBinaryDescription():
683 if Value:
684 ChildElement = CreateXmlElement('BinaryDescription', Value, [], [['Lang', Lang]])
685 Root.appendChild(ChildElement)
686 for (Lang, Value) in UserExtension.GetBinaryCopyright():
687 if Value:
688 ChildElement = CreateXmlElement('BinaryCopyright', Value, [], [])
689 Root.appendChild(ChildElement)
690 for (Lang, Value) in UserExtension.GetBinaryLicense():
691 if Value:
692 ChildElement = CreateXmlElement('BinaryLicense', Value, [], [])
693 Root.appendChild(ChildElement)
694
695 NodeList = []
696 DefineDict = UserExtension.GetDefinesDict()
697 if DefineDict:
698 for Item in DefineDict.keys():
699 NodeList.append(CreateXmlElement\
700 ('Statement', Item, [], []))
701 DefineElement = CreateXmlElement('Define', '', NodeList, [])
702 Root.appendChild(DefineElement)
703 NodeList = []
704 BuildOptionDict = UserExtension.GetBuildOptionDict()
705 if BuildOptionDict:
706 for Item in BuildOptionDict.keys():
707 NodeList.append(CreateXmlElement\
708 ('Statement', BuildOptionDict[Item], [], \
709 [['SupArchList', Item]]))
710 BuildOptionElement = \
711 CreateXmlElement('BuildOption', '', NodeList, [])
712 Root.appendChild(BuildOptionElement)
713 NodeList = []
714 IncludesDict = UserExtension.GetIncludesDict()
715 if IncludesDict:
716 for Item in IncludesDict.keys():
717 NodeList.append(CreateXmlElement\
718 ('Statement', Item, [], \
719 [['SupArchList', IncludesDict[Item]]]))
720 IncludesElement = CreateXmlElement('Includes', '', NodeList, [])
721 Root.appendChild(IncludesElement)
722 NodeList = []
723 SourcesDict = UserExtension.GetSourcesDict()
724 if SourcesDict:
725 Tmp = UserExtensionSourceXml()
726 Root.appendChild(Tmp.ToXml(SourcesDict, 'Sources'))
727 NodeList = []
728 BinariesDict = UserExtension.GetBinariesDict()
729 if BinariesDict:
730 Tmp = UserExtensionBinaryXml()
731 Root.appendChild(Tmp.ToXml(BinariesDict, 'Binaries'))
732 return Root
733
734 def __str__(self):
735 Str = "UserId = %s Identifier = %s" % (self.UserId, self.Identifier)
736 Str = Str + '\n\tDefines:' + str(self.Defines)
737 Str = Str + '\n\tBuildOptions:' + str(self.BuildOptions)
738 return Str
739
740 ##
741 # UserExtensionSourceXml
742 #
743 class UserExtensionSourceXml(object):
744 def __init__(self):
745 self.UserExtensionSource = ''
746
747 def FromXml(self, Item, Key):
748 if Key:
749 pass
750 if self.UserExtensionSource:
751 pass
752 Dict = {}
753 #SourcesItem = XmlNode(Item, '%s/Sources' % Key)
754 for SubItem in XmlList(Item, 'Sources/SourceFile'):
755 FileName = XmlElement(SubItem, 'SourceFile/FileName')
756 Family = XmlElement(SubItem, 'SourceFile/Family')
757 FeatureFlag = XmlElement(SubItem, 'SourceFile/FeatureFlag')
758 SupArchStr = XmlElement(SubItem, 'SourceFile/SupArchList')
759 DictKey = (FileName, Family, FeatureFlag, SupArchStr)
760 ValueList = []
761 for ValueNodeItem in XmlList(SubItem, \
762 'SourceFile/SourceFileOtherAttr'):
763 TagName = XmlElement(ValueNodeItem, \
764 'SourceFileOtherAttr/TagName')
765 ToolCode = XmlElement(ValueNodeItem, \
766 'SourceFileOtherAttr/ToolCode')
767 Comment = XmlElement(ValueNodeItem, \
768 'SourceFileOtherAttr/Comment')
769 if (TagName == ' ') and (ToolCode == ' ') and (Comment == ' '):
770 TagName = ''
771 ToolCode = ''
772 Comment = ''
773 ValueList.append((TagName, ToolCode, Comment))
774 Dict[DictKey] = ValueList
775 return Dict
776
777 def ToXml(self, Dict, Key):
778 if self.UserExtensionSource:
779 pass
780 SourcesNodeList = []
781 for Item in Dict:
782 ValueList = Dict[Item]
783 (FileName, Family, FeatureFlag, SupArchStr) = Item
784 SourceFileNodeList = []
785 SourceFileNodeList.append(["FileName", FileName])
786 SourceFileNodeList.append(["Family", Family])
787 SourceFileNodeList.append(["FeatureFlag", FeatureFlag])
788 SourceFileNodeList.append(["SupArchList", SupArchStr])
789 for (TagName, ToolCode, Comment) in ValueList:
790 ValueNodeList = []
791 if not (TagName or ToolCode or Comment):
792 TagName = ' '
793 ToolCode = ' '
794 Comment = ' '
795 ValueNodeList.append(["TagName", TagName])
796 ValueNodeList.append(["ToolCode", ToolCode])
797 ValueNodeList.append(["Comment", Comment])
798 ValueNodeXml = CreateXmlElement('SourceFileOtherAttr', '', \
799 ValueNodeList, [])
800 SourceFileNodeList.append(ValueNodeXml)
801 SourceFileNodeXml = CreateXmlElement('SourceFile', '', \
802 SourceFileNodeList, [])
803 SourcesNodeList.append(SourceFileNodeXml)
804 Root = CreateXmlElement('%s' % Key, '', SourcesNodeList, [])
805 return Root
806
807 ##
808 # UserExtensionBinaryXml
809 #
810 class UserExtensionBinaryXml(object):
811 def __init__(self):
812 self.UserExtensionBinary = ''
813
814 def FromXml(self, Item, Key):
815 if Key:
816 pass
817 if self.UserExtensionBinary:
818 pass
819 Dict = {}
820 for SubItem in XmlList(Item, 'Binaries/Binary'):
821 FileName = XmlElement(SubItem, 'Binary/FileName')
822 FileType = XmlElement(SubItem, 'Binary/FileType')
823 FFE = XmlElement(SubItem, 'Binary/FeatureFlag')
824 SupArch = XmlElement(SubItem, 'Binary/SupArchList')
825 DictKey = (FileName, FileType, ConvertNOTEQToNE(FFE), SupArch)
826 ValueList = []
827 for ValueNodeItem in XmlList(SubItem, \
828 'Binary/BinaryFileOtherAttr'):
829 Target = XmlElement(ValueNodeItem, \
830 'BinaryFileOtherAttr/Target')
831 Family = XmlElement(ValueNodeItem, \
832 'BinaryFileOtherAttr/Family')
833 TagName = XmlElement(ValueNodeItem, \
834 'BinaryFileOtherAttr/TagName')
835 Comment = XmlElement(ValueNodeItem, \
836 'BinaryFileOtherAttr/Comment')
837 if (Target == ' ') and (Family == ' ') and \
838 (TagName == ' ') and (Comment == ' '):
839 Target = ''
840 Family = ''
841 TagName = ''
842 Comment = ''
843
844 ValueList.append((Target, Family, TagName, Comment))
845 Dict[DictKey] = ValueList
846 return Dict
847
848 def ToXml(self, Dict, Key):
849 if self.UserExtensionBinary:
850 pass
851 BinariesNodeList = []
852 for Item in Dict:
853 ValueList = Dict[Item]
854 (FileName, FileType, FeatureFlag, SupArch) = Item
855 FileNodeList = []
856 FileNodeList.append(["FileName", FileName])
857 FileNodeList.append(["FileType", FileType])
858 FileNodeList.append(["FeatureFlag", ConvertNEToNOTEQ(FeatureFlag)])
859 FileNodeList.append(["SupArchList", SupArch])
860 for (Target, Family, TagName, Comment) in ValueList:
861 ValueNodeList = []
862 if not (Target or Family or TagName or Comment):
863 Target = ' '
864 Family = ' '
865 TagName = ' '
866 Comment = ' '
867 ValueNodeList.append(["Target", Target])
868 ValueNodeList.append(["Family", Family])
869 ValueNodeList.append(["TagName", TagName])
870 ValueNodeList.append(["Comment", Comment])
871 ValueNodeXml = CreateXmlElement('BinaryFileOtherAttr', '', \
872 ValueNodeList, [])
873 FileNodeList.append(ValueNodeXml)
874 FileNodeXml = CreateXmlElement('Binary', '', FileNodeList, [])
875 BinariesNodeList.append(FileNodeXml)
876 Root = CreateXmlElement('%s' % Key, '', BinariesNodeList, [])
877 return Root
878
879 ##
880 # LibraryClassXml
881 #
882 class LibraryClassXml(object):
883 def __init__(self):
884 self.Keyword = ''
885 self.HeaderFile = ''
886 self.RecommendedInstanceGuid = ''
887 self.RecommendedInstanceVersion = ''
888 self.CommonDefines = CommonDefinesXml()
889 self.HelpText = []
890
891 def FromXml(self, Item, Key):
892 self.Keyword = XmlAttribute(XmlNode(Item, '%s' % Key), 'Keyword')
893 if self.Keyword == '':
894 self.Keyword = XmlElement(Item, '%s/Keyword' % Key)
895 self.HeaderFile = XmlElement(Item, '%s/HeaderFile' % Key)
896 self.CommonDefines.FromXml(XmlNode(Item, '%s' % Key), Key)
897 for HelpTextItem in XmlList(Item, '%s/HelpText' % Key):
898 HelpTextObj = HelpTextXml()
899 HelpTextObj.FromXml(HelpTextItem, '%s/HelpText' % Key)
900 self.HelpText.append(HelpTextObj)
901 LibraryClass = LibraryClassObject()
902 LibraryClass.SetLibraryClass(self.Keyword)
903 LibraryClass.SetIncludeHeader(self.HeaderFile)
904 if self.CommonDefines.Usage:
905 LibraryClass.SetUsage(self.CommonDefines.Usage)
906 LibraryClass.SetSupArchList(self.CommonDefines.SupArchList)
907 LibraryClass.SetSupModuleList(self.CommonDefines.SupModList)
908 LibraryClass.SetFeatureFlag(ConvertNOTEQToNE(self.CommonDefines.FeatureFlag))
909 LibraryClass.SetHelpTextList(GetHelpTextList(self.HelpText))
910 return LibraryClass
911
912 def ToXml(self, LibraryClass, Key):
913 if self.HeaderFile:
914 pass
915 AttributeList = \
916 [['Keyword', LibraryClass.GetLibraryClass()],
917 ['SupArchList', GetStringOfList(LibraryClass.GetSupArchList())],
918 ['SupModList', GetStringOfList(LibraryClass.GetSupModuleList())]
919 ]
920 NodeList = [['HeaderFile', LibraryClass.GetIncludeHeader()]]
921 for Item in LibraryClass.GetHelpTextList():
922 Tmp = HelpTextXml()
923 NodeList.append(Tmp.ToXml(Item))
924 Root = CreateXmlElement('%s' % Key, '', NodeList, AttributeList)
925 return Root
926
927 def ToXml2(self, LibraryClass, Key):
928 if self.HeaderFile:
929 pass
930 FeatureFlag = ConvertNEToNOTEQ(LibraryClass.GetFeatureFlag())
931 AttributeList = \
932 [['Usage', LibraryClass.GetUsage()], \
933 ['SupArchList', GetStringOfList(LibraryClass.GetSupArchList())], \
934 ['SupModList', GetStringOfList(LibraryClass.GetSupModuleList())], \
935 ['FeatureFlag', FeatureFlag]
936 ]
937 NodeList = [['Keyword', LibraryClass.GetLibraryClass()], ]
938 for Item in LibraryClass.GetHelpTextList():
939 Tmp = HelpTextXml()
940 NodeList.append(Tmp.ToXml(Item))
941 Root = CreateXmlElement('%s' % Key, '', NodeList, AttributeList)
942 return Root
943
944 def __str__(self):
945 Str = "Keyword = %s HeaderFile = %s RecommendedInstanceGuid = %s RecommendedInstanceVersion = %s %s" % \
946 (self.Keyword, self.HeaderFile, self.RecommendedInstanceGuid, self.RecommendedInstanceVersion, \
947 self.CommonDefines)
948 for Item in self.HelpText:
949 Str = Str + "\n\t" + str(Item)
950 return Str
951
952 ##
953 # FilenameXml
954 #
955 class FilenameXml(object):
956 def __init__(self):
957 self.FileType = ''
958 self.Filename = ''
959 self.CommonDefines = CommonDefinesXml()
960
961 def FromXml(self, Item, Key):
962 self.FileType = XmlAttribute(Item, 'FileType')
963 Guid = XmlAttribute(Item, 'GUID')
964 self.Filename = XmlElement(Item, 'Filename')
965 self.CommonDefines.FromXml(Item, Key)
966 FeatureFlag = ConvertNOTEQToNE(self.CommonDefines.FeatureFlag)
967 Filename = FileNameObject()
968 #
969 # Convert File Type
970 #
971 if self.FileType == 'UEFI_IMAGE':
972 self.FileType = 'PE32'
973
974 Filename.SetGuidValue(Guid)
975 Filename.SetFileType(self.FileType)
976 Filename.SetFilename(self.Filename)
977 Filename.SetSupArchList(self.CommonDefines.SupArchList)
978 Filename.SetFeatureFlag(FeatureFlag)
979
980 return Filename
981
982 def ToXml(self, Filename, Key):
983 if self.Filename:
984 pass
985 AttributeList = [['SupArchList', \
986 GetStringOfList(Filename.GetSupArchList())],
987 ['FileType', Filename.GetFileType()],
988 ['FeatureFlag', ConvertNEToNOTEQ(Filename.GetFeatureFlag())],
989 ['GUID', Filename.GetGuidValue()]
990 ]
991 Root = CreateXmlElement('%s' % Key, Filename.GetFilename(), [], AttributeList)
992
993 return Root
994
995 def __str__(self):
996 return "FileType = %s Filename = %s %s" \
997 % (self.FileType, self.Filename, self.CommonDefines)