From: Jaben Carsey <jaben.carsey@intel.com>
To: edk2-devel@lists.01.org
Cc: Liming Gao <liming.gao@intel.com>, Yonghong Zhu <yonghong.zhu@intel.com>
Subject: [PATCH v1 1/3] BaseTools: refactor and remove more keys() usage
Date: Tue, 10 Apr 2018 07:20:06 -0700 [thread overview]
Message-ID: <5a483778fbfbd93317b013c0109324950a05990f.1523369916.git.jaben.carsey@intel.com> (raw)
In-Reply-To: <cover.1523369916.git.jaben.carsey@intel.com>
In-Reply-To: <cover.1523369916.git.jaben.carsey@intel.com>
this is no longer required to make dictionary objects iterable.
Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jaben Carsey <jaben.carsey@intel.com>
---
BaseTools/Source/Python/Workspace/DscBuildData.py | 59 +++++++++-----------
1 file changed, 27 insertions(+), 32 deletions(-)
diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/Source/Python/Workspace/DscBuildData.py
index cf9608651269..35ef15262a09 100644
--- a/BaseTools/Source/Python/Workspace/DscBuildData.py
+++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
@@ -593,7 +593,7 @@ class DscBuildData(PlatformBuildClassObject):
#
# If command line defined, should override the value in DSC file.
#
- if 'FIX_LOAD_TOP_MEMORY_ADDRESS' in GlobalData.gCommandLineDefines.keys():
+ if 'FIX_LOAD_TOP_MEMORY_ADDRESS' in GlobalData.gCommandLineDefines:
try:
self._LoadFixAddress = int(GlobalData.gCommandLineDefines['FIX_LOAD_TOP_MEMORY_ADDRESS'], 0)
except:
@@ -682,9 +682,7 @@ class DscBuildData(PlatformBuildClassObject):
self.DefaultStores[Record[1].upper()] = (self.ToInt(Record[0]),Record[1].upper())
if TAB_DEFAULT_STORES_DEFAULT not in self.DefaultStores:
self.DefaultStores[TAB_DEFAULT_STORES_DEFAULT] = (0,TAB_DEFAULT_STORES_DEFAULT)
- GlobalData.gDefaultStores = self.DefaultStores.keys()
- if GlobalData.gDefaultStores:
- GlobalData.gDefaultStores.sort()
+ GlobalData.gDefaultStores = sorted(self.DefaultStores.keys())
return self.DefaultStores
## Retrieve [Components] section information
@@ -1430,11 +1428,11 @@ class DscBuildData(PlatformBuildClassObject):
for pcdkey in Pcds:
pcd = Pcds[pcdkey]
- if 'DEFAULT' not in pcd.SkuInfoList.keys() and 'COMMON' in pcd.SkuInfoList.keys():
+ if 'DEFAULT' not in pcd.SkuInfoList and 'COMMON' in pcd.SkuInfoList:
pcd.SkuInfoList['DEFAULT'] = pcd.SkuInfoList['COMMON']
- del(pcd.SkuInfoList['COMMON'])
- elif 'DEFAULT' in pcd.SkuInfoList.keys() and 'COMMON' in pcd.SkuInfoList.keys():
- del(pcd.SkuInfoList['COMMON'])
+ del pcd.SkuInfoList['COMMON']
+ elif 'DEFAULT' in pcd.SkuInfoList and 'COMMON' in pcd.SkuInfoList:
+ del pcd.SkuInfoList['COMMON']
map(self.FilterSkuSettings,[Pcds[pcdkey] for pcdkey in Pcds if Pcds[pcdkey].Type in DynamicPcdType])
return Pcds
@@ -1479,10 +1477,7 @@ class DscBuildData(PlatformBuildClassObject):
else:
PcdValueDict[PcdCName, TokenSpaceGuid] = {SkuName:(PcdValue, DatumType, MaxDatumSize)}
- PcdsKeys = PcdValueDict.keys()
- for PcdCName, TokenSpaceGuid in PcdsKeys:
-
- PcdSetting = PcdValueDict[PcdCName, TokenSpaceGuid]
+ for ((PcdName,TokenSpaceGuid),PcdSetting) in PcdValueDict.iteritems():
PcdValue = None
DatumType = None
MaxDatumSize = None
@@ -1883,7 +1878,7 @@ class DscBuildData(PlatformBuildClassObject):
OverrideValues = {DefaultStore:""}
if Pcd.SkuOverrideValues:
OverrideValues = Pcd.SkuOverrideValues[SkuName]
- for DefaultStoreName in OverrideValues.keys():
+ for DefaultStoreName in OverrideValues:
CApp = CApp + 'void\n'
CApp = CApp + 'Initialize_%s_%s_%s_%s(\n' % (SkuName, DefaultStoreName, Pcd.TokenSpaceGuidCName, Pcd.TokenCName)
CApp = CApp + ' void\n'
@@ -2261,7 +2256,7 @@ class DscBuildData(PlatformBuildClassObject):
PcdValue, DatumType, MaxDatumSize = self._ValidatePcd(PcdCName, TokenSpaceGuid, Setting, Type, Dummy4)
SkuInfo = SkuInfoClass(SkuName, self.SkuIds[SkuName][0], '', '', '', '', '', PcdValue)
- if (PcdCName, TokenSpaceGuid) in Pcds.keys():
+ if (PcdCName, TokenSpaceGuid) in Pcds:
pcdObject = Pcds[PcdCName, TokenSpaceGuid]
pcdObject.SkuInfoList[SkuName] = SkuInfo
if MaxDatumSize.strip():
@@ -2294,15 +2289,15 @@ class DscBuildData(PlatformBuildClassObject):
for sku in pcd.SkuInfoList.values():
if (sku.DefaultValue == "" or sku.DefaultValue==None):
sku.DefaultValue = pcdDecObject.DefaultValue
- if 'DEFAULT' not in pcd.SkuInfoList.keys() and 'COMMON' not in pcd.SkuInfoList.keys():
+ if 'DEFAULT' not in pcd.SkuInfoList and 'COMMON' not in pcd.SkuInfoList:
valuefromDec = pcdDecObject.DefaultValue
SkuInfo = SkuInfoClass('DEFAULT', '0', '', '', '', '', '', valuefromDec)
pcd.SkuInfoList['DEFAULT'] = SkuInfo
- elif 'DEFAULT' not in pcd.SkuInfoList.keys() and 'COMMON' in pcd.SkuInfoList.keys():
+ elif 'DEFAULT' not in pcd.SkuInfoList and 'COMMON' in pcd.SkuInfoList:
pcd.SkuInfoList['DEFAULT'] = pcd.SkuInfoList['COMMON']
- del(pcd.SkuInfoList['COMMON'])
- elif 'DEFAULT' in pcd.SkuInfoList.keys() and 'COMMON' in pcd.SkuInfoList.keys():
- del(pcd.SkuInfoList['COMMON'])
+ del pcd.SkuInfoList['COMMON']
+ elif 'DEFAULT' in pcd.SkuInfoList and 'COMMON' in pcd.SkuInfoList:
+ del pcd.SkuInfoList['COMMON']
map(self.FilterSkuSettings,Pcds.values())
@@ -2311,7 +2306,7 @@ class DscBuildData(PlatformBuildClassObject):
def FilterSkuSettings(self, PcdObj):
if self.SkuIdMgr.SkuUsageType == self.SkuIdMgr.SINGLE:
- if 'DEFAULT' in PcdObj.SkuInfoList.keys() and self.SkuIdMgr.SystemSkuId not in PcdObj.SkuInfoList.keys():
+ if 'DEFAULT' in PcdObj.SkuInfoList and self.SkuIdMgr.SystemSkuId not in PcdObj.SkuInfoList:
PcdObj.SkuInfoList[self.SkuIdMgr.SystemSkuId] = PcdObj.SkuInfoList['DEFAULT']
PcdObj.SkuInfoList = {'DEFAULT':PcdObj.SkuInfoList[self.SkuIdMgr.SystemSkuId]}
PcdObj.SkuInfoList['DEFAULT'].SkuIdName = 'DEFAULT'
@@ -2465,7 +2460,7 @@ class DscBuildData(PlatformBuildClassObject):
EdkLogger.error('Build', PCD_VARIABLE_ATTRIBUTES_CONFLICT_ERROR, "The variable %s.%s for DynamicHii PCDs has conflicting attributes [%s] and [%s] " % (VariableGuid, VariableName, VarAttribute, VariableAttrs[(VariableName, VariableGuid)]))
pcdDecObject = self._DecPcds[PcdCName, TokenSpaceGuid]
- if (PcdCName, TokenSpaceGuid) in Pcds.keys():
+ if (PcdCName, TokenSpaceGuid) in Pcds:
pcdObject = Pcds[PcdCName, TokenSpaceGuid]
if SkuName in pcdObject.SkuInfoList:
Skuitem = pcdObject.SkuInfoList[SkuName]
@@ -2503,15 +2498,15 @@ class DscBuildData(PlatformBuildClassObject):
for default_store in sku.DefaultStoreDict:
sku.DefaultStoreDict[default_store]=pcdDecObject.DefaultValue
pcd.DefaultValue = pcdDecObject.DefaultValue
- if 'DEFAULT' not in pcd.SkuInfoList.keys() and 'COMMON' not in pcd.SkuInfoList.keys():
+ if 'DEFAULT' not in pcd.SkuInfoList and 'COMMON' not in pcd.SkuInfoList:
valuefromDec = pcdDecObject.DefaultValue
SkuInfo = SkuInfoClass('DEFAULT', '0', SkuInfoObj.VariableName, SkuInfoObj.VariableGuid, SkuInfoObj.VariableOffset, valuefromDec,VariableAttribute=SkuInfoObj.VariableAttribute,DefaultStore={DefaultStore:valuefromDec})
pcd.SkuInfoList['DEFAULT'] = SkuInfo
- elif 'DEFAULT' not in pcd.SkuInfoList.keys() and 'COMMON' in pcd.SkuInfoList.keys():
+ elif 'DEFAULT' not in pcd.SkuInfoList and 'COMMON' in pcd.SkuInfoList:
pcd.SkuInfoList['DEFAULT'] = pcd.SkuInfoList['COMMON']
- del(pcd.SkuInfoList['COMMON'])
- elif 'DEFAULT' in pcd.SkuInfoList.keys() and 'COMMON' in pcd.SkuInfoList.keys():
- del(pcd.SkuInfoList['COMMON'])
+ del pcd.SkuInfoList['COMMON']
+ elif 'DEFAULT' in pcd.SkuInfoList and 'COMMON' in pcd.SkuInfoList:
+ del pcd.SkuInfoList['COMMON']
if pcd.MaxDatumSize.strip():
MaxSize = int(pcd.MaxDatumSize, 0)
@@ -2592,7 +2587,7 @@ class DscBuildData(PlatformBuildClassObject):
#
VpdOffset, MaxDatumSize, InitialValue = self._ValidatePcd(PcdCName, TokenSpaceGuid, Setting, Type, Dummy4)
SkuInfo = SkuInfoClass(SkuName, self.SkuIds[SkuName][0], '', '', '', '', VpdOffset, InitialValue)
- if (PcdCName, TokenSpaceGuid) in Pcds.keys():
+ if (PcdCName, TokenSpaceGuid) in Pcds:
pcdObject = Pcds[PcdCName, TokenSpaceGuid]
pcdObject.SkuInfoList[SkuName] = SkuInfo
if MaxDatumSize.strip():
@@ -2626,15 +2621,15 @@ class DscBuildData(PlatformBuildClassObject):
for sku in pcd.SkuInfoList.values():
if (sku.DefaultValue == "" or sku.DefaultValue==None):
sku.DefaultValue = pcdDecObject.DefaultValue
- if 'DEFAULT' not in pcd.SkuInfoList.keys() and 'COMMON' not in pcd.SkuInfoList.keys():
+ if 'DEFAULT' not in pcd.SkuInfoList and 'COMMON' not in pcd.SkuInfoList:
valuefromDec = pcdDecObject.DefaultValue
SkuInfo = SkuInfoClass('DEFAULT', '0', '', '', '', '', SkuInfoObj.VpdOffset, valuefromDec)
pcd.SkuInfoList['DEFAULT'] = SkuInfo
- elif 'DEFAULT' not in pcd.SkuInfoList.keys() and 'COMMON' in pcd.SkuInfoList.keys():
+ elif 'DEFAULT' not in pcd.SkuInfoList and 'COMMON' in pcd.SkuInfoList:
pcd.SkuInfoList['DEFAULT'] = pcd.SkuInfoList['COMMON']
- del(pcd.SkuInfoList['COMMON'])
- elif 'DEFAULT' in pcd.SkuInfoList.keys() and 'COMMON' in pcd.SkuInfoList.keys():
- del(pcd.SkuInfoList['COMMON'])
+ del pcd.SkuInfoList['COMMON']
+ elif 'DEFAULT' in pcd.SkuInfoList and 'COMMON' in pcd.SkuInfoList:
+ del pcd.SkuInfoList['COMMON']
map(self.FilterSkuSettings,Pcds.values())
--
2.16.2.windows.1
next prev parent reply other threads:[~2018-04-10 14:20 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-10 14:20 [PATCH v1 0/3] BaseTools: refactor to remove redundant Jaben Carsey
2018-04-10 14:20 ` Jaben Carsey [this message]
2018-04-18 8:48 ` [PATCH v1 1/3] BaseTools: refactor and remove more keys() usage Zhu, Yonghong
2018-04-10 14:20 ` [PATCH v1 2/3] BaseTools: use predefined constants instead of local strings Jaben Carsey
2018-04-16 1:43 ` Zhu, Yonghong
2018-04-10 14:20 ` [PATCH v1 3/3] BaseTools: use existing contrants to replace raw strings in python code Jaben Carsey
2018-04-11 1:07 ` Zhu, Yonghong
2018-04-11 14:20 ` Carsey, Jaben
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5a483778fbfbd93317b013c0109324950a05990f.1523369916.git.jaben.carsey@intel.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox