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