From 9eb87141eca12b1f15afa4b769af04d1395891c6 Mon Sep 17 00:00:00 2001 From: "Carsey, Jaben" Date: Tue, 17 Apr 2018 22:40:15 +0800 Subject: [PATCH] BaseTools: refactor and remove un-needed use of .keys() on dictionaries sometimes just delete it. sometimes the loop needed .values() instead Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jaben Carsey Reviewed-by: Yonghong Zhu --- BaseTools/Source/Python/AutoGen/AutoGen.py | 32 +++++----- BaseTools/Source/Python/AutoGen/GenMake.py | 24 ++++---- BaseTools/Source/Python/AutoGen/GenVar.py | 2 +- .../Source/Python/AutoGen/InfSectionParser.py | 6 +- BaseTools/Source/Python/BPDG/GenVpd.py | 2 +- .../Source/Python/Common/EdkIIWorkspace.py | 7 +-- BaseTools/Source/Python/Common/Expression.py | 4 +- BaseTools/Source/Python/Common/Misc.py | 2 +- BaseTools/Source/Python/Common/Parsing.py | 15 ++--- BaseTools/Source/Python/Common/String.py | 4 +- BaseTools/Source/Python/Common/VpdInfoFile.py | 8 +-- BaseTools/Source/Python/GenFds/Capsule.py | 8 +-- BaseTools/Source/Python/GenFds/CapsuleData.py | 10 +-- BaseTools/Source/Python/GenFds/Fd.py | 4 +- BaseTools/Source/Python/GenFds/FdfParser.py | 18 +++--- .../Source/Python/GenFds/FfsFileStatement.py | 6 +- .../Source/Python/GenFds/FfsInfStatement.py | 2 +- BaseTools/Source/Python/GenFds/Fv.py | 14 ++--- BaseTools/Source/Python/GenFds/GenFds.py | 61 ++++++++----------- .../Python/GenFds/GenFdsGlobalVariable.py | 4 +- BaseTools/Source/Python/GenFds/Region.py | 12 ++-- .../Source/Python/TargetTool/TargetTool.py | 8 +-- .../Source/Python/Workspace/InfBuildData.py | 5 +- .../Source/Python/Workspace/MetaFileParser.py | 4 +- .../Python/Workspace/WorkspaceCommon.py | 8 +-- BaseTools/Source/Python/build/BuildReport.py | 4 +- BaseTools/Source/Python/build/build.py | 22 +++---- 27 files changed, 137 insertions(+), 159 deletions(-) diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py b/BaseTools/Source/Python/AutoGen/AutoGen.py index bd443fe626..6152225943 100644 --- a/BaseTools/Source/Python/AutoGen/AutoGen.py +++ b/BaseTools/Source/Python/AutoGen/AutoGen.py @@ -762,7 +762,7 @@ class WorkspaceAutoGen(AutoGen): for Module in Pa.ModuleAutoGenList: if path.normpath(Module.MetaFile.File) == path.normpath(FfsFile.InfFileName): InfFoundFlag = True - if not Module.Guid.upper() in _GuidDict.keys(): + if Module.Guid.upper() not in _GuidDict: _GuidDict[Module.Guid.upper()] = FfsFile break else: @@ -789,7 +789,7 @@ class WorkspaceAutoGen(AutoGen): # BuildObject from one of AutoGenObjectList is enough. # InfObj = self.AutoGenObjectList[0].BuildDatabase.WorkspaceDb.BuildObject[PathClassObj, TAB_COMMON, self.BuildTarget, self.ToolChain] - if not InfObj.Guid.upper() in _GuidDict.keys(): + if InfObj.Guid.upper() not in _GuidDict: _GuidDict[InfObj.Guid.upper()] = FfsFile else: EdkLogger.error("build", @@ -837,7 +837,7 @@ class WorkspaceAutoGen(AutoGen): "The format of PCD value is incorrect. PCD: %s , Value: %s\n" % (_PcdName, PcdItem.DefaultValue), ExtraData=self.FdfFile) - if not _PcdGuidString.upper() in _GuidDict.keys(): + if _PcdGuidString.upper() not in _GuidDict: _GuidDict[_PcdGuidString.upper()] = FfsFile PcdFoundFlag = True break @@ -851,7 +851,7 @@ class WorkspaceAutoGen(AutoGen): FfsFile.NameGuid.upper()), ExtraData=self.FdfFile) - if not FfsFile.NameGuid.upper() in _GuidDict.keys(): + if FfsFile.NameGuid.upper() not in _GuidDict: _GuidDict[FfsFile.NameGuid.upper()] = FfsFile else: # @@ -1402,10 +1402,8 @@ class PlatformAutoGen(AutoGen): PcdFromModule.IsFromBinaryInf = True # Check the PCD from DSC or not - if (PcdFromModule.TokenCName, PcdFromModule.TokenSpaceGuidCName) in self.Platform.Pcds.keys(): - PcdFromModule.IsFromDsc = True - else: - PcdFromModule.IsFromDsc = False + PcdFromModule.IsFromDsc = (PcdFromModule.TokenCName, PcdFromModule.TokenSpaceGuidCName) in self.Platform.Pcds + if PcdFromModule.Type in GenC.gDynamicPcd or PcdFromModule.Type in GenC.gDynamicExPcd: if F.Path not in FdfModuleList: # If one of the Source built modules listed in the DSC is not listed @@ -1532,8 +1530,8 @@ class PlatformAutoGen(AutoGen): VpdFile = VpdInfoFile.VpdInfoFile() NeedProcessVpdMapFile = False - for pcd in self.Platform.Pcds.keys(): - if pcd not in self._PlatformPcds.keys(): + for pcd in self.Platform.Pcds: + if pcd not in self._PlatformPcds: self._PlatformPcds[pcd] = self.Platform.Pcds[pcd] for item in self._PlatformPcds: @@ -1543,7 +1541,7 @@ class PlatformAutoGen(AutoGen): if (self.Workspace.ArchList[-1] == self.Arch): for Pcd in self._DynamicPcdList: # just pick the a value to determine whether is unicode string type - Sku = Pcd.SkuInfoList[Pcd.SkuInfoList.keys()[0]] + Sku = Pcd.SkuInfoList.values()[0] Sku.VpdOffset = Sku.VpdOffset.strip() if Pcd.DatumType not in [TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64, TAB_VOID, "BOOLEAN"]: @@ -1630,7 +1628,7 @@ class PlatformAutoGen(AutoGen): if DscPcdEntry.Type in [TAB_PCDS_DYNAMIC_VPD, TAB_PCDS_DYNAMIC_EX_VPD]: if not (self.Platform.VpdToolGuid is None or self.Platform.VpdToolGuid == ''): FoundFlag = False - for VpdPcd in VpdFile._VpdArray.keys(): + for VpdPcd in VpdFile._VpdArray: # This PCD has been referenced by module if (VpdPcd.TokenSpaceGuidCName == DscPcdEntry.TokenSpaceGuidCName) and \ (VpdPcd.TokenCName == DscPcdEntry.TokenCName): @@ -1742,7 +1740,7 @@ class PlatformAutoGen(AutoGen): # Delete the DynamicPcdList At the last time enter into this function for Pcd in self._DynamicPcdList: # just pick the a value to determine whether is unicode string type - Sku = Pcd.SkuInfoList[Pcd.SkuInfoList.keys()[0]] + Sku = Pcd.SkuInfoList.values()[0] Sku.VpdOffset = Sku.VpdOffset.strip() if Pcd.DatumType not in [TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64, TAB_VOID, "BOOLEAN"]: @@ -2482,7 +2480,7 @@ class PlatformAutoGen(AutoGen): for LibraryName in M.Libraries: Library = self.Platform.LibraryClasses[LibraryName, ':dummy:'] if Library is None: - for Key in self.Platform.LibraryClasses.data.keys(): + for Key in self.Platform.LibraryClasses.data: if LibraryName.upper() == Key.upper(): Library = self.Platform.LibraryClasses[Key, ':dummy:'] break @@ -3105,7 +3103,7 @@ class ModuleAutoGen(AutoGen): InfObj = InfSectionParser.InfSectionParser(Filename) DepexExpresionList = InfObj.GetDepexExpresionList() for DepexExpresion in DepexExpresionList: - for key in DepexExpresion.keys(): + for key in DepexExpresion: Arch, ModuleType = key DepexExpr = [x for x in DepexExpresion[key] if not str(x).startswith('#')] # the type of build module is USER_DEFINED. @@ -3123,7 +3121,7 @@ class ModuleAutoGen(AutoGen): #the type of build module is USER_DEFINED. if self.ModuleType.upper() == SUP_MODULE_USER_DEFINED: for Depex in DepexList: - for key in Depex.keys(): + for key in Depex: DepexStr += '[Depex.%s.%s]\n' % key DepexStr += '\n'.join(['# '+ val for val in Depex[key]]) DepexStr += '\n\n' @@ -3233,7 +3231,7 @@ class ModuleAutoGen(AutoGen): InfObj = InfSectionParser.InfSectionParser(Filename) TianoCoreUserExtenList = InfObj.GetUserExtensionTianoCore() for TianoCoreUserExtent in TianoCoreUserExtenList: - for Section in TianoCoreUserExtent.keys(): + for Section in TianoCoreUserExtent: ItemList = Section.split(TAB_SPLIT) Arch = self.Arch if len(ItemList) == 4: diff --git a/BaseTools/Source/Python/AutoGen/GenMake.py b/BaseTools/Source/Python/AutoGen/GenMake.py index b7594d8988..1bb5163e73 100644 --- a/BaseTools/Source/Python/AutoGen/GenMake.py +++ b/BaseTools/Source/Python/AutoGen/GenMake.py @@ -495,11 +495,11 @@ cleanlib: if k not in self._AutoGenObject.Macros: self._AutoGenObject.Macros[k] = v - if 'MODULE_ENTRY_POINT' not in self._AutoGenObject.Macros.keys(): + if 'MODULE_ENTRY_POINT' not in self._AutoGenObject.Macros: self._AutoGenObject.Macros['MODULE_ENTRY_POINT'] = ModuleEntryPoint - if 'ARCH_ENTRY_POINT' not in self._AutoGenObject.Macros.keys(): + if 'ARCH_ENTRY_POINT' not in self._AutoGenObject.Macros: self._AutoGenObject.Macros['ARCH_ENTRY_POINT'] = ArchEntryPoint - if 'IMAGE_ENTRY_POINT' not in self._AutoGenObject.Macros.keys(): + if 'IMAGE_ENTRY_POINT' not in self._AutoGenObject.Macros: self._AutoGenObject.Macros['IMAGE_ENTRY_POINT'] = ImageEntryPoint PCI_COMPRESS_Flag = False @@ -540,7 +540,7 @@ cleanlib: RespFileList = os.path.join(self._AutoGenObject.OutputDir, 'respfilelist.txt') if RespDict: RespFileListContent = '' - for Resp in RespDict.keys(): + for Resp in RespDict: RespFile = os.path.join(self._AutoGenObject.OutputDir, str(Resp).lower() + '.txt') StrList = RespDict[Resp].split(' ') UnexpandMacro = [] @@ -794,7 +794,7 @@ cleanlib: SingleCommandLength = len(SingleCommand) SingleCommandList = SingleCommand.split() if len(SingleCommandList) > 0: - for Flag in FlagDict.keys(): + for Flag in FlagDict: if '$('+ Flag +')' in SingleCommandList[0]: Tool = Flag break @@ -807,12 +807,12 @@ cleanlib: if 'FLAGS' not in self._AutoGenObject._BuildOption[Tool]: EdkLogger.error("build", AUTOGEN_ERROR, "%s_FLAGS doesn't exist in %s ToolChain and %s Arch." %(Tool, self._AutoGenObject.ToolChain, self._AutoGenObject.Arch), ExtraData="[%s]" % str(self._AutoGenObject)) Str = self._AutoGenObject._BuildOption[Tool]['FLAGS'] - for Option in self._AutoGenObject.BuildOption.keys(): + for Option in self._AutoGenObject.BuildOption: for Attr in self._AutoGenObject.BuildOption[Option]: if Str.find(Option + '_' + Attr) != -1: Str = Str.replace('$(' + Option + '_' + Attr + ')', self._AutoGenObject.BuildOption[Option][Attr]) while(Str.find('$(') != -1): - for macro in self._AutoGenObject.Macros.keys(): + for macro in self._AutoGenObject.Macros: MacroName = '$('+ macro + ')' if (Str.find(MacroName) != -1): Str = Str.replace(MacroName, self._AutoGenObject.Macros[macro]) @@ -824,12 +824,12 @@ cleanlib: SingleCommandLength += self._AutoGenObject.IncludePathLength + len(IncPrefix) * len(self._AutoGenObject._IncludePathList) elif item.find('$(') != -1: Str = item - for Option in self._AutoGenObject.BuildOption.keys(): + for Option in self._AutoGenObject.BuildOption: for Attr in self._AutoGenObject.BuildOption[Option]: if Str.find(Option + '_' + Attr) != -1: Str = Str.replace('$(' + Option + '_' + Attr + ')', self._AutoGenObject.BuildOption[Option][Attr]) while(Str.find('$(') != -1): - for macro in self._AutoGenObject.Macros.keys(): + for macro in self._AutoGenObject.Macros: MacroName = '$('+ macro + ')' if (Str.find(MacroName) != -1): Str = Str.replace(MacroName, self._AutoGenObject.Macros[macro]) @@ -842,19 +842,19 @@ cleanlib: FlagDict[Tool]['Value'] = True # generate the response file content by combine the FLAGS and INC - for Flag in FlagDict.keys(): + for Flag in FlagDict: if FlagDict[Flag]['Value']: Key = Flag + '_RESP' RespMacro = FlagDict[Flag]['Macro'].replace('FLAGS', 'RESP') Value = self._AutoGenObject.BuildOption[Flag]['FLAGS'] for inc in self._AutoGenObject._IncludePathList: Value += ' ' + IncPrefix + inc - for Option in self._AutoGenObject.BuildOption.keys(): + for Option in self._AutoGenObject.BuildOption: for Attr in self._AutoGenObject.BuildOption[Option]: if Value.find(Option + '_' + Attr) != -1: Value = Value.replace('$(' + Option + '_' + Attr + ')', self._AutoGenObject.BuildOption[Option][Attr]) while (Value.find('$(') != -1): - for macro in self._AutoGenObject.Macros.keys(): + for macro in self._AutoGenObject.Macros: MacroName = '$('+ macro + ')' if (Value.find(MacroName) != -1): Value = Value.replace(MacroName, self._AutoGenObject.Macros[macro]) diff --git a/BaseTools/Source/Python/AutoGen/GenVar.py b/BaseTools/Source/Python/AutoGen/GenVar.py index 1c66a9eb05..37c168a84b 100644 --- a/BaseTools/Source/Python/AutoGen/GenVar.py +++ b/BaseTools/Source/Python/AutoGen/GenVar.py @@ -114,8 +114,8 @@ class VariableMgr(object): self.VarInfo = [item[0] for item in indexedvarinfo.values()] def assemble_variable(self, valuelist): - ordered_value = [valuelist[k] for k in sorted(valuelist.keys())] ordered_offset = sorted(valuelist.keys()) + ordered_value = [valuelist[k] for k in ordered_offset] var_value = [] num = 0 for offset in ordered_offset: diff --git a/BaseTools/Source/Python/AutoGen/InfSectionParser.py b/BaseTools/Source/Python/AutoGen/InfSectionParser.py index cdc9e5e8a8..cf4e76159e 100644 --- a/BaseTools/Source/Python/AutoGen/InfSectionParser.py +++ b/BaseTools/Source/Python/AutoGen/InfSectionParser.py @@ -1,7 +1,7 @@ ## @file # Parser a Inf file and Get specify section data. # -# Copyright (c) 2007 - 2012, Intel Corporation. All rights reserved.
+# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.
# This program and the accompanying materials # are licensed and made available under the terms and conditions of the BSD License # which accompanies this distribution. The full text of the license may be found at @@ -70,7 +70,7 @@ class InfSectionParser(): if not self._FileSectionDataList: return UserExtensionTianoCore for SectionDataDict in self._FileSectionDataList: - for key in SectionDataDict.keys(): + for key in SectionDataDict: if key.lower().startswith("[userextensions") and key.lower().find('.tianocore.') > -1: SectionLine = key.lstrip(TAB_SECTION_START).rstrip(TAB_SECTION_END) SubSectionList = [SectionLine] @@ -89,7 +89,7 @@ class InfSectionParser(): if not self._FileSectionDataList: return DepexExpresionList for SectionDataDict in self._FileSectionDataList: - for key in SectionDataDict.keys(): + for key in SectionDataDict: if key.lower() == "[depex]" or key.lower().startswith("[depex."): SectionLine = key.lstrip(TAB_SECTION_START).rstrip(TAB_SECTION_END) SubSectionList = [SectionLine] diff --git a/BaseTools/Source/Python/BPDG/GenVpd.py b/BaseTools/Source/Python/BPDG/GenVpd.py index 887240e94c..69a9665f5a 100644 --- a/BaseTools/Source/Python/BPDG/GenVpd.py +++ b/BaseTools/Source/Python/BPDG/GenVpd.py @@ -120,7 +120,7 @@ class PcdEntry: # # def _PackIntValue(self, IntValue, Size): - if Size not in _FORMAT_CHAR.keys(): + if Size not in _FORMAT_CHAR: EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, "Invalid size %d for PCD %s in integer datum size(File: %s Line: %s)." % (Size, self.PcdCName, self.FileName, self.Lineno)) diff --git a/BaseTools/Source/Python/Common/EdkIIWorkspace.py b/BaseTools/Source/Python/Common/EdkIIWorkspace.py index c14b4eb52d..d75b9f8025 100644 --- a/BaseTools/Source/Python/Common/EdkIIWorkspace.py +++ b/BaseTools/Source/Python/Common/EdkIIWorkspace.py @@ -1,7 +1,7 @@ ## @file # This is the base class for applications that operate on an EDK II Workspace # -# Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.
+# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.
# This program and the accompanying materials # are licensed and made available under the terms and conditions of the BSD License # which accompanies this distribution. The full text of the license may be found at @@ -259,10 +259,7 @@ def ConvertDictionaryToTextFile(FileName, Dictionary, CommentCharacter, KeySplit except: Lines = [] Keys = Dictionary.keys() - MaxLength = 0 - for Key in Keys: - if len(Key) > MaxLength: - MaxLength = len(Key) + MaxLength = max(map(len,Keys)) Index = 0 for Line in Lines: LineList = Line.split(KeySplitCharacter, 1) diff --git a/BaseTools/Source/Python/Common/Expression.py b/BaseTools/Source/Python/Common/Expression.py index 462e8f93f8..9a3415ccaa 100644 --- a/BaseTools/Source/Python/Common/Expression.py +++ b/BaseTools/Source/Python/Common/Expression.py @@ -151,7 +151,7 @@ def ReplaceExprMacro(String, Macros, ExceptionList = None): InQuote = True MacroStartPos = String.find('$(') if MacroStartPos < 0: - for Pcd in gPlatformPcds.keys(): + for Pcd in gPlatformPcds: if Pcd in String: if Pcd not in gConditionalPcds: gConditionalPcds.append(Pcd) @@ -908,7 +908,7 @@ class ValueExpressionEx(ValueExpression): for Label in LabelList: if not IsValidCName(Label): raise BadExpression('%s is not a valid c variable name' % Label) - if Label not in LabelDict.keys(): + if Label not in LabelDict: LabelDict[Label] = str(LabelOffset) if Item.startswith('UINT8'): LabelOffset = LabelOffset + 1 diff --git a/BaseTools/Source/Python/Common/Misc.py b/BaseTools/Source/Python/Common/Misc.py index 5ffd8cd022..4f2bfd63cf 100644 --- a/BaseTools/Source/Python/Common/Misc.py +++ b/BaseTools/Source/Python/Common/Misc.py @@ -1918,7 +1918,7 @@ class DefaultStore(): if not self.DefaultStores or "0" in self.DefaultStores: return "0",TAB_DEFAULT_STORES_DEFAULT else: - minvalue = min([int(value_str) for value_str in self.DefaultStores.keys()]) + minvalue = min([int(value_str) for value_str in self.DefaultStores]) return (str(minvalue), self.DefaultStores[str(minvalue)]) def GetMin(self,DefaultSIdList): if not DefaultSIdList: diff --git a/BaseTools/Source/Python/Common/Parsing.py b/BaseTools/Source/Python/Common/Parsing.py index d199d1e40d..453c2039e3 100644 --- a/BaseTools/Source/Python/Common/Parsing.py +++ b/BaseTools/Source/Python/Common/Parsing.py @@ -1,7 +1,7 @@ ## @file # This file is used to define common parsing related functions used in parsing INF/DEC/DSC process # -# Copyright (c) 2008 - 2014, Intel Corporation. All rights reserved.
+# Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.
# This program and the accompanying materials # are licensed and made available under the terms and conditions of the BSD License # which accompanies this distribution. The full text of the license may be found at @@ -37,16 +37,14 @@ def ParseDefineMacro2(Table, RecordSets, GlobalMacro): # # Overrided by Global Macros # - for Key in GlobalMacro.keys(): - Macros[Key] = GlobalMacro[Key] + Macros.update(GlobalMacro) # # Replace the Macros # - for Key in RecordSets.keys(): - if RecordSets[Key] != []: - for Item in RecordSets[Key]: - Item[0] = ReplaceMacro(Item[0], Macros) + for Value in (v for v in RecordSets.values() if v): + for Item in Value: + Item[0] = ReplaceMacro(Item[0], Macros) ## ParseDefineMacro # @@ -79,8 +77,7 @@ def ParseDefineMacro(Table, GlobalMacro): # # Overrided by Global Macros # - for Key in GlobalMacro.keys(): - Macros[Key] = GlobalMacro[Key] + Macros.update(GlobalMacro) # # Found all defined macro and replaced diff --git a/BaseTools/Source/Python/Common/String.py b/BaseTools/Source/Python/Common/String.py index 5dc5b85dc5..ee26d7f7b1 100644 --- a/BaseTools/Source/Python/Common/String.py +++ b/BaseTools/Source/Python/Common/String.py @@ -1,7 +1,7 @@ ## @file # This file is used to define common string related functions used in parsing process # -# Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.
+# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.
# This program and the accompanying materials # are licensed and made available under the terms and conditions of the BSD License # which accompanies this distribution. The full text of the license may be found at @@ -110,7 +110,7 @@ def GetSplitList(String, SplitStr=DataType.TAB_VALUE_SPLIT, MaxSplit= -1): # @param Arch: The Arch to be added or merged # def MergeArches(Dict, Key, Arch): - if Key in Dict.keys(): + if Key in Dict: Dict[Key].append(Arch) else: Dict[Key] = Arch.split() diff --git a/BaseTools/Source/Python/Common/VpdInfoFile.py b/BaseTools/Source/Python/Common/VpdInfoFile.py index b1baf06b9c..5559a88b97 100644 --- a/BaseTools/Source/Python/Common/VpdInfoFile.py +++ b/BaseTools/Source/Python/Common/VpdInfoFile.py @@ -6,7 +6,7 @@ # is pointed by *_*_*_VPD_TOOL_GUID in conf/tools_def.txt # # -# Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.
+# Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.
# This program and the accompanying materials # are licensed and made available under the terms and conditions of the BSD License # which accompanies this distribution. The full text of the license may be found at @@ -107,7 +107,7 @@ class VpdInfoFile: EdkLogger.error("VpdInfoFile", BuildToolError.PARAMETER_INVALID, "Invalid max datum size for VPD PCD %s.%s" % (Vpd.TokenSpaceGuidCName, Vpd.TokenCName)) - if Vpd not in self._VpdArray.keys(): + if Vpd not in self._VpdArray: # # If there is no Vpd instance in dict, that imply this offset for a given SKU is a new one # @@ -180,12 +180,12 @@ class VpdInfoFile: if (TokenSpaceName, PcdTokenName) not in self._VpdInfo: self._VpdInfo[(TokenSpaceName, PcdTokenName)] = [] self._VpdInfo[(TokenSpaceName, PcdTokenName)].append((SkuId,Offset, Value)) - for VpdObject in self._VpdArray.keys(): + for VpdObject in self._VpdArray: VpdObjectTokenCName = VpdObject.TokenCName for PcdItem in GlobalData.MixedPcd: if (VpdObject.TokenCName, VpdObject.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]: VpdObjectTokenCName = PcdItem[0] - for sku in VpdObject.SkuInfoList.keys(): + for sku in VpdObject.SkuInfoList: if VpdObject.TokenSpaceGuidCName == TokenSpaceName and VpdObjectTokenCName == PcdTokenName.strip() and sku == SkuId: if self._VpdArray[VpdObject][sku] == "*": if Offset == "*": diff --git a/BaseTools/Source/Python/GenFds/Capsule.py b/BaseTools/Source/Python/GenFds/Capsule.py index 9332f016f7..fbd48f3c6d 100644 --- a/BaseTools/Source/Python/GenFds/Capsule.py +++ b/BaseTools/Source/Python/GenFds/Capsule.py @@ -1,7 +1,7 @@ ## @file # generate capsule # -# Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.
+# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.
# # This program and the accompanying materials # are licensed and made available under the terms and conditions of the BSD License @@ -201,7 +201,7 @@ class Capsule (CapsuleClassObject) : # @retval string Generated Capsule file path # def GenCapsule(self): - if self.UiCapsuleName.upper() + 'cap' in GenFds.ImageBinDict.keys(): + if self.UiCapsuleName.upper() + 'cap' in GenFds.ImageBinDict: return GenFds.ImageBinDict[self.UiCapsuleName.upper() + 'cap'] GenFdsGlobalVariable.InfLogger( "\nGenerate %s Capsule" %self.UiCapsuleName) @@ -251,11 +251,11 @@ class Capsule (CapsuleClassObject) : CapInfFile.writelines("[options]" + T_CHAR_LF) - for Item in self.TokensDict.keys(): + for Item in self.TokensDict: CapInfFile.writelines("EFI_" + \ Item + \ ' = ' + \ - self.TokensDict.get(Item) + \ + self.TokensDict[Item] + \ T_CHAR_LF) return CapInfFile diff --git a/BaseTools/Source/Python/GenFds/CapsuleData.py b/BaseTools/Source/Python/GenFds/CapsuleData.py index 5b806d9e44..b376d6b2e9 100644 --- a/BaseTools/Source/Python/GenFds/CapsuleData.py +++ b/BaseTools/Source/Python/GenFds/CapsuleData.py @@ -1,7 +1,7 @@ ## @file # generate capsule # -# Copyright (c) 2007-2017, Intel Corporation. All rights reserved.
+# Copyright (c) 2007-2018, Intel Corporation. All rights reserved.
# # This program and the accompanying materials # are licensed and made available under the terms and conditions of the BSD License @@ -80,8 +80,8 @@ class CapsuleFv (CapsuleData): # def GenCapsuleSubItem(self): if self.FvName.find('.fv') == -1: - if self.FvName.upper() in GenFdsGlobalVariable.FdfParser.Profile.FvDict.keys(): - FvObj = GenFdsGlobalVariable.FdfParser.Profile.FvDict.get(self.FvName.upper()) + if self.FvName.upper() in GenFdsGlobalVariable.FdfParser.Profile.FvDict: + FvObj = GenFdsGlobalVariable.FdfParser.Profile.FvDict[self.FvName.upper()] FdBuffer = StringIO.StringIO('') FvObj.CapsuleName = self.CapsuleName FvFile = FvObj.AddToBuffer(FdBuffer) @@ -112,8 +112,8 @@ class CapsuleFd (CapsuleData): # def GenCapsuleSubItem(self): if self.FdName.find('.fd') == -1: - if self.FdName.upper() in GenFdsGlobalVariable.FdfParser.Profile.FdDict.keys(): - FdObj = GenFdsGlobalVariable.FdfParser.Profile.FdDict.get(self.FdName.upper()) + if self.FdName.upper() in GenFdsGlobalVariable.FdfParser.Profile.FdDict: + FdObj = GenFdsGlobalVariable.FdfParser.Profile.FdDict[self.FdName.upper()] FdFile = FdObj.GenFd() return FdFile else: diff --git a/BaseTools/Source/Python/GenFds/Fd.py b/BaseTools/Source/Python/GenFds/Fd.py index f735d3b5b0..cc4124ad90 100644 --- a/BaseTools/Source/Python/GenFds/Fd.py +++ b/BaseTools/Source/Python/GenFds/Fd.py @@ -1,7 +1,7 @@ ## @file # process FD generation # -# Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.
+# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.
# # This program and the accompanying materials # are licensed and made available under the terms and conditions of the BSD License @@ -46,7 +46,7 @@ class FD(FDClassObject): # @retval string Generated FD file name # def GenFd (self, Flag = False): - if self.FdUiName.upper() + 'fd' in GenFds.ImageBinDict.keys(): + if self.FdUiName.upper() + 'fd' in GenFds.ImageBinDict: return GenFds.ImageBinDict[self.FdUiName.upper() + 'fd'] # diff --git a/BaseTools/Source/Python/GenFds/FdfParser.py b/BaseTools/Source/Python/GenFds/FdfParser.py index bff1d47393..a106253527 100644 --- a/BaseTools/Source/Python/GenFds/FdfParser.py +++ b/BaseTools/Source/Python/GenFds/FdfParser.py @@ -3402,7 +3402,7 @@ class FdfParser: if not self.__GetNextToken(): raise Warning("expected FV name", self.FileName, self.CurrentLineNumber) - if self.__Token.upper() not in self.Profile.FvDict.keys(): + if self.__Token.upper() not in self.Profile.FvDict: raise Warning("FV name does not exist", self.FileName, self.CurrentLineNumber) CapsuleFv = CapsuleData.CapsuleFv() @@ -3436,7 +3436,7 @@ class FdfParser: if not self.__GetNextToken(): raise Warning("expected FD name", self.FileName, self.CurrentLineNumber) - if self.__Token.upper() not in self.Profile.FdDict.keys(): + if self.__Token.upper() not in self.Profile.FdDict: raise Warning("FD name does not exist", self.FileName, self.CurrentLineNumber) CapsuleFd = CapsuleData.CapsuleFd() @@ -4532,7 +4532,7 @@ class FdfParser: def __GetCapInFd (self, FdName): CapList = [] - if FdName.upper() in self.Profile.FdDict.keys(): + if FdName.upper() in self.Profile.FdDict: FdObj = self.Profile.FdDict[FdName.upper()] for elementRegion in FdObj.RegionList: if elementRegion.RegionType == 'CAPSULE': @@ -4579,7 +4579,7 @@ class FdfParser: def __GetFvInFd (self, FdName): FvList = [] - if FdName.upper() in self.Profile.FdDict.keys(): + if FdName.upper() in self.Profile.FdDict: FdObj = self.Profile.FdDict[FdName.upper()] for elementRegion in FdObj.RegionList: if elementRegion.RegionType == 'FV': @@ -4648,7 +4648,7 @@ class FdfParser: # Check the cycle between FV and FD image # MaxLength = len (self.Profile.FvDict) - for FvName in self.Profile.FvDict.keys(): + for FvName in self.Profile.FvDict: LogStr = "\nCycle Reference Checking for FV: %s\n" % FvName RefFvStack = [] RefFvStack.append(FvName) @@ -4658,7 +4658,7 @@ class FdfParser: while RefFvStack != [] and Index < MaxLength: Index = Index + 1 FvNameFromStack = RefFvStack.pop() - if FvNameFromStack.upper() in self.Profile.FvDict.keys(): + if FvNameFromStack.upper() in self.Profile.FvDict: FvObj = self.Profile.FvDict[FvNameFromStack.upper()] else: continue @@ -4697,7 +4697,7 @@ class FdfParser: # Check the cycle between Capsule and FD image # MaxLength = len (self.Profile.CapsuleDict) - for CapName in self.Profile.CapsuleDict.keys(): + for CapName in self.Profile.CapsuleDict: # # Capsule image to be checked. # @@ -4711,7 +4711,7 @@ class FdfParser: while RefCapStack != [] and Index < MaxLength: Index = Index + 1 CapNameFromStack = RefCapStack.pop() - if CapNameFromStack.upper() in self.Profile.CapsuleDict.keys(): + if CapNameFromStack.upper() in self.Profile.CapsuleDict: CapObj = self.Profile.CapsuleDict[CapNameFromStack.upper()] else: continue @@ -4756,7 +4756,7 @@ class FdfParser: if RefFvName in FvAnalyzedList: continue LogStr += "Capsule %s contains FV %s\n" % (CapNameFromStack, RefFvName) - if RefFvName.upper() in self.Profile.FvDict.keys(): + if RefFvName.upper() in self.Profile.FvDict: FvObj = self.Profile.FvDict[RefFvName.upper()] else: continue diff --git a/BaseTools/Source/Python/GenFds/FfsFileStatement.py b/BaseTools/Source/Python/GenFds/FfsFileStatement.py index 3fd5a9c215..ba8e0465ef 100644 --- a/BaseTools/Source/Python/GenFds/FfsFileStatement.py +++ b/BaseTools/Source/Python/GenFds/FfsFileStatement.py @@ -1,7 +1,7 @@ ## @file # process FFS generation from FILE statement # -# Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.
+# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.
# # This program and the accompanying materials # are licensed and made available under the terms and conditions of the BSD License @@ -83,14 +83,14 @@ class FileStatement (FileStatementClassObject) : SectionAlignments = None if self.FvName is not None : Buffer = StringIO.StringIO('') - if self.FvName.upper() not in GenFdsGlobalVariable.FdfParser.Profile.FvDict.keys(): + if self.FvName.upper() not in GenFdsGlobalVariable.FdfParser.Profile.FvDict: EdkLogger.error("GenFds", GENFDS_ERROR, "FV (%s) is NOT described in FDF file!" % (self.FvName)) Fv = GenFdsGlobalVariable.FdfParser.Profile.FvDict.get(self.FvName.upper()) FileName = Fv.AddToBuffer(Buffer) SectionFiles = [FileName] elif self.FdName is not None: - if self.FdName.upper() not in GenFdsGlobalVariable.FdfParser.Profile.FdDict.keys(): + if self.FdName.upper() not in GenFdsGlobalVariable.FdfParser.Profile.FdDict: EdkLogger.error("GenFds", GENFDS_ERROR, "FD (%s) is NOT described in FDF file!" % (self.FdName)) Fd = GenFdsGlobalVariable.FdfParser.Profile.FdDict.get(self.FdName.upper()) FileName = Fd.GenFd() diff --git a/BaseTools/Source/Python/GenFds/FfsInfStatement.py b/BaseTools/Source/Python/GenFds/FfsInfStatement.py index 8f5a1bfd10..887619694d 100644 --- a/BaseTools/Source/Python/GenFds/FfsInfStatement.py +++ b/BaseTools/Source/Python/GenFds/FfsInfStatement.py @@ -613,7 +613,7 @@ class FfsInfStatement(FfsInfStatementClassObject): # the file name FILE_GUIDmodule.inf, then PlatformDataBase.Modules use FILE_GUIDmodule.inf as key, # but the path (self.MetaFile.Path) is the real path # - for key in PlatformDataBase.Modules.keys(): + for key in PlatformDataBase.Modules: if InfFileKey == str((PlatformDataBase.Modules[key]).MetaFile.Path): DscArchList.append (Arch) break diff --git a/BaseTools/Source/Python/GenFds/Fv.py b/BaseTools/Source/Python/GenFds/Fv.py index aae644bef9..5228e15526 100644 --- a/BaseTools/Source/Python/GenFds/Fv.py +++ b/BaseTools/Source/Python/GenFds/Fv.py @@ -70,7 +70,7 @@ class FV (FvClassObject): # def AddToBuffer (self, Buffer, BaseAddress=None, BlockSize= None, BlockNum=None, ErasePloarity='1', VtfDict=None, MacroDict = {}, Flag=False) : - if BaseAddress is None and self.UiFvName.upper() + 'fv' in GenFds.ImageBinDict.keys(): + if BaseAddress is None and self.UiFvName.upper() + 'fv' in GenFds.ImageBinDict: return GenFds.ImageBinDict[self.UiFvName.upper() + 'fv'] # @@ -78,14 +78,13 @@ class FV (FvClassObject): # If yes, return error. Doesn't support FV in Capsule image is also in FD flash region. # if self.CapsuleName is not None: - for FdName in GenFdsGlobalVariable.FdfParser.Profile.FdDict.keys(): - FdObj = GenFdsGlobalVariable.FdfParser.Profile.FdDict[FdName] + for FdObj in GenFdsGlobalVariable.FdfParser.Profile.FdDict.values(): for RegionObj in FdObj.RegionList: if RegionObj.RegionType == 'FV': for RegionData in RegionObj.RegionDataList: if RegionData.endswith(".fv"): continue - elif RegionData.upper() + 'fv' in GenFds.ImageBinDict.keys(): + elif RegionData.upper() + 'fv' in GenFds.ImageBinDict: continue elif self.UiFvName.upper() == RegionData.upper(): GenFdsGlobalVariable.ErrorLogger("Capsule %s in FD region can't contain a FV %s in FD region." % (self.CapsuleName, self.UiFvName.upper())) @@ -235,8 +234,7 @@ class FV (FvClassObject): if self.BlockSizeList: return True - for FdName in GenFdsGlobalVariable.FdfParser.Profile.FdDict.keys(): - FdObj = GenFdsGlobalVariable.FdfParser.Profile.FdDict[FdName] + for FdObj in GenFdsGlobalVariable.FdfParser.Profile.FdDict.values(): for RegionObj in FdObj.RegionList: if RegionObj.RegionType != 'FV': continue @@ -441,7 +439,7 @@ class FV (FvClassObject): # Add [Files] # self.FvInfFile.writelines("[files]" + T_CHAR_LF) - if VtfDict is not None and self.UiFvName in VtfDict.keys(): + if VtfDict is not None and self.UiFvName in VtfDict: self.FvInfFile.writelines("EFI_FILE_NAME = " + \ - VtfDict.get(self.UiFvName) + \ + VtfDict[self.UiFvName] + \ T_CHAR_LF) diff --git a/BaseTools/Source/Python/GenFds/GenFds.py b/BaseTools/Source/Python/GenFds/GenFds.py index c507b0148a..54c7d82830 100644 --- a/BaseTools/Source/Python/GenFds/GenFds.py +++ b/BaseTools/Source/Python/GenFds/GenFds.py @@ -92,7 +92,7 @@ def main(): else: Workspace = os.path.normcase(Options.Workspace) GenFdsGlobalVariable.WorkSpaceDir = Workspace - if 'EDK_SOURCE' in os.environ.keys(): + if 'EDK_SOURCE' in os.environ: GenFdsGlobalVariable.EdkSourceDir = os.path.normcase(os.environ['EDK_SOURCE']) if (Options.debug): GenFdsGlobalVariable.VerboseLogger("Using Workspace:" + Workspace) @@ -156,7 +156,7 @@ def main(): # This also handles someone specifying the Conf directory in the workspace. Using --conf=Conf ConfDirectoryPath = os.path.join(GenFdsGlobalVariable.WorkSpaceDir, ConfDirectoryPath) else: - if "CONF_PATH" in os.environ.keys(): + if "CONF_PATH" in os.environ: ConfDirectoryPath = os.path.normcase(os.environ["CONF_PATH"]) else: # Get standard WORKSPACE/Conf, use the absolute path to the WORKSPACE/Conf @@ -216,11 +216,11 @@ def main(): os.environ["WORKSPACE"] = Workspace # Use the -t and -b option as gGlobalDefines's TOOLCHAIN and TARGET if they are not defined - if "TARGET" not in GlobalData.gGlobalDefines.keys(): + if "TARGET" not in GlobalData.gGlobalDefines: GlobalData.gGlobalDefines["TARGET"] = GenFdsGlobalVariable.TargetName - if "TOOLCHAIN" not in GlobalData.gGlobalDefines.keys(): + if "TOOLCHAIN" not in GlobalData.gGlobalDefines: GlobalData.gGlobalDefines["TOOLCHAIN"] = GenFdsGlobalVariable.ToolChainTag - if "TOOL_CHAIN_TAG" not in GlobalData.gGlobalDefines.keys(): + if "TOOL_CHAIN_TAG" not in GlobalData.gGlobalDefines: GlobalData.gGlobalDefines['TOOL_CHAIN_TAG'] = GenFdsGlobalVariable.ToolChainTag """call Workspace build create database""" @@ -278,21 +278,21 @@ def main(): EdkLogger.error("GenFds", FORMAT_NOT_SUPPORTED, "Cycle Reference Detected in FDF file") if (Options.uiFdName) : - if Options.uiFdName.upper() in FdfParserObj.Profile.FdDict.keys(): + if Options.uiFdName.upper() in FdfParserObj.Profile.FdDict: GenFds.OnlyGenerateThisFd = Options.uiFdName else: EdkLogger.error("GenFds", OPTION_VALUE_INVALID, "No such an FD in FDF file: %s" % Options.uiFdName) if (Options.uiFvName) : - if Options.uiFvName.upper() in FdfParserObj.Profile.FvDict.keys(): + if Options.uiFvName.upper() in FdfParserObj.Profile.FvDict: GenFds.OnlyGenerateThisFv = Options.uiFvName else: EdkLogger.error("GenFds", OPTION_VALUE_INVALID, "No such an FV in FDF file: %s" % Options.uiFvName) if (Options.uiCapName) : - if Options.uiCapName.upper() in FdfParserObj.Profile.CapsuleDict.keys(): + if Options.uiCapName.upper() in FdfParserObj.Profile.CapsuleDict: GenFds.OnlyGenerateThisCap = Options.uiCapName else: EdkLogger.error("GenFds", OPTION_VALUE_INVALID, @@ -388,7 +388,7 @@ def FindExtendTool(KeyStringList, CurrentArchList, NameGuid): KeyStringList.append(Target + '_' + ToolChain + '_' + Arch) if GenFdsGlobalVariable.GuidToolDefinition: - if NameGuid in GenFdsGlobalVariable.GuidToolDefinition.keys(): + if NameGuid in GenFdsGlobalVariable.GuidToolDefinition: return GenFdsGlobalVariable.GuidToolDefinition[NameGuid] ToolDefinition = ToolDefClassObject.ToolDefDict(GenFdsGlobalVariable.ConfDir).ToolsDefTxtDictionary @@ -450,10 +450,10 @@ def FindExtendTool(KeyStringList, CurrentArchList, NameGuid): if Key in KeyStringList and KeyList[4] == 'GUID': ToolPathKey = Key + '_' + KeyList[3] + '_PATH' ToolOptionKey = Key + '_' + KeyList[3] + '_FLAGS' - if ToolPathKey in BuildOption.keys(): - ToolPathTmp = BuildOption.get(ToolPathKey) - if ToolOptionKey in BuildOption.keys(): - ToolOption = BuildOption.get(ToolOptionKey) + if ToolPathKey in BuildOption: + ToolPathTmp = BuildOption[ToolPathKey] + if ToolOptionKey in BuildOption: + ToolOption = BuildOption[ToolOptionKey] GenFdsGlobalVariable.GuidToolDefinition[NameGuid] = (ToolPathTmp, ToolOption) return ToolPathTmp, ToolOption @@ -522,63 +522,56 @@ class GenFds : GenFdsGlobalVariable.SetDir ('', FdfParser, WorkSpace, ArchList) GenFdsGlobalVariable.VerboseLogger(" Generate all Fd images and their required FV and Capsule images!") - if GenFds.OnlyGenerateThisCap is not None and GenFds.OnlyGenerateThisCap.upper() in GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict.keys(): - CapsuleObj = GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict.get(GenFds.OnlyGenerateThisCap.upper()) + if GenFds.OnlyGenerateThisCap is not None and GenFds.OnlyGenerateThisCap.upper() in GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict: + CapsuleObj = GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict[GenFds.OnlyGenerateThisCap.upper()] if CapsuleObj is not None: CapsuleObj.GenCapsule() return - if GenFds.OnlyGenerateThisFd is not None and GenFds.OnlyGenerateThisFd.upper() in GenFdsGlobalVariable.FdfParser.Profile.FdDict.keys(): - FdObj = GenFdsGlobalVariable.FdfParser.Profile.FdDict.get(GenFds.OnlyGenerateThisFd.upper()) + if GenFds.OnlyGenerateThisFd is not None and GenFds.OnlyGenerateThisFd.upper() in GenFdsGlobalVariable.FdfParser.Profile.FdDict: + FdObj = GenFdsGlobalVariable.FdfParser.Profile.FdDict[GenFds.OnlyGenerateThisFd.upper()] if FdObj is not None: FdObj.GenFd() return elif GenFds.OnlyGenerateThisFd is None and GenFds.OnlyGenerateThisFv is None: - for FdName in GenFdsGlobalVariable.FdfParser.Profile.FdDict.keys(): - FdObj = GenFdsGlobalVariable.FdfParser.Profile.FdDict[FdName] + for FdObj in GenFdsGlobalVariable.FdfParser.Profile.FdDict.values(): FdObj.GenFd() GenFdsGlobalVariable.VerboseLogger("\n Generate other FV images! ") - if GenFds.OnlyGenerateThisFv is not None and GenFds.OnlyGenerateThisFv.upper() in GenFdsGlobalVariable.FdfParser.Profile.FvDict.keys(): - FvObj = GenFdsGlobalVariable.FdfParser.Profile.FvDict.get(GenFds.OnlyGenerateThisFv.upper()) + if GenFds.OnlyGenerateThisFv is not None and GenFds.OnlyGenerateThisFv.upper() in GenFdsGlobalVariable.FdfParser.Profile.FvDict: + FvObj = GenFdsGlobalVariable.FdfParser.Profile.FvDict[GenFds.OnlyGenerateThisFv.upper()] if FvObj is not None: Buffer = StringIO.StringIO() FvObj.AddToBuffer(Buffer) Buffer.close() return elif GenFds.OnlyGenerateThisFv is None: - for FvName in GenFdsGlobalVariable.FdfParser.Profile.FvDict.keys(): + for FvObj in GenFdsGlobalVariable.FdfParser.Profile.FvDict.values(): Buffer = StringIO.StringIO('') - FvObj = GenFdsGlobalVariable.FdfParser.Profile.FvDict[FvName] FvObj.AddToBuffer(Buffer) Buffer.close() if GenFds.OnlyGenerateThisFv is None and GenFds.OnlyGenerateThisFd is None and GenFds.OnlyGenerateThisCap is None: if GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict != {}: GenFdsGlobalVariable.VerboseLogger("\n Generate other Capsule images!") - for CapsuleName in GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict.keys(): - CapsuleObj = GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict[CapsuleName] + for CapsuleObj in GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict.values(): CapsuleObj.GenCapsule() if GenFdsGlobalVariable.FdfParser.Profile.OptRomDict != {}: GenFdsGlobalVariable.VerboseLogger("\n Generate all Option ROM!") - for DriverName in GenFdsGlobalVariable.FdfParser.Profile.OptRomDict.keys(): - OptRomObj = GenFdsGlobalVariable.FdfParser.Profile.OptRomDict[DriverName] + for OptRomObj in GenFdsGlobalVariable.FdfParser.Profile.OptRomDict.values(): OptRomObj.AddToBuffer(None) @staticmethod def GenFfsMakefile(OutputDir, FdfParser, WorkSpace, ArchList, GlobalData): GenFdsGlobalVariable.SetEnv(FdfParser, WorkSpace, ArchList, GlobalData) - for FdName in GenFdsGlobalVariable.FdfParser.Profile.FdDict.keys(): - FdObj = GenFdsGlobalVariable.FdfParser.Profile.FdDict[FdName] + for FdObj in GenFdsGlobalVariable.FdfParser.Profile.FdDict.values(): FdObj.GenFd(Flag=True) - for FvName in GenFdsGlobalVariable.FdfParser.Profile.FvDict.keys(): - FvObj = GenFdsGlobalVariable.FdfParser.Profile.FvDict[FvName] + for FvObj in GenFdsGlobalVariable.FdfParser.Profile.FvDict.values(): FvObj.AddToBuffer(Buffer=None, Flag=True) if GenFdsGlobalVariable.FdfParser.Profile.OptRomDict != {}: - for DriverName in GenFdsGlobalVariable.FdfParser.Profile.OptRomDict.keys(): - OptRomObj = GenFdsGlobalVariable.FdfParser.Profile.OptRomDict[DriverName] + for OptRomObj in GenFdsGlobalVariable.FdfParser.Profile.OptRomDict.values(): OptRomObj.AddToBuffer(Buffer=None, Flag=True) return GenFdsGlobalVariable.FfsCmdDict @@ -591,7 +584,7 @@ class GenFds : def GetFvBlockSize(FvObj): DefaultBlockSize = 0x1 FdObj = None - if GenFds.OnlyGenerateThisFd is not None and GenFds.OnlyGenerateThisFd.upper() in GenFdsGlobalVariable.FdfParser.Profile.FdDict.keys(): + if GenFds.OnlyGenerateThisFd is not None and GenFds.OnlyGenerateThisFd.upper() in GenFdsGlobalVariable.FdfParser.Profile.FdDict: FdObj = GenFdsGlobalVariable.FdfParser.Profile.FdDict[GenFds.OnlyGenerateThisFd.upper()] if FdObj is None: for ElementFd in GenFdsGlobalVariable.FdfParser.Profile.FdDict.values(): diff --git a/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py b/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py index 5e5dc4c948..6a3873940e 100644 --- a/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py +++ b/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py @@ -549,7 +549,7 @@ class GenFdsGlobalVariable: GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input)) if MakefilePath: - if (tuple(Cmd),tuple(GenFdsGlobalVariable.SecCmdList),tuple(GenFdsGlobalVariable.CopyList)) not in GenFdsGlobalVariable.FfsCmdDict.keys(): + if (tuple(Cmd),tuple(GenFdsGlobalVariable.SecCmdList),tuple(GenFdsGlobalVariable.CopyList)) not in GenFdsGlobalVariable.FfsCmdDict: GenFdsGlobalVariable.FfsCmdDict[tuple(Cmd), tuple(GenFdsGlobalVariable.SecCmdList), tuple(GenFdsGlobalVariable.CopyList)] = MakefilePath GenFdsGlobalVariable.SecCmdList = [] GenFdsGlobalVariable.CopyList = [] @@ -779,7 +779,7 @@ class GenFdsGlobalVariable: if MacroDict is not None and len (MacroDict) != 0: Dict.update(MacroDict) - for key in Dict.keys(): + for key in Dict: if Str.find(key) >= 0 : Str = Str.replace (key, Dict[key]) diff --git a/BaseTools/Source/Python/GenFds/Region.py b/BaseTools/Source/Python/GenFds/Region.py index e639739b7e..44f122a712 100644 --- a/BaseTools/Source/Python/GenFds/Region.py +++ b/BaseTools/Source/Python/GenFds/Region.py @@ -1,7 +1,7 @@ ## @file # process FD Region generation # -# Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.
+# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.
# # This program and the accompanying materials # are licensed and made available under the terms and conditions of the BSD License @@ -102,7 +102,7 @@ class Region(RegionClassObject): EdkLogger.error("GenFds", FILE_NOT_FOUND, ExtraData=RegionData) FileName = RegionData - elif RegionData.upper() + 'fv' in ImageBinDict.keys(): + elif RegionData.upper() + 'fv' in ImageBinDict: if not Flag: GenFdsGlobalVariable.InfLogger(' Region Name = FV') FileName = ImageBinDict[RegionData.upper() + 'fv'] @@ -111,8 +111,8 @@ class Region(RegionClassObject): # Generate FvImage. # FvObj = None - if RegionData.upper() in GenFdsGlobalVariable.FdfParser.Profile.FvDict.keys(): - FvObj = GenFdsGlobalVariable.FdfParser.Profile.FvDict.get(RegionData.upper()) + if RegionData.upper() in GenFdsGlobalVariable.FdfParser.Profile.FvDict: + FvObj = GenFdsGlobalVariable.FdfParser.Profile.FvDict[RegionData.upper()] if FvObj is not None : if not Flag: @@ -182,7 +182,7 @@ class Region(RegionClassObject): EdkLogger.error("GenFds", FILE_NOT_FOUND, ExtraData=RegionData) FileName = RegionData - elif RegionData.upper() + 'cap' in ImageBinDict.keys(): + elif RegionData.upper() + 'cap' in ImageBinDict: GenFdsGlobalVariable.InfLogger(' Region Name = CAPSULE') FileName = ImageBinDict[RegionData.upper() + 'cap'] else: @@ -190,7 +190,7 @@ class Region(RegionClassObject): # Generate Capsule image and Put it into FD buffer # CapsuleObj = None - if RegionData.upper() in GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict.keys(): + if RegionData.upper() in GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict: CapsuleObj = GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict[RegionData.upper()] if CapsuleObj is not None : diff --git a/BaseTools/Source/Python/TargetTool/TargetTool.py b/BaseTools/Source/Python/TargetTool/TargetTool.py index 143b53ec35..ecac316b7a 100644 --- a/BaseTools/Source/Python/TargetTool/TargetTool.py +++ b/BaseTools/Source/Python/TargetTool/TargetTool.py @@ -1,7 +1,7 @@ ## @file # Target Tool Parser # -# Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.
+# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.
# # This program and the accompanying materials # are licensed and made available under the terms and conditions of the BSD License @@ -65,7 +65,7 @@ class TargetTool(): LineList = Line.split(KeySplitCharacter,1) if len(LineList) >= 2: Key = LineList[0].strip() - if Key.startswith(CommentCharacter) == False and Key in self.TargetTxtDictionary.keys(): + if Key.startswith(CommentCharacter) == False and Key in self.TargetTxtDictionary: if Key == TAB_TAT_DEFINES_ACTIVE_PLATFORM or Key == TAB_TAT_DEFINES_TOOL_CHAIN_CONF \ or Key == TAB_TAT_DEFINES_MAX_CONCURRENT_THREAD_NUMBER \ or Key == TAB_TAT_DEFINES_ACTIVE_MODULE: @@ -105,7 +105,7 @@ class TargetTool(): LineList = Line.split(KeySplitCharacter,1) if len(LineList) >= 2: Key = LineList[0].strip() - if Key.startswith(CommentCharacter) == False and Key in self.TargetTxtDictionary.keys(): + if Key.startswith(CommentCharacter) == False and Key in self.TargetTxtDictionary: if Key not in existKeys: existKeys.append(Key) else: @@ -118,7 +118,7 @@ class TargetTool(): if ret is not None: Line = ret fw.write(Line) - for key in self.TargetTxtDictionary.keys(): + for key in self.TargetTxtDictionary: if key not in existKeys: print "Warning: %s does not exist in original configuration file" % key Line = GetConfigureKeyValue(self, key) diff --git a/BaseTools/Source/Python/Workspace/InfBuildData.py b/BaseTools/Source/Python/Workspace/InfBuildData.py index bf3da028c6..a725a2a2a7 100644 --- a/BaseTools/Source/Python/Workspace/InfBuildData.py +++ b/BaseTools/Source/Python/Workspace/InfBuildData.py @@ -788,10 +788,7 @@ class InfBuildData(ModuleBuildClassObject): self._Includes.append(self._SourceOverridePath) Macros = self._Macros - if 'PROCESSOR' in GlobalData.gEdkGlobal.keys(): - Macros['PROCESSOR'] = GlobalData.gEdkGlobal['PROCESSOR'] - else: - Macros['PROCESSOR'] = self._Arch + Macros['PROCESSOR'] = GlobalData.gEdkGlobal.get('PROCESSOR', self._Arch) RecordList = self._RawData[MODEL_EFI_INCLUDE, self._Arch, self._Platform] for Record in RecordList: if Record[0].find('EDK_SOURCE') > -1: diff --git a/BaseTools/Source/Python/Workspace/MetaFileParser.py b/BaseTools/Source/Python/Workspace/MetaFileParser.py index ae8cf57e38..3d12314717 100644 --- a/BaseTools/Source/Python/Workspace/MetaFileParser.py +++ b/BaseTools/Source/Python/Workspace/MetaFileParser.py @@ -1504,12 +1504,12 @@ class DscParser(MetaFileParser): # Allow using system environment variables in path after !include # __IncludeMacros['WORKSPACE'] = GlobalData.gGlobalDefines['WORKSPACE'] - if "ECP_SOURCE" in GlobalData.gGlobalDefines.keys(): + if "ECP_SOURCE" in GlobalData.gGlobalDefines: __IncludeMacros['ECP_SOURCE'] = GlobalData.gGlobalDefines['ECP_SOURCE'] # # During GenFds phase call DSC parser, will go into this branch. # - elif "ECP_SOURCE" in GlobalData.gCommandLineDefines.keys(): + elif "ECP_SOURCE" in GlobalData.gCommandLineDefines: __IncludeMacros['ECP_SOURCE'] = GlobalData.gCommandLineDefines['ECP_SOURCE'] __IncludeMacros['EFI_SOURCE'] = GlobalData.gGlobalDefines['EFI_SOURCE'] diff --git a/BaseTools/Source/Python/Workspace/WorkspaceCommon.py b/BaseTools/Source/Python/Workspace/WorkspaceCommon.py index 17ac3b1054..736ef62534 100644 --- a/BaseTools/Source/Python/Workspace/WorkspaceCommon.py +++ b/BaseTools/Source/Python/Workspace/WorkspaceCommon.py @@ -1,7 +1,7 @@ ## @file # Common routines used by workspace # -# Copyright (c) 2012 - 2017, Intel Corporation. All rights reserved.
+# Copyright (c) 2012 - 2018, Intel Corporation. All rights reserved.
# This program and the accompanying materials # are licensed and made available under the terms and conditions of the BSD License # which accompanies this distribution. The full text of the license may be found at @@ -63,11 +63,11 @@ def GetDeclaredPcd(Platform, BuildDatabase, Arch, Target, Toolchain,additionalPk PcdCName = Pcd[0] PcdTokenName = Pcd[1] if GlobalData.MixedPcd: - for PcdItem in GlobalData.MixedPcd.keys(): + for PcdItem in GlobalData.MixedPcd: if (PcdCName, PcdTokenName) in GlobalData.MixedPcd[PcdItem]: PcdCName = PcdItem[0] break - if (PcdCName, PcdTokenName) not in DecPcds.keys(): + if (PcdCName, PcdTokenName) not in DecPcds: DecPcds[PcdCName, PcdTokenName] = Pkg.Pcds[Pcd] return DecPcds, GuidDict @@ -243,7 +243,7 @@ def _ResolveLibraryReference(Module, Platform): for LibraryName in M.Libraries: Library = Platform.LibraryClasses[LibraryName, ':dummy:'] if Library is None: - for Key in Platform.LibraryClasses.data.keys(): + for Key in Platform.LibraryClasses.data: if LibraryName.upper() == Key.upper(): Library = Platform.LibraryClasses[Key, ':dummy:'] break diff --git a/BaseTools/Source/Python/build/BuildReport.py b/BaseTools/Source/Python/build/BuildReport.py index f333279a58..635c311f1a 100644 --- a/BaseTools/Source/Python/build/BuildReport.py +++ b/BaseTools/Source/Python/build/BuildReport.py @@ -838,7 +838,7 @@ class PcdReport(object): for PcdItem in GlobalData.gConditionalPcds: if '.' in PcdItem: (TokenSpaceGuidCName, TokenCName) = PcdItem.split('.') - if (TokenCName, TokenSpaceGuidCName) in Pa.Platform.Pcds.keys(): + if (TokenCName, TokenSpaceGuidCName) in Pa.Platform.Pcds: Pcd = Pa.Platform.Pcds[(TokenCName, TokenSpaceGuidCName)] PcdList = self.ConditionalPcds.setdefault(Pcd.TokenSpaceGuidCName, {}).setdefault(Pcd.Type, []) if Pcd not in PcdList: @@ -1043,7 +1043,7 @@ class PcdReport(object): DscMatch = (DscDefaultValue.strip() == PcdValue.strip()) IsStructure = False - if GlobalData.gStructurePcd and (self.Arch in GlobalData.gStructurePcd.keys()) and ((Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in GlobalData.gStructurePcd[self.Arch]): + if GlobalData.gStructurePcd and (self.Arch in GlobalData.gStructurePcd) and ((Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in GlobalData.gStructurePcd[self.Arch]): IsStructure = True if TypeName in ('DYNVPD', 'DEXVPD'): SkuInfoList = Pcd.SkuInfoList diff --git a/BaseTools/Source/Python/build/build.py b/BaseTools/Source/Python/build/build.py index ede963bc23..36bb1fecf7 100644 --- a/BaseTools/Source/Python/build/build.py +++ b/BaseTools/Source/Python/build/build.py @@ -53,7 +53,7 @@ import Common.EdkLogger import Common.GlobalData as GlobalData from GenFds.GenFds import GenFds -from collections import OrderedDict +from collections import OrderedDict,defaultdict # Version and Copyright VersionNumber = "0.60" + ' ' + gBUILD_VERSION @@ -524,8 +524,7 @@ class BuildTask: BuildTask._Thread.acquire(True) # start a new build thread - Bo = BuildTask._ReadyQueue.keys()[0] - Bt = BuildTask._ReadyQueue.pop(Bo) + Bo,Bt = BuildTask._ReadyQueue.popitem() # move into running queue BuildTask._RunningQueueLock.acquire() @@ -1000,7 +999,7 @@ class Build(): GlobalData.gGlobalDefines['TOOL_CHAIN_TAG'] = self.ToolChainList[0] if self.ToolChainFamily: GlobalData.gGlobalDefines['FAMILY'] = self.ToolChainFamily[0] - if 'PREBUILD' in GlobalData.gCommandLineDefines.keys(): + if 'PREBUILD' in GlobalData.gCommandLineDefines: self.Prebuild = GlobalData.gCommandLineDefines.get('PREBUILD') else: self.Db.InitDatabase() @@ -1041,7 +1040,7 @@ class Build(): self.Prebuild += self.PassCommandOption(self.BuildTargetList, self.ArchList, self.ToolChainList, self.PlatformFile, self.Target) def InitPostBuild(self): - if 'POSTBUILD' in GlobalData.gCommandLineDefines.keys(): + if 'POSTBUILD' in GlobalData.gCommandLineDefines: self.Postbuild = GlobalData.gCommandLineDefines.get('POSTBUILD') else: Platform = self.Db._MapPlatform(str(self.PlatformFile)) @@ -1524,7 +1523,7 @@ class Build(): # First get the XIP base address for FV map file. GuidPattern = re.compile("[-a-fA-F0-9]+") GuidName = re.compile("\(GUID=[-a-fA-F0-9]+") - for FvName in Wa.FdfProfile.FvDict.keys(): + for FvName in Wa.FdfProfile.FvDict: FvMapBuffer = os.path.join(Wa.FvDir, FvName + '.Fv.map') if not os.path.exists(FvMapBuffer): continue @@ -1961,15 +1960,14 @@ class Build(): self._SaveMapFile (MapBuffer, Wa) def _GenFfsCmd(self): - CmdListDict = {} + # convert dictionary of Cmd:(Inf,Arch) + # to a new dictionary of (Inf,Arch):Cmd,Cmd,Cmd... + CmdSetDict = defaultdict(set) GenFfsDict = GenFds.GenFfsMakefile('', GlobalData.gFdfParser, self, self.ArchList, GlobalData) for Cmd in GenFfsDict: tmpInf, tmpArch = GenFfsDict[Cmd] - if (tmpInf, tmpArch) not in CmdListDict.keys(): - CmdListDict[tmpInf, tmpArch] = [Cmd] - else: - CmdListDict[tmpInf, tmpArch].append(Cmd) - return CmdListDict + CmdSetDict[tmpInf, tmpArch].add(Cmd) + return CmdSetDict ## Build a platform in multi-thread mode # -- 2.39.2