public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v3 1/1] BaseTools: Explicitly close files after readlines
@ 2018-11-02  2:02 Michael Johnson
  2018-11-02  2:18 ` Feng, Bob C
  0 siblings, 1 reply; 2+ messages in thread
From: Michael Johnson @ 2018-11-02  2:02 UTC (permalink / raw)
  To: edk2-devel; +Cc: mjohn4, Liming Gao

From: mjohn4 <michael.johnson@intel.com>

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>
---
 BaseTools/Source/Python/AutoGen/InfSectionParser.py |  3 ++-
 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 d985089738..69f0bc8ee9 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", 0).readlines()
+            with open(self._FilePath, "r", 0) 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 804a4aa5cb..1cbed6e693 100644
--- a/BaseTools/Source/Python/Workspace/MetaFileParser.py
+++ b/BaseTools/Source/Python/Workspace/MetaFileParser.py
@@ -537,7 +537,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)
 
@@ -917,7 +918,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)
 
@@ -1429,7 +1431,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,
@@ -1727,7 +1734,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)
 
-- 
2.18.0.windows.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v3 1/1] BaseTools: Explicitly close files after readlines
  2018-11-02  2:02 [PATCH v3 1/1] BaseTools: Explicitly close files after readlines Michael Johnson
@ 2018-11-02  2:18 ` Feng, Bob C
  0 siblings, 0 replies; 2+ messages in thread
From: Feng, Bob C @ 2018-11-02  2:18 UTC (permalink / raw)
  To: edk2-devel, edk2-devel@lists.01.org; +Cc: Gao, Liming

Reviewed-by: Bob C Feng <bob.c.feng@intel.com> 


Thanks,
Bob

-----Original Message-----
From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] 
Sent: Friday, November 2, 2018 10:02 AM
To: edk2-devel@lists.01.org
Cc: Gao, Liming <liming.gao@intel.com>
Subject: [edk2] [PATCH v3 1/1] BaseTools: Explicitly close files after readlines

From: mjohn4 <michael.johnson@intel.com>

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>
---
 BaseTools/Source/Python/AutoGen/InfSectionParser.py |  3 ++-  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 d985089738..69f0bc8ee9 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", 0).readlines()
+            with open(self._FilePath, "r", 0) 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 804a4aa5cb..1cbed6e693 100644
--- a/BaseTools/Source/Python/Workspace/MetaFileParser.py
+++ b/BaseTools/Source/Python/Workspace/MetaFileParser.py
@@ -537,7 +537,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)
 
@@ -917,7 +918,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)
 
@@ -1429,7 +1431,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, @@ -1727,7 +1734,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)
 
--
2.18.0.windows.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-11-02  2:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-11-02  2:02 [PATCH v3 1/1] BaseTools: Explicitly close files after readlines Michael Johnson
2018-11-02  2:18 ` Feng, Bob C

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox