diff options
author | mjohn4 <michael.johnson@intel.com> | 2018-11-02 10:02:10 +0800 |
---|---|---|
committer | Feng, Bob C <bob.c.feng@intel.com> | 2019-03-15 15:38:59 +0800 |
commit | b0189eac00a5a97ecf4697bfe22d49aa47e39162 (patch) | |
tree | bad2bb1df7ad62eb9ac6d7c1399f3af12fa5f833 | |
parent | dbe05cb1c0386b6c6abc32b771499acc28a27520 (diff) | |
download | edk2-b0189eac00a5a97ecf4697bfe22d49aa47e39162.zip edk2-b0189eac00a5a97ecf4697bfe22d49aa47e39162.tar.gz edk2-b0189eac00a5a97ecf4697bfe22d49aa47e39162.tar.bz2 |
BaseTools: Explicitly close files after readlines
Rework some file open().readlines to open, readlines, close.
This prevents excessive file handles being open at the same time,
which may be a problem with alternative python environments.
Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Michael Johnson <michael.johnson@intel.com>
Reviewed-by: Bob Feng <bob.c.feng@intel.com>
-rw-r--r-- | BaseTools/Source/Python/AutoGen/InfSectionParser.py | 3 | ||||
-rw-r--r-- | BaseTools/Source/Python/Workspace/MetaFileParser.py | 16 |
2 files changed, 14 insertions, 5 deletions
diff --git a/BaseTools/Source/Python/AutoGen/InfSectionParser.py b/BaseTools/Source/Python/AutoGen/InfSectionParser.py index 388b678..3337304 100644 --- a/BaseTools/Source/Python/AutoGen/InfSectionParser.py +++ b/BaseTools/Source/Python/AutoGen/InfSectionParser.py @@ -34,7 +34,8 @@ class InfSectionParser(): SectionData = []
try:
- FileLinesList = open(self._FilePath, "r").readlines()
+ with open(self._FilePath, "r") as File:
+ FileLinesList = File.readlines()
except BaseException:
EdkLogger.error("build", AUTOGEN_ERROR, 'File %s is opened failed.' % self._FilePath)
diff --git a/BaseTools/Source/Python/Workspace/MetaFileParser.py b/BaseTools/Source/Python/Workspace/MetaFileParser.py index a3e3216..e5fb3f5 100644 --- a/BaseTools/Source/Python/Workspace/MetaFileParser.py +++ b/BaseTools/Source/Python/Workspace/MetaFileParser.py @@ -576,7 +576,8 @@ class InfParser(MetaFileParser): NmakeLine = ''
Content = ''
try:
- Content = open(str(self.MetaFile), 'r').readlines()
+ with open(str(self.MetaFile), 'r') as File:
+ Content = File.readlines()
except:
EdkLogger.error("Parser", FILE_READ_FAILURE, ExtraData=self.MetaFile)
@@ -950,7 +951,8 @@ class DscParser(MetaFileParser): def Start(self):
Content = ''
try:
- Content = open(str(self.MetaFile), 'r').readlines()
+ with open(str(self.MetaFile), 'r') as File:
+ Content = File.readlines()
except:
EdkLogger.error("Parser", FILE_READ_FAILURE, ExtraData=self.MetaFile)
@@ -1493,7 +1495,12 @@ class DscParser(MetaFileParser): self._SubsectionType = MODEL_UNKNOWN
def __RetrievePcdValue(self):
- Content = open(str(self.MetaFile), 'r').readlines()
+ try:
+ with open(str(self.MetaFile), 'r') as File:
+ Content = File.readlines()
+ except:
+ EdkLogger.error("Parser", FILE_READ_FAILURE, ExtraData=self.MetaFile)
+
GlobalData.gPlatformOtherPcds['DSCFILE'] = str(self.MetaFile)
for PcdType in (MODEL_PCD_PATCHABLE_IN_MODULE, MODEL_PCD_DYNAMIC_DEFAULT, MODEL_PCD_DYNAMIC_HII,
MODEL_PCD_DYNAMIC_VPD, MODEL_PCD_DYNAMIC_EX_DEFAULT, MODEL_PCD_DYNAMIC_EX_HII,
@@ -1786,7 +1793,8 @@ class DecParser(MetaFileParser): def Start(self):
Content = ''
try:
- Content = open(str(self.MetaFile), 'r').readlines()
+ with open(str(self.MetaFile), 'r') as File:
+ Content = File.readlines()
except:
EdkLogger.error("Parser", FILE_READ_FAILURE, ExtraData=self.MetaFile)
|