summaryrefslogtreecommitdiffstats
path: root/BaseTools/Source/Python/GenFds
diff options
context:
space:
mode:
authorGary Lin <glin@suse.com>2018-06-25 18:31:36 +0800
committerYonghong Zhu <yonghong.zhu@intel.com>2018-06-27 16:33:28 +0800
commit86379ac48ba17c71d4623c57099b064b15118e21 (patch)
tree9ec107c195a28a4bdcf9b4734fa2c20b8c07ce32 /BaseTools/Source/Python/GenFds
parent0d1f5b2b5dc3c1cf381be0a1ec8f960dc6029a93 (diff)
downloadedk2-86379ac48ba17c71d4623c57099b064b15118e21.tar.gz
edk2-86379ac48ba17c71d4623c57099b064b15118e21.tar.bz2
edk2-86379ac48ba17c71d4623c57099b064b15118e21.zip
BaseTools: Replace StringIO.StringIO with io.BytesIO
Replace StringIO.StringIO with io.BytesIO to be compatible with python3. This commit also removes "import StringIO" from those python scripts that don't really use it. Contributed-under: TianoCore Contribution Agreement 1.1 Cc: Yonghong Zhu <yonghong.zhu@intel.com> Cc: Liming Gao <liming.gao@intel.com> Signed-off-by: Gary Lin <glin@suse.com> Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
Diffstat (limited to 'BaseTools/Source/Python/GenFds')
-rw-r--r--BaseTools/Source/Python/GenFds/AprioriSection.py4
-rw-r--r--BaseTools/Source/Python/GenFds/Capsule.py10
-rw-r--r--BaseTools/Source/Python/GenFds/CapsuleData.py4
-rw-r--r--BaseTools/Source/Python/GenFds/Fd.py6
-rw-r--r--BaseTools/Source/Python/GenFds/FfsFileStatement.py4
-rw-r--r--BaseTools/Source/Python/GenFds/FfsInfStatement.py4
-rw-r--r--BaseTools/Source/Python/GenFds/Fv.py6
-rw-r--r--BaseTools/Source/Python/GenFds/FvImageSection.py4
-rw-r--r--BaseTools/Source/Python/GenFds/GenFds.py8
-rw-r--r--BaseTools/Source/Python/GenFds/OptionRom.py3
-rw-r--r--BaseTools/Source/Python/GenFds/Region.py11
11 files changed, 31 insertions, 33 deletions
diff --git a/BaseTools/Source/Python/GenFds/AprioriSection.py b/BaseTools/Source/Python/GenFds/AprioriSection.py
index 3d28c7d778..b3e7b5fc64 100644
--- a/BaseTools/Source/Python/GenFds/AprioriSection.py
+++ b/BaseTools/Source/Python/GenFds/AprioriSection.py
@@ -17,7 +17,7 @@
#
from struct import *
import Common.LongFilePathOs as os
-import StringIO
+from io import BytesIO
import FfsFileStatement
from GenFdsGlobalVariable import GenFdsGlobalVariable
from CommonDataClass.FdfClass import AprioriSectionClassObject
@@ -51,7 +51,7 @@ class AprioriSection (AprioriSectionClassObject):
def GenFfs (self, FvName, Dict = {}, IsMakefile = False):
DXE_GUID = "FC510EE7-FFDC-11D4-BD41-0080C73C8881"
PEI_GUID = "1B45CC0A-156A-428A-AF62-49864DA0E6E6"
- Buffer = StringIO.StringIO('')
+ Buffer = BytesIO('')
AprioriFileGuid = DXE_GUID
if self.AprioriType == "PEI":
AprioriFileGuid = PEI_GUID
diff --git a/BaseTools/Source/Python/GenFds/Capsule.py b/BaseTools/Source/Python/GenFds/Capsule.py
index fbd48f3c6d..b02661d998 100644
--- a/BaseTools/Source/Python/GenFds/Capsule.py
+++ b/BaseTools/Source/Python/GenFds/Capsule.py
@@ -19,7 +19,7 @@ from GenFdsGlobalVariable import GenFdsGlobalVariable
from CommonDataClass.FdfClass import CapsuleClassObject
import Common.LongFilePathOs as os
import subprocess
-import StringIO
+from io import BytesIO
from Common.Misc import SaveFileOnChange
from GenFds import GenFds
from Common.Misc import PackRegistryFormatGuid
@@ -66,7 +66,7 @@ class Capsule (CapsuleClassObject) :
# UINT32 CapsuleImageSize;
# } EFI_CAPSULE_HEADER;
#
- Header = StringIO.StringIO()
+ Header = BytesIO()
#
# Use FMP capsule GUID: 6DCBD5ED-E82D-4C44-BDA1-7194199AD92A
#
@@ -97,7 +97,7 @@ class Capsule (CapsuleClassObject) :
# // UINT64 ItemOffsetList[];
# } EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER;
#
- FwMgrHdr = StringIO.StringIO()
+ FwMgrHdr = BytesIO()
if 'CAPSULE_HEADER_INIT_VERSION' in self.TokensDict:
FwMgrHdr.write(pack('=I', int(self.TokensDict['CAPSULE_HEADER_INIT_VERSION'], 16)))
else:
@@ -132,7 +132,7 @@ class Capsule (CapsuleClassObject) :
#
PreSize = FwMgrHdrSize
- Content = StringIO.StringIO()
+ Content = BytesIO()
for driver in self.CapsuleDataList:
FileName = driver.GenCapsuleSubItem()
FwMgrHdr.write(pack('=Q', PreSize))
@@ -247,7 +247,7 @@ class Capsule (CapsuleClassObject) :
def GenCapInf(self):
self.CapInfFileName = os.path.join(GenFdsGlobalVariable.FvDir,
self.UiCapsuleName + "_Cap" + '.inf')
- CapInfFile = StringIO.StringIO() #open (self.CapInfFileName , 'w+')
+ CapInfFile = BytesIO() #open (self.CapInfFileName , 'w+')
CapInfFile.writelines("[options]" + T_CHAR_LF)
diff --git a/BaseTools/Source/Python/GenFds/CapsuleData.py b/BaseTools/Source/Python/GenFds/CapsuleData.py
index 9dc55e5dbf..83b2731110 100644
--- a/BaseTools/Source/Python/GenFds/CapsuleData.py
+++ b/BaseTools/Source/Python/GenFds/CapsuleData.py
@@ -17,7 +17,7 @@
#
import Ffs
from GenFdsGlobalVariable import GenFdsGlobalVariable
-import StringIO
+from io import BytesIO
from struct import pack
import os
from Common.Misc import SaveFileOnChange
@@ -82,7 +82,7 @@ class CapsuleFv (CapsuleData):
if self.FvName.find('.fv') == -1:
if self.FvName.upper() in GenFdsGlobalVariable.FdfParser.Profile.FvDict:
FvObj = GenFdsGlobalVariable.FdfParser.Profile.FvDict[self.FvName.upper()]
- FdBuffer = StringIO.StringIO('')
+ FdBuffer = BytesIO('')
FvObj.CapsuleName = self.CapsuleName
FvFile = FvObj.AddToBuffer(FdBuffer)
FvObj.CapsuleName = None
diff --git a/BaseTools/Source/Python/GenFds/Fd.py b/BaseTools/Source/Python/GenFds/Fd.py
index b2a14a1e13..3305a470ed 100644
--- a/BaseTools/Source/Python/GenFds/Fd.py
+++ b/BaseTools/Source/Python/GenFds/Fd.py
@@ -18,7 +18,7 @@
import Region
import Fv
import Common.LongFilePathOs as os
-import StringIO
+from io import BytesIO
import sys
from struct import *
from GenFdsGlobalVariable import GenFdsGlobalVariable
@@ -75,7 +75,7 @@ class FD(FDClassObject):
HasCapsuleRegion = True
break
if HasCapsuleRegion:
- TempFdBuffer = StringIO.StringIO('')
+ TempFdBuffer = BytesIO('')
PreviousRegionStart = -1
PreviousRegionSize = 1
@@ -104,7 +104,7 @@ class FD(FDClassObject):
GenFdsGlobalVariable.VerboseLogger('Call each region\'s AddToBuffer function')
RegionObj.AddToBuffer (TempFdBuffer, self.BaseAddress, self.BlockSizeList, self.ErasePolarity, GenFds.ImageBinDict, self.vtfRawDict, self.DefineVarDict)
- FdBuffer = StringIO.StringIO('')
+ FdBuffer = BytesIO('')
PreviousRegionStart = -1
PreviousRegionSize = 1
for RegionObj in self.RegionList :
diff --git a/BaseTools/Source/Python/GenFds/FfsFileStatement.py b/BaseTools/Source/Python/GenFds/FfsFileStatement.py
index ba8e0465ef..f5de57d0ac 100644
--- a/BaseTools/Source/Python/GenFds/FfsFileStatement.py
+++ b/BaseTools/Source/Python/GenFds/FfsFileStatement.py
@@ -18,7 +18,7 @@
import Ffs
import Rule
import Common.LongFilePathOs as os
-import StringIO
+from io import BytesIO
import subprocess
from GenFdsGlobalVariable import GenFdsGlobalVariable
@@ -82,7 +82,7 @@ class FileStatement (FileStatementClassObject) :
Dict.update(self.DefineVarDict)
SectionAlignments = None
if self.FvName is not None :
- Buffer = StringIO.StringIO('')
+ Buffer = BytesIO('')
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())
diff --git a/BaseTools/Source/Python/GenFds/FfsInfStatement.py b/BaseTools/Source/Python/GenFds/FfsInfStatement.py
index 9eb99d659b..ef34dbf007 100644
--- a/BaseTools/Source/Python/GenFds/FfsInfStatement.py
+++ b/BaseTools/Source/Python/GenFds/FfsInfStatement.py
@@ -18,7 +18,7 @@
#
import Rule
import Common.LongFilePathOs as os
-import StringIO
+from io import BytesIO
from struct import *
from GenFdsGlobalVariable import GenFdsGlobalVariable
import Ffs
@@ -1088,7 +1088,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
def __GenUniVfrOffsetFile(VfrUniOffsetList, UniVfrOffsetFileName):
# Use a instance of StringIO to cache data
- fStringIO = StringIO.StringIO('')
+ fStringIO = BytesIO('')
for Item in VfrUniOffsetList:
if (Item[0].find("Strings") != -1):
diff --git a/BaseTools/Source/Python/GenFds/Fv.py b/BaseTools/Source/Python/GenFds/Fv.py
index fb82634ccd..d980020680 100644
--- a/BaseTools/Source/Python/GenFds/Fv.py
+++ b/BaseTools/Source/Python/GenFds/Fv.py
@@ -17,7 +17,7 @@
#
import Common.LongFilePathOs as os
import subprocess
-import StringIO
+from io import BytesIO
from struct import *
import Ffs
@@ -265,7 +265,7 @@ class FV (FvClassObject):
#
self.InfFileName = os.path.join(GenFdsGlobalVariable.FvDir,
self.UiFvName + '.inf')
- self.FvInfFile = StringIO.StringIO()
+ self.FvInfFile = BytesIO()
#
# Add [Options]
@@ -407,7 +407,7 @@ class FV (FvClassObject):
#
if TotalSize > 0:
FvExtHeaderFileName = os.path.join(GenFdsGlobalVariable.FvDir, self.UiFvName + '.ext')
- FvExtHeaderFile = StringIO.StringIO()
+ FvExtHeaderFile = BytesIO()
FvExtHeaderFile.write(Buffer)
Changed = SaveFileOnChange(FvExtHeaderFileName, FvExtHeaderFile.getvalue(), True)
FvExtHeaderFile.close()
diff --git a/BaseTools/Source/Python/GenFds/FvImageSection.py b/BaseTools/Source/Python/GenFds/FvImageSection.py
index 77bf6a7006..b4f1f3340e 100644
--- a/BaseTools/Source/Python/GenFds/FvImageSection.py
+++ b/BaseTools/Source/Python/GenFds/FvImageSection.py
@@ -16,7 +16,7 @@
# Import Modules
#
import Section
-import StringIO
+from io import BytesIO
from Ffs import Ffs
import subprocess
from GenFdsGlobalVariable import GenFdsGlobalVariable
@@ -98,7 +98,7 @@ class FvImageSection(FvImageSectionClassObject):
# Generate Fv
#
if self.FvName is not None:
- Buffer = StringIO.StringIO('')
+ Buffer = BytesIO('')
Fv = GenFdsGlobalVariable.FdfParser.Profile.FvDict.get(self.FvName)
if Fv is not None:
self.Fv = Fv
diff --git a/BaseTools/Source/Python/GenFds/GenFds.py b/BaseTools/Source/Python/GenFds/GenFds.py
index 912e6c58f4..acd19e5276 100644
--- a/BaseTools/Source/Python/GenFds/GenFds.py
+++ b/BaseTools/Source/Python/GenFds/GenFds.py
@@ -27,7 +27,7 @@ from Workspace.WorkspaceDatabase import WorkspaceDatabase
from Workspace.BuildClassObject import PcdClassObject
import RuleComplexFile
from EfiSection import EfiSection
-import StringIO
+from io import BytesIO
import Common.TargetTxtClassObject as TargetTxtClassObject
import Common.ToolDefClassObject as ToolDefClassObject
from Common.DataType import *
@@ -542,13 +542,13 @@ class GenFds :
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()
+ Buffer = BytesIO()
FvObj.AddToBuffer(Buffer)
Buffer.close()
return
elif GenFds.OnlyGenerateThisFv is None:
for FvObj in GenFdsGlobalVariable.FdfParser.Profile.FvDict.values():
- Buffer = StringIO.StringIO('')
+ Buffer = BytesIO('')
FvObj.AddToBuffer(Buffer)
Buffer.close()
@@ -694,7 +694,7 @@ class GenFds :
def GenerateGuidXRefFile(BuildDb, ArchList, FdfParserObj):
GuidXRefFileName = os.path.join(GenFdsGlobalVariable.FvDir, "Guid.xref")
- GuidXRefFile = StringIO.StringIO('')
+ GuidXRefFile = BytesIO('')
GuidDict = {}
ModuleList = []
FileGuidList = []
diff --git a/BaseTools/Source/Python/GenFds/OptionRom.py b/BaseTools/Source/Python/GenFds/OptionRom.py
index b058415299..755eb01da7 100644
--- a/BaseTools/Source/Python/GenFds/OptionRom.py
+++ b/BaseTools/Source/Python/GenFds/OptionRom.py
@@ -17,7 +17,6 @@
#
import Common.LongFilePathOs as os
import subprocess
-import StringIO
import OptRomInfStatement
from GenFdsGlobalVariable import GenFdsGlobalVariable
@@ -138,5 +137,3 @@ class OverrideAttribs:
self.PciDeviceId = None
self.PciRevision = None
self.NeedCompress = None
-
- \ No newline at end of file
diff --git a/BaseTools/Source/Python/GenFds/Region.py b/BaseTools/Source/Python/GenFds/Region.py
index 9d632b6321..3b7e30ec85 100644
--- a/BaseTools/Source/Python/GenFds/Region.py
+++ b/BaseTools/Source/Python/GenFds/Region.py
@@ -17,7 +17,7 @@
#
from struct import *
from GenFdsGlobalVariable import GenFdsGlobalVariable
-import StringIO
+from io import BytesIO
import string
from CommonDataClass.FdfClass import RegionClassObject
import Common.LongFilePathOs as os
@@ -127,7 +127,7 @@ class Region(RegionClassObject):
if self.FvAddress % FvAlignValue != 0:
EdkLogger.error("GenFds", GENFDS_ERROR,
"FV (%s) is NOT %s Aligned!" % (FvObj.UiFvName, FvObj.FvAlignment))
- FvBuffer = StringIO.StringIO('')
+ FvBuffer = BytesIO('')
FvBaseAddress = '0x%X' % self.FvAddress
BlockSize = None
BlockNum = None
@@ -135,7 +135,8 @@ class Region(RegionClassObject):
if Flag:
continue
- if FvBuffer.len > Size:
+ FvBufferLen = len(FvBuffer.getvalue())
+ if FvBufferLen > Size:
FvBuffer.close()
EdkLogger.error("GenFds", GENFDS_ERROR,
"Size of FV (%s) is larger than Region Size 0x%X specified." % (RegionData, Size))
@@ -144,8 +145,8 @@ class Region(RegionClassObject):
#
Buffer.write(FvBuffer.getvalue())
FvBuffer.close()
- FvOffset = FvOffset + FvBuffer.len
- Size = Size - FvBuffer.len
+ FvOffset = FvOffset + FvBufferLen
+ Size = Size - FvBufferLen
continue
else:
EdkLogger.error("GenFds", GENFDS_ERROR, "FV (%s) is NOT described in FDF file!" % (RegionData))