]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/GenFds/GenFds.py
BaseTools: refactor and remove un-needed use of .keys() on dictionaries
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / GenFds.py
index c507b0148af0baccdd7e608e086a655d531d5310..54c7d828305f7c58a42378280e622daf9c47909f 100644 (file)
@@ -92,7 +92,7 @@ def main():
         else:\r
             Workspace = os.path.normcase(Options.Workspace)\r
             GenFdsGlobalVariable.WorkSpaceDir = Workspace\r
-            if 'EDK_SOURCE' in os.environ.keys():\r
+            if 'EDK_SOURCE' in os.environ:\r
                 GenFdsGlobalVariable.EdkSourceDir = os.path.normcase(os.environ['EDK_SOURCE'])\r
             if (Options.debug):\r
                 GenFdsGlobalVariable.VerboseLogger("Using Workspace:" + Workspace)\r
@@ -156,7 +156,7 @@ def main():
                 # This also handles someone specifying the Conf directory in the workspace. Using --conf=Conf\r
                 ConfDirectoryPath = os.path.join(GenFdsGlobalVariable.WorkSpaceDir, ConfDirectoryPath)\r
         else:\r
-            if "CONF_PATH" in os.environ.keys():\r
+            if "CONF_PATH" in os.environ:\r
                 ConfDirectoryPath = os.path.normcase(os.environ["CONF_PATH"])\r
             else:\r
                 # Get standard WORKSPACE/Conf, use the absolute path to the WORKSPACE/Conf\r
@@ -216,11 +216,11 @@ def main():
         os.environ["WORKSPACE"] = Workspace\r
 \r
         # Use the -t and -b option as gGlobalDefines's TOOLCHAIN and TARGET if they are not defined\r
-        if "TARGET" not in GlobalData.gGlobalDefines.keys():\r
+        if "TARGET" not in GlobalData.gGlobalDefines:\r
             GlobalData.gGlobalDefines["TARGET"] = GenFdsGlobalVariable.TargetName\r
-        if "TOOLCHAIN" not in GlobalData.gGlobalDefines.keys():\r
+        if "TOOLCHAIN" not in GlobalData.gGlobalDefines:\r
             GlobalData.gGlobalDefines["TOOLCHAIN"] = GenFdsGlobalVariable.ToolChainTag\r
-        if "TOOL_CHAIN_TAG" not in GlobalData.gGlobalDefines.keys():\r
+        if "TOOL_CHAIN_TAG" not in GlobalData.gGlobalDefines:\r
             GlobalData.gGlobalDefines['TOOL_CHAIN_TAG'] = GenFdsGlobalVariable.ToolChainTag\r
 \r
         """call Workspace build create database"""\r
@@ -278,21 +278,21 @@ def main():
             EdkLogger.error("GenFds", FORMAT_NOT_SUPPORTED, "Cycle Reference Detected in FDF file")\r
 \r
         if (Options.uiFdName) :\r
-            if Options.uiFdName.upper() in FdfParserObj.Profile.FdDict.keys():\r
+            if Options.uiFdName.upper() in FdfParserObj.Profile.FdDict:\r
                 GenFds.OnlyGenerateThisFd = Options.uiFdName\r
             else:\r
                 EdkLogger.error("GenFds", OPTION_VALUE_INVALID,\r
                                 "No such an FD in FDF file: %s" % Options.uiFdName)\r
 \r
         if (Options.uiFvName) :\r
-            if Options.uiFvName.upper() in FdfParserObj.Profile.FvDict.keys():\r
+            if Options.uiFvName.upper() in FdfParserObj.Profile.FvDict:\r
                 GenFds.OnlyGenerateThisFv = Options.uiFvName\r
             else:\r
                 EdkLogger.error("GenFds", OPTION_VALUE_INVALID,\r
                                 "No such an FV in FDF file: %s" % Options.uiFvName)\r
 \r
         if (Options.uiCapName) :\r
-            if Options.uiCapName.upper() in FdfParserObj.Profile.CapsuleDict.keys():\r
+            if Options.uiCapName.upper() in FdfParserObj.Profile.CapsuleDict:\r
                 GenFds.OnlyGenerateThisCap = Options.uiCapName\r
             else:\r
                 EdkLogger.error("GenFds", OPTION_VALUE_INVALID,\r
@@ -388,7 +388,7 @@ def FindExtendTool(KeyStringList, CurrentArchList, NameGuid):
                 KeyStringList.append(Target + '_' + ToolChain + '_' + Arch)\r
 \r
     if GenFdsGlobalVariable.GuidToolDefinition:\r
-        if NameGuid in GenFdsGlobalVariable.GuidToolDefinition.keys():\r
+        if NameGuid in GenFdsGlobalVariable.GuidToolDefinition:\r
             return GenFdsGlobalVariable.GuidToolDefinition[NameGuid]\r
 \r
     ToolDefinition = ToolDefClassObject.ToolDefDict(GenFdsGlobalVariable.ConfDir).ToolsDefTxtDictionary\r
@@ -450,10 +450,10 @@ def FindExtendTool(KeyStringList, CurrentArchList, NameGuid):
                     if Key in KeyStringList and KeyList[4] == 'GUID':\r
                         ToolPathKey   = Key + '_' + KeyList[3] + '_PATH'\r
                         ToolOptionKey = Key + '_' + KeyList[3] + '_FLAGS'\r
-        if ToolPathKey in BuildOption.keys():\r
-            ToolPathTmp = BuildOption.get(ToolPathKey)\r
-        if ToolOptionKey in BuildOption.keys():\r
-            ToolOption = BuildOption.get(ToolOptionKey)\r
+        if ToolPathKey in BuildOption:\r
+            ToolPathTmp = BuildOption[ToolPathKey]\r
+        if ToolOptionKey in BuildOption:\r
+            ToolOption = BuildOption[ToolOptionKey]\r
 \r
     GenFdsGlobalVariable.GuidToolDefinition[NameGuid] = (ToolPathTmp, ToolOption)\r
     return ToolPathTmp, ToolOption\r
@@ -522,63 +522,56 @@ class GenFds :
         GenFdsGlobalVariable.SetDir ('', FdfParser, WorkSpace, ArchList)\r
 \r
         GenFdsGlobalVariable.VerboseLogger(" Generate all Fd images and their required FV and Capsule images!")\r
-        if GenFds.OnlyGenerateThisCap is not None and GenFds.OnlyGenerateThisCap.upper() in GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict.keys():\r
-            CapsuleObj = GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict.get(GenFds.OnlyGenerateThisCap.upper())\r
+        if GenFds.OnlyGenerateThisCap is not None and GenFds.OnlyGenerateThisCap.upper() in GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict:\r
+            CapsuleObj = GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict[GenFds.OnlyGenerateThisCap.upper()]\r
             if CapsuleObj is not None:\r
                 CapsuleObj.GenCapsule()\r
                 return\r
 \r
-        if GenFds.OnlyGenerateThisFd is not None and GenFds.OnlyGenerateThisFd.upper() in GenFdsGlobalVariable.FdfParser.Profile.FdDict.keys():\r
-            FdObj = GenFdsGlobalVariable.FdfParser.Profile.FdDict.get(GenFds.OnlyGenerateThisFd.upper())\r
+        if GenFds.OnlyGenerateThisFd is not None and GenFds.OnlyGenerateThisFd.upper() in GenFdsGlobalVariable.FdfParser.Profile.FdDict:\r
+            FdObj = GenFdsGlobalVariable.FdfParser.Profile.FdDict[GenFds.OnlyGenerateThisFd.upper()]\r
             if FdObj is not None:\r
                 FdObj.GenFd()\r
                 return\r
         elif GenFds.OnlyGenerateThisFd is None and GenFds.OnlyGenerateThisFv is None:\r
-            for FdName in GenFdsGlobalVariable.FdfParser.Profile.FdDict.keys():\r
-                FdObj = GenFdsGlobalVariable.FdfParser.Profile.FdDict[FdName]\r
+            for FdObj in GenFdsGlobalVariable.FdfParser.Profile.FdDict.values():\r
                 FdObj.GenFd()\r
 \r
         GenFdsGlobalVariable.VerboseLogger("\n Generate other FV images! ")\r
-        if GenFds.OnlyGenerateThisFv is not None and GenFds.OnlyGenerateThisFv.upper() in GenFdsGlobalVariable.FdfParser.Profile.FvDict.keys():\r
-            FvObj = GenFdsGlobalVariable.FdfParser.Profile.FvDict.get(GenFds.OnlyGenerateThisFv.upper())\r
+        if GenFds.OnlyGenerateThisFv is not None and GenFds.OnlyGenerateThisFv.upper() in GenFdsGlobalVariable.FdfParser.Profile.FvDict:\r
+            FvObj = GenFdsGlobalVariable.FdfParser.Profile.FvDict[GenFds.OnlyGenerateThisFv.upper()]\r
             if FvObj is not None:\r
                 Buffer = StringIO.StringIO()\r
                 FvObj.AddToBuffer(Buffer)\r
                 Buffer.close()\r
                 return\r
         elif GenFds.OnlyGenerateThisFv is None:\r
-            for FvName in GenFdsGlobalVariable.FdfParser.Profile.FvDict.keys():\r
+            for FvObj in GenFdsGlobalVariable.FdfParser.Profile.FvDict.values():\r
                 Buffer = StringIO.StringIO('')\r
-                FvObj = GenFdsGlobalVariable.FdfParser.Profile.FvDict[FvName]\r
                 FvObj.AddToBuffer(Buffer)\r
                 Buffer.close()\r
         \r
         if GenFds.OnlyGenerateThisFv is None and GenFds.OnlyGenerateThisFd is None and GenFds.OnlyGenerateThisCap is None:\r
             if GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict != {}:\r
                 GenFdsGlobalVariable.VerboseLogger("\n Generate other Capsule images!")\r
-                for CapsuleName in GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict.keys():\r
-                    CapsuleObj = GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict[CapsuleName]\r
+                for CapsuleObj in GenFdsGlobalVariable.FdfParser.Profile.CapsuleDict.values():\r
                     CapsuleObj.GenCapsule()\r
 \r
             if GenFdsGlobalVariable.FdfParser.Profile.OptRomDict != {}:\r
                 GenFdsGlobalVariable.VerboseLogger("\n Generate all Option ROM!")\r
-                for DriverName in GenFdsGlobalVariable.FdfParser.Profile.OptRomDict.keys():\r
-                    OptRomObj = GenFdsGlobalVariable.FdfParser.Profile.OptRomDict[DriverName]\r
+                for OptRomObj in GenFdsGlobalVariable.FdfParser.Profile.OptRomDict.values():\r
                     OptRomObj.AddToBuffer(None)\r
     @staticmethod\r
     def GenFfsMakefile(OutputDir, FdfParser, WorkSpace, ArchList, GlobalData):\r
         GenFdsGlobalVariable.SetEnv(FdfParser, WorkSpace, ArchList, GlobalData)\r
-        for FdName in GenFdsGlobalVariable.FdfParser.Profile.FdDict.keys():\r
-            FdObj = GenFdsGlobalVariable.FdfParser.Profile.FdDict[FdName]\r
+        for FdObj in GenFdsGlobalVariable.FdfParser.Profile.FdDict.values():\r
             FdObj.GenFd(Flag=True)\r
 \r
-        for FvName in GenFdsGlobalVariable.FdfParser.Profile.FvDict.keys():\r
-            FvObj = GenFdsGlobalVariable.FdfParser.Profile.FvDict[FvName]\r
+        for FvObj in GenFdsGlobalVariable.FdfParser.Profile.FvDict.values():\r
             FvObj.AddToBuffer(Buffer=None, Flag=True)\r
 \r
         if GenFdsGlobalVariable.FdfParser.Profile.OptRomDict != {}:\r
-            for DriverName in GenFdsGlobalVariable.FdfParser.Profile.OptRomDict.keys():\r
-                OptRomObj = GenFdsGlobalVariable.FdfParser.Profile.OptRomDict[DriverName]\r
+            for OptRomObj in GenFdsGlobalVariable.FdfParser.Profile.OptRomDict.values():\r
                 OptRomObj.AddToBuffer(Buffer=None, Flag=True)\r
 \r
         return GenFdsGlobalVariable.FfsCmdDict\r
@@ -591,7 +584,7 @@ class GenFds :
     def GetFvBlockSize(FvObj):\r
         DefaultBlockSize = 0x1\r
         FdObj = None\r
-        if GenFds.OnlyGenerateThisFd is not None and GenFds.OnlyGenerateThisFd.upper() in GenFdsGlobalVariable.FdfParser.Profile.FdDict.keys():\r
+        if GenFds.OnlyGenerateThisFd is not None and GenFds.OnlyGenerateThisFd.upper() in GenFdsGlobalVariable.FdfParser.Profile.FdDict:\r
             FdObj = GenFdsGlobalVariable.FdfParser.Profile.FdDict[GenFds.OnlyGenerateThisFd.upper()]\r
         if FdObj is None:\r
             for ElementFd in GenFdsGlobalVariable.FdfParser.Profile.FdDict.values():\r