summaryrefslogtreecommitdiffstats
path: root/BaseTools/Source/Python/UPT
diff options
context:
space:
mode:
authorYonghong Zhu <yonghong.zhu@intel.com>2018-09-04 10:39:47 +0800
committerYonghong Zhu <yonghong.zhu@intel.com>2018-10-13 09:57:16 +0800
commit1b2e077260030290c512f3ac71a044ed1150899f (patch)
tree4834e04cda1ed358ce20dd24906af28665907e8c /BaseTools/Source/Python/UPT
parent9d7e1e56a727743a811abfed92e1ede39ecbfa8c (diff)
downloadedk2-1b2e077260030290c512f3ac71a044ed1150899f.tar.gz
edk2-1b2e077260030290c512f3ac71a044ed1150899f.tar.bz2
edk2-1b2e077260030290c512f3ac71a044ed1150899f.zip
BaseTools/UPT: Porting UPT Tool from Python2 to Python3
Cc: Liming Gao <liming.gao@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Yonghong Zhu <yonghong.zhu@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com>
Diffstat (limited to 'BaseTools/Source/Python/UPT')
-rw-r--r--BaseTools/Source/Python/UPT/Core/FileHook.py2
-rw-r--r--BaseTools/Source/Python/UPT/Core/IpiDb.py2
-rw-r--r--BaseTools/Source/Python/UPT/GenMetaFile/GenDecFile.py18
-rw-r--r--BaseTools/Source/Python/UPT/GenMetaFile/GenInfFile.py18
-rw-r--r--BaseTools/Source/Python/UPT/Library/CommentGenerating.py40
-rw-r--r--BaseTools/Source/Python/UPT/Library/CommentParsing.py9
-rw-r--r--BaseTools/Source/Python/UPT/Library/ExpressionValidate.py1
-rw-r--r--BaseTools/Source/Python/UPT/Library/Misc.py24
-rw-r--r--BaseTools/Source/Python/UPT/Library/ParserValidate.py2
-rw-r--r--BaseTools/Source/Python/UPT/Library/Parsing.py3
-rw-r--r--BaseTools/Source/Python/UPT/Library/StringUtils.py13
-rw-r--r--BaseTools/Source/Python/UPT/Library/UniClassObject.py21
-rw-r--r--BaseTools/Source/Python/UPT/Logger/StringTable.py2
-rw-r--r--BaseTools/Source/Python/UPT/MkPkg.py2
-rw-r--r--BaseTools/Source/Python/UPT/Parser/DecParser.py8
-rw-r--r--BaseTools/Source/Python/UPT/Parser/DecParserMisc.py4
-rw-r--r--BaseTools/Source/Python/UPT/Parser/InfAsBuiltProcess.py2
-rw-r--r--BaseTools/Source/Python/UPT/Parser/InfParser.py4
-rw-r--r--BaseTools/Source/Python/UPT/Parser/InfSectionParser.py6
-rw-r--r--BaseTools/Source/Python/UPT/PomAdapter/DecPomAlignment.py1
-rw-r--r--BaseTools/Source/Python/UPT/UPT.py4
-rw-r--r--BaseTools/Source/Python/UPT/UnitTest/DecParserTest.py1
-rw-r--r--BaseTools/Source/Python/UPT/UnitTest/InfBinarySectionTest.py1
-rw-r--r--BaseTools/Source/Python/UPT/Xml/IniToXml.py2
-rw-r--r--BaseTools/Source/Python/UPT/Xml/XmlParserMisc.py2
25 files changed, 89 insertions, 103 deletions
diff --git a/BaseTools/Source/Python/UPT/Core/FileHook.py b/BaseTools/Source/Python/UPT/Core/FileHook.py
index ceae12fb37..247dc4bd34 100644
--- a/BaseTools/Source/Python/UPT/Core/FileHook.py
+++ b/BaseTools/Source/Python/UPT/Core/FileHook.py
@@ -66,7 +66,7 @@ class RecoverMgr:
arc = self._tryhook(path)
if arc and os.path.isfile(path):
self._createzip()
- self.zip.write(path, arc.encode('utf_8'))
+ self.zip.write(path, arc)
sta = os.stat(path)
oldmode = stat.S_IMODE(sta.st_mode)
self.rlist.append(_PathInfo(_CHMOD, path, oldmode))
diff --git a/BaseTools/Source/Python/UPT/Core/IpiDb.py b/BaseTools/Source/Python/UPT/Core/IpiDb.py
index a781d358c8..6c85c9756c 100644
--- a/BaseTools/Source/Python/UPT/Core/IpiDb.py
+++ b/BaseTools/Source/Python/UPT/Core/IpiDb.py
@@ -44,7 +44,7 @@ class IpiDatabase(object):
Dir = os.path.dirname(DbPath)
if not os.path.isdir(Dir):
os.mkdir(Dir)
- self.Conn = sqlite3.connect(unicode(DbPath), isolation_level='DEFERRED')
+ self.Conn = sqlite3.connect(DbPath, isolation_level='DEFERRED')
self.Conn.execute("PRAGMA page_size=4096")
self.Conn.execute("PRAGMA synchronous=OFF")
self.Cur = self.Conn.cursor()
diff --git a/BaseTools/Source/Python/UPT/GenMetaFile/GenDecFile.py b/BaseTools/Source/Python/UPT/GenMetaFile/GenDecFile.py
index e2dd6a02dc..a377dce9d9 100644
--- a/BaseTools/Source/Python/UPT/GenMetaFile/GenDecFile.py
+++ b/BaseTools/Source/Python/UPT/GenMetaFile/GenDecFile.py
@@ -585,17 +585,17 @@ def GenPackageUNIEncodeFile(PackageObject, UniFileHeader = '', Encoding=TAB_ENCO
ContainerFile = GetUniFileName(os.path.dirname(PackageObject.GetFullPath()), PackageObject.GetBaseName())
- Content = UniFileHeader + '\r\n'
- Content += '\r\n'
+ Content = UniFileHeader + '\n'
+ Content += '\n'
- Content += FormatUniEntry('#string ' + TAB_DEC_PACKAGE_ABSTRACT, PackageObject.GetAbstract(), ContainerFile) + '\r\n'
+ Content += FormatUniEntry('#string ' + TAB_DEC_PACKAGE_ABSTRACT, PackageObject.GetAbstract(), ContainerFile) + '\n'
Content += FormatUniEntry('#string ' + TAB_DEC_PACKAGE_DESCRIPTION, PackageObject.GetDescription(), ContainerFile) \
- + '\r\n'
+ + '\n'
- Content += FormatUniEntry('#string ' + TAB_DEC_BINARY_ABSTRACT, BinaryAbstract, ContainerFile) + '\r\n'
+ Content += FormatUniEntry('#string ' + TAB_DEC_BINARY_ABSTRACT, BinaryAbstract, ContainerFile) + '\n'
- Content += FormatUniEntry('#string ' + TAB_DEC_BINARY_DESCRIPTION, BinaryDescription, ContainerFile) + '\r\n'
+ Content += FormatUniEntry('#string ' + TAB_DEC_BINARY_DESCRIPTION, BinaryDescription, ContainerFile) + '\n'
PromptGenList = []
HelpTextGenList = []
@@ -612,7 +612,7 @@ def GenPackageUNIEncodeFile(PackageObject, UniFileHeader = '', Encoding=TAB_ENCO
if (PcdPromptStrName, Lang) not in PromptGenList:
TokenValueList.append((Lang, PromptStr))
PromptGenList.append((PcdPromptStrName, Lang))
- PromptString = FormatUniEntry(PcdPromptStrName, TokenValueList, ContainerFile) + '\r\n'
+ PromptString = FormatUniEntry(PcdPromptStrName, TokenValueList, ContainerFile) + '\n'
if PromptString not in Content:
Content += PromptString
@@ -628,7 +628,7 @@ def GenPackageUNIEncodeFile(PackageObject, UniFileHeader = '', Encoding=TAB_ENCO
if (PcdHelpStrName, Lang) not in HelpTextGenList:
TokenValueList.append((Lang, HelpStr))
HelpTextGenList.append((PcdHelpStrName, Lang))
- HelpTextString = FormatUniEntry(PcdHelpStrName, TokenValueList, ContainerFile) + '\r\n'
+ HelpTextString = FormatUniEntry(PcdHelpStrName, TokenValueList, ContainerFile) + '\n'
if HelpTextString not in Content:
Content += HelpTextString
@@ -639,7 +639,7 @@ def GenPackageUNIEncodeFile(PackageObject, UniFileHeader = '', Encoding=TAB_ENCO
PcdErrStrName = '#string ' + TAB_STR_TOKENCNAME + TAB_UNDERLINE_SPLIT + Pcd.GetTokenSpaceGuidCName() \
+ TAB_UNDERLINE_SPLIT + TAB_STR_TOKENERR \
+ TAB_UNDERLINE_SPLIT + ErrorNo[2:]
- PcdErrString = FormatUniEntry(PcdErrStrName, PcdError.GetErrorMessageList(), ContainerFile) + '\r\n'
+ PcdErrString = FormatUniEntry(PcdErrStrName, PcdError.GetErrorMessageList(), ContainerFile) + '\n'
if PcdErrString not in Content:
Content += PcdErrString
diff --git a/BaseTools/Source/Python/UPT/GenMetaFile/GenInfFile.py b/BaseTools/Source/Python/UPT/GenMetaFile/GenInfFile.py
index c2a240a884..82df4c62cf 100644
--- a/BaseTools/Source/Python/UPT/GenMetaFile/GenInfFile.py
+++ b/BaseTools/Source/Python/UPT/GenMetaFile/GenInfFile.py
@@ -234,22 +234,22 @@ def GenModuleUNIEncodeFile(ModuleObject, UniFileHeader='', Encoding=DT.TAB_ENCOD
if not os.path.exists(os.path.dirname(ModuleObject.GetFullPath())):
os.makedirs(os.path.dirname(ModuleObject.GetFullPath()))
- Content = UniFileHeader + '\r\n'
- Content += '\r\n'
+ Content = UniFileHeader + '\n'
+ Content += '\n'
- Content += FormatUniEntry('#string ' + DT.TAB_INF_ABSTRACT, ModuleObject.GetAbstract(), ContainerFile) + '\r\n'
+ Content += FormatUniEntry('#string ' + DT.TAB_INF_ABSTRACT, ModuleObject.GetAbstract(), ContainerFile) + '\n'
Content += FormatUniEntry('#string ' + DT.TAB_INF_DESCRIPTION, ModuleObject.GetDescription(), ContainerFile) \
- + '\r\n'
+ + '\n'
BinaryAbstractString = FormatUniEntry('#string ' + DT.TAB_INF_BINARY_ABSTRACT, BinaryAbstract, ContainerFile)
if BinaryAbstractString:
- Content += BinaryAbstractString + '\r\n'
+ Content += BinaryAbstractString + '\n'
BinaryDescriptionString = FormatUniEntry('#string ' + DT.TAB_INF_BINARY_DESCRIPTION, BinaryDescription, \
ContainerFile)
if BinaryDescriptionString:
- Content += BinaryDescriptionString + '\r\n'
+ Content += BinaryDescriptionString + '\n'
if not os.path.exists(ContainerFile):
File = codecs.open(ContainerFile, 'wb', Encoding)
@@ -274,7 +274,7 @@ def GenDefines(ModuleObject):
if not DefinesDict:
continue
for Statement in DefinesDict:
- if Statement.split(DT.TAB_EQUAL_SPLIT) > 1:
+ if len(Statement.split(DT.TAB_EQUAL_SPLIT)) > 1:
Statement = (u'%s ' % Statement.split(DT.TAB_EQUAL_SPLIT, 1)[0]).ljust(LeftOffset) \
+ u'= %s' % Statement.split(DT.TAB_EQUAL_SPLIT, 1)[1].lstrip()
SortedArch = DT.TAB_ARCH_COMMON
@@ -409,7 +409,7 @@ def GenLibraryClasses(ModuleObject):
Statement += '|' + FFE
ModuleList = LibraryClass.GetSupModuleList()
ArchList = LibraryClass.GetSupArchList()
- for Index in xrange(0, len(ArchList)):
+ for Index in range(0, len(ArchList)):
ArchList[Index] = ConvertArchForInstall(ArchList[Index])
ArchList.sort()
SortedArch = ' '.join(ArchList)
@@ -572,7 +572,7 @@ def GenUserExtensions(ModuleObject):
# if not Statement:
# continue
ArchList = UserExtension.GetSupArchList()
- for Index in xrange(0, len(ArchList)):
+ for Index in range(0, len(ArchList)):
ArchList[Index] = ConvertArchForInstall(ArchList[Index])
ArchList.sort()
KeyList = []
diff --git a/BaseTools/Source/Python/UPT/Library/CommentGenerating.py b/BaseTools/Source/Python/UPT/Library/CommentGenerating.py
index 4726629695..78d3c91581 100644
--- a/BaseTools/Source/Python/UPT/Library/CommentGenerating.py
+++ b/BaseTools/Source/Python/UPT/Library/CommentGenerating.py
@@ -124,50 +124,46 @@ def GenHeaderCommentSection(Abstract, Description, Copyright, License, IsBinaryH
#
# Convert special character to (c), (r) and (tm).
#
- if isinstance(Abstract, unicode):
- Abstract = ConvertSpecialUnicodes(Abstract)
- if isinstance(Description, unicode):
- Description = ConvertSpecialUnicodes(Description)
if IsBinaryHeader:
- Content += CommChar * 2 + TAB_SPACE_SPLIT + TAB_BINARY_HEADER_COMMENT + '\r\n'
+ Content += CommChar * 2 + TAB_SPACE_SPLIT + TAB_BINARY_HEADER_COMMENT + '\n'
elif CommChar == TAB_COMMENT_EDK1_SPLIT:
Content += CommChar + TAB_SPACE_SPLIT + TAB_COMMENT_EDK1_START + TAB_STAR + TAB_SPACE_SPLIT +\
- TAB_HEADER_COMMENT + '\r\n'
+ TAB_HEADER_COMMENT + '\n'
else:
- Content += CommChar * 2 + TAB_SPACE_SPLIT + TAB_HEADER_COMMENT + '\r\n'
+ Content += CommChar * 2 + TAB_SPACE_SPLIT + TAB_HEADER_COMMENT + '\n'
if Abstract:
- Abstract = Abstract.rstrip('\r\n')
- Content += CommChar + TAB_SPACE_SPLIT + ('\r\n' + CommChar + TAB_SPACE_SPLIT).join(GetSplitValueList\
+ Abstract = Abstract.rstrip('\n')
+ Content += CommChar + TAB_SPACE_SPLIT + ('\n' + CommChar + TAB_SPACE_SPLIT).join(GetSplitValueList\
(Abstract, '\n'))
- Content += '\r\n' + CommChar + '\r\n'
+ Content += '\n' + CommChar + '\n'
else:
- Content += CommChar + '\r\n'
+ Content += CommChar + '\n'
if Description:
- Description = Description.rstrip('\r\n')
- Content += CommChar + TAB_SPACE_SPLIT + ('\r\n' + CommChar + TAB_SPACE_SPLIT).join(GetSplitValueList\
+ Description = Description.rstrip('\n')
+ Content += CommChar + TAB_SPACE_SPLIT + ('\n' + CommChar + TAB_SPACE_SPLIT).join(GetSplitValueList\
(Description, '\n'))
- Content += '\r\n' + CommChar + '\r\n'
+ Content += '\n' + CommChar + '\n'
#
# There is no '#\n' line to separate multiple copyright lines in code base
#
if Copyright:
- Copyright = Copyright.rstrip('\r\n')
- Content += CommChar + TAB_SPACE_SPLIT + ('\r\n' + CommChar + TAB_SPACE_SPLIT).join\
+ Copyright = Copyright.rstrip('\n')
+ Content += CommChar + TAB_SPACE_SPLIT + ('\n' + CommChar + TAB_SPACE_SPLIT).join\
(GetSplitValueList(Copyright, '\n'))
- Content += '\r\n' + CommChar + '\r\n'
+ Content += '\n' + CommChar + '\n'
if License:
- License = License.rstrip('\r\n')
- Content += CommChar + TAB_SPACE_SPLIT + ('\r\n' + CommChar + TAB_SPACE_SPLIT).join(GetSplitValueList\
+ License = License.rstrip('\n')
+ Content += CommChar + TAB_SPACE_SPLIT + ('\n' + CommChar + TAB_SPACE_SPLIT).join(GetSplitValueList\
(License, '\n'))
- Content += '\r\n' + CommChar + '\r\n'
+ Content += '\n' + CommChar + '\n'
if CommChar == TAB_COMMENT_EDK1_SPLIT:
- Content += CommChar + TAB_SPACE_SPLIT + TAB_STAR + TAB_COMMENT_EDK1_END + '\r\n'
+ Content += CommChar + TAB_SPACE_SPLIT + TAB_STAR + TAB_COMMENT_EDK1_END + '\n'
else:
- Content += CommChar * 2 + '\r\n'
+ Content += CommChar * 2 + '\n'
return Content
diff --git a/BaseTools/Source/Python/UPT/Library/CommentParsing.py b/BaseTools/Source/Python/UPT/Library/CommentParsing.py
index 285812c9c2..8f9fec7595 100644
--- a/BaseTools/Source/Python/UPT/Library/CommentParsing.py
+++ b/BaseTools/Source/Python/UPT/Library/CommentParsing.py
@@ -74,7 +74,7 @@ def ParseHeaderCommentSection(CommentList, FileName = None, IsBinaryHeader = Fal
# first find the last copyright line
#
Last = 0
- for Index in xrange(len(CommentList)-1, 0, -1):
+ for Index in range(len(CommentList)-1, 0, -1):
Line = CommentList[Index][0]
if _IsCopyrightLine(Line):
Last = Index
@@ -206,17 +206,14 @@ def ParsePcdErrorCode (Value = None, ContainerFile = None, LineNum = None):
Base = 16
else:
Base = 10
- ErrorCode = long(Value, Base)
+ ErrorCode = int(Value, Base)
if ErrorCode > PCD_ERR_CODE_MAX_SIZE or ErrorCode < 0:
Logger.Error('Parser',
FORMAT_NOT_SUPPORTED,
"The format %s of ErrorCode is not valid, should be UNIT32 type or long type" % Value,
File = ContainerFile,
Line = LineNum)
- #
- # To delete the tailing 'L'
- #
- return hex(ErrorCode)[:-1]
+ return hex(ErrorCode)
except ValueError as XStr:
if XStr:
pass
diff --git a/BaseTools/Source/Python/UPT/Library/ExpressionValidate.py b/BaseTools/Source/Python/UPT/Library/ExpressionValidate.py
index 2e0253ab51..35b963ed0f 100644
--- a/BaseTools/Source/Python/UPT/Library/ExpressionValidate.py
+++ b/BaseTools/Source/Python/UPT/Library/ExpressionValidate.py
@@ -14,7 +14,6 @@
'''
ExpressionValidate
'''
-from __future__ import print_function
##
# Import Modules
diff --git a/BaseTools/Source/Python/UPT/Library/Misc.py b/BaseTools/Source/Python/UPT/Library/Misc.py
index 8c2a6787f0..f9ca8f32e0 100644
--- a/BaseTools/Source/Python/UPT/Library/Misc.py
+++ b/BaseTools/Source/Python/UPT/Library/Misc.py
@@ -32,7 +32,7 @@ from os import linesep
from os import walk
from os import environ
import re
-from UserDict import IterableUserDict
+from collections import UserDict as IterableUserDict
import Logger.Log as Logger
from Logger import StringTable as ST
@@ -160,19 +160,23 @@ def RemoveDirectory(Directory, Recursively=False):
# or not
#
def SaveFileOnChange(File, Content, IsBinaryFile=True):
- if not IsBinaryFile:
- Content = Content.replace("\n", linesep)
-
if os.path.exists(File):
try:
- if Content == __FileHookOpen__(File, "rb").read():
- return False
+ if isinstance(Content, bytes):
+ if Content == __FileHookOpen__(File, "rb").read():
+ return False
+ else:
+ if Content == __FileHookOpen__(File, "r").read():
+ return False
except BaseException:
Logger.Error(None, ToolError.FILE_OPEN_FAILURE, ExtraData=File)
CreateDirectory(os.path.dirname(File))
try:
- FileFd = __FileHookOpen__(File, "wb")
+ if isinstance(Content, bytes):
+ FileFd = __FileHookOpen__(File, "wb")
+ else:
+ FileFd = __FileHookOpen__(File, "w")
FileFd.write(Content)
FileFd.close()
except BaseException:
@@ -437,7 +441,7 @@ class Sdict(IterableUserDict):
def CommonPath(PathList):
Path1 = min(PathList).split(os.path.sep)
Path2 = max(PathList).split(os.path.sep)
- for Index in xrange(min(len(Path1), len(Path2))):
+ for Index in range(min(len(Path1), len(Path2))):
if Path1[Index] != Path2[Index]:
return os.path.sep.join(Path1[:Index])
return os.path.sep.join(Path1)
@@ -890,7 +894,7 @@ def ProcessEdkComment(LineList):
if FindEdkBlockComment:
if FirstPos == -1:
FirstPos = StartPos
- for Index in xrange(StartPos, EndPos+1):
+ for Index in range(StartPos, EndPos+1):
LineList[Index] = ''
FindEdkBlockComment = False
elif Line.find("//") != -1 and not Line.startswith("#"):
@@ -957,7 +961,7 @@ def GetLibInstanceInfo(String, WorkSpace, LineNo):
FileLinesList = []
try:
- FInputfile = open(FullFileName, "rb", 0)
+ FInputfile = open(FullFileName, "r")
try:
FileLinesList = FInputfile.readlines()
except BaseException:
diff --git a/BaseTools/Source/Python/UPT/Library/ParserValidate.py b/BaseTools/Source/Python/UPT/Library/ParserValidate.py
index 31b9b68cd5..87d156fa4c 100644
--- a/BaseTools/Source/Python/UPT/Library/ParserValidate.py
+++ b/BaseTools/Source/Python/UPT/Library/ParserValidate.py
@@ -727,7 +727,7 @@ def IsValidUserId(UserId):
#
def CheckUTF16FileHeader(File):
FileIn = open(File, 'rb').read(2)
- if FileIn != '\xff\xfe':
+ if FileIn != b'\xff\xfe':
return False
return True
diff --git a/BaseTools/Source/Python/UPT/Library/Parsing.py b/BaseTools/Source/Python/UPT/Library/Parsing.py
index 81729d6cdb..0564080d35 100644
--- a/BaseTools/Source/Python/UPT/Library/Parsing.py
+++ b/BaseTools/Source/Python/UPT/Library/Parsing.py
@@ -16,7 +16,6 @@
'''
Parsing
'''
-from __future__ import absolute_import
##
# Import Modules
@@ -974,7 +973,7 @@ def GenSection(SectionName, SectionDict, SplitArch=True, NeedBlankLine=False):
ArchList = GetSplitValueList(SectionAttrs, DataType.TAB_COMMENT_SPLIT)
else:
ArchList = [SectionAttrs]
- for Index in xrange(0, len(ArchList)):
+ for Index in range(0, len(ArchList)):
ArchList[Index] = ConvertArchForInstall(ArchList[Index])
Section = '[' + SectionName + '.' + (', ' + SectionName + '.').join(ArchList) + ']'
else:
diff --git a/BaseTools/Source/Python/UPT/Library/StringUtils.py b/BaseTools/Source/Python/UPT/Library/StringUtils.py
index c2148a44fb..011eb98ca6 100644
--- a/BaseTools/Source/Python/UPT/Library/StringUtils.py
+++ b/BaseTools/Source/Python/UPT/Library/StringUtils.py
@@ -20,7 +20,6 @@ StringUtils
#
import re
import os.path
-from string import strip
import Logger.Log as Logger
import Library.DataType as DataType
from Logger.ToolError import FORMAT_INVALID
@@ -44,7 +43,7 @@ gMACRO_PATTERN = re.compile("\$\(([_A-Z][_A-Z0-9]*)\)", re.UNICODE)
#
#
def GetSplitValueList(String, SplitTag=DataType.TAB_VALUE_SPLIT, MaxSplit= -1):
- return map(lambda l: l.strip(), String.split(SplitTag, MaxSplit))
+ return list(map(lambda l: l.strip(), String.split(SplitTag, MaxSplit)))
## MergeArches
#
@@ -435,7 +434,7 @@ def GetSingleValueOfKeyFromLines(Lines, Dictionary, CommentCharacter, KeySplitCh
#
LineList[1] = CleanString(LineList[1], CommentCharacter)
if ValueSplitFlag:
- Value = map(strip, LineList[1].split(ValueSplitCharacter))
+ Value = map(lambda x: x.strip(), LineList[1].split(ValueSplitCharacter))
else:
Value = CleanString(LineList[1], CommentCharacter).splitlines()
@@ -502,7 +501,7 @@ def PreCheck(FileName, FileContent, SupSectionTag):
#
# Regenerate FileContent
#
- NewFileContent = NewFileContent + Line + '\r\n'
+ NewFileContent = NewFileContent + Line + '\n'
if IsFailed:
Logger.Error("Parser", FORMAT_INVALID, Line=LineNo, File=FileName, RaiseError=Logger.IS_RAISE_ERROR)
@@ -938,14 +937,14 @@ def SplitPcdEntry(String):
def IsMatchArch(Arch1, Arch2):
if 'COMMON' in Arch1 or 'COMMON' in Arch2:
return True
- if isinstance(Arch1, basestring) and isinstance(Arch2, basestring):
+ if isinstance(Arch1, str) and isinstance(Arch2, str):
if Arch1 == Arch2:
return True
- if isinstance(Arch1, basestring) and isinstance(Arch2, list):
+ if isinstance(Arch1, str) and isinstance(Arch2, list):
return Arch1 in Arch2
- if isinstance(Arch2, basestring) and isinstance(Arch1, list):
+ if isinstance(Arch2, str) and isinstance(Arch1, list):
return Arch2 in Arch1
if isinstance(Arch1, list) and isinstance(Arch2, list):
diff --git a/BaseTools/Source/Python/UPT/Library/UniClassObject.py b/BaseTools/Source/Python/UPT/Library/UniClassObject.py
index 670cf3b4ee..549f278b05 100644
--- a/BaseTools/Source/Python/UPT/Library/UniClassObject.py
+++ b/BaseTools/Source/Python/UPT/Library/UniClassObject.py
@@ -14,7 +14,6 @@
"""
Collect all defined strings in multiple uni files
"""
-from __future__ import print_function
##
# Import Modules
@@ -247,9 +246,9 @@ def FormatUniEntry(StrTokenName, TokenValueList, ContainerFile):
for SubValue in ValueList:
if SubValue.strip():
SubValueContent += \
- ' ' * (PreFormatLength + len('#language en-US ')) + '\"%s\\n\"' % SubValue.strip() + '\r\n'
+ ' ' * (PreFormatLength + len('#language en-US ')) + '\"%s\\n\"' % SubValue.strip() + '\n'
SubValueContent = SubValueContent[(PreFormatLength + len('#language en-US ')):SubValueContent.rfind('\\n')] \
- + '\"' + '\r\n'
+ + '\"' + '\n'
SubContent += ' '*PreFormatLength + '#language %-5s ' % Lang + SubValueContent
if SubContent:
SubContent = StrTokenName + ' '*(PreFormatLength - len(StrTokenName)) + SubContent[PreFormatLength:]
@@ -291,7 +290,7 @@ class StringDefClassObject(object):
def UpdateValue(self, Value = None):
if Value is not None:
if self.StringValue:
- self.StringValue = self.StringValue + '\r\n' + Value
+ self.StringValue = self.StringValue + '\n' + Value
else:
self.StringValue = Value
self.StringValueByteList = UniToHexList(self.StringValue)
@@ -465,7 +464,7 @@ class UniFileClassObject(object):
if not Line.startswith(DT.TAB_COMMENT_EDK1_SPLIT) and HeaderStart and not HeaderEnd:
HeaderEnd = True
if Line.startswith(DT.TAB_COMMENT_EDK1_SPLIT) and HeaderStart and not HeaderEnd and FirstGenHeader:
- self.UniFileHeader += Line + '\r\n'
+ self.UniFileHeader += Line + '\n'
continue
#
@@ -511,11 +510,11 @@ class UniFileClassObject(object):
if FileIn[LineCount].strip().startswith('#language'):
Line = Line + FileIn[LineCount]
FileIn[LineCount-1] = Line
- FileIn[LineCount] = '\r\n'
+ FileIn[LineCount] = '\n'
LineCount -= 1
- for Index in xrange (LineCount + 1, len (FileIn) - 1):
+ for Index in range (LineCount + 1, len (FileIn) - 1):
if (Index == len(FileIn) -1):
- FileIn[Index] = '\r\n'
+ FileIn[Index] = '\n'
else:
FileIn[Index] = FileIn[Index + 1]
continue
@@ -867,12 +866,12 @@ class UniFileClassObject(object):
Value = Value + Lines[IndexJ].strip()[1:-1]
CombineToken = False
else:
- Value = Value + Lines[IndexJ].strip()[1:-1] + '\r\n'
+ Value = Value + Lines[IndexJ].strip()[1:-1] + '\n'
else:
IndexI = IndexJ
break
- if Value.endswith('\r\n'):
- Value = Value[: Value.rfind('\r\n')]
+ if Value.endswith('\n'):
+ Value = Value[: Value.rfind('\n')]
Language = GetLanguageCode(Language, self.IsCompatibleMode, self.File)
self.AddStringToList(Name, Language, Value)
continue
diff --git a/BaseTools/Source/Python/UPT/Logger/StringTable.py b/BaseTools/Source/Python/UPT/Logger/StringTable.py
index c1c7732b40..061943925a 100644
--- a/BaseTools/Source/Python/UPT/Logger/StringTable.py
+++ b/BaseTools/Source/Python/UPT/Logger/StringTable.py
@@ -42,7 +42,7 @@ MSG_USAGE_STRING = _("\n"
MSG_VERSION_NUMBER = _("1.1")
MSG_VERSION = _("UEFI Packaging Tool (UEFIPT) - Revision " + \
MSG_VERSION_NUMBER)
-MSG_COPYRIGHT = _("Copyright (c) 2011 - 2016 Intel Corporation All Rights Reserved.")
+MSG_COPYRIGHT = _("Copyright (c) 2011 - 2018 Intel Corporation All Rights Reserved.")
MSG_VERSION_COPYRIGHT = _("\n %s\n %s" % (MSG_VERSION, MSG_COPYRIGHT))
MSG_USAGE = _("%s [options]\n%s" % ("UPT", MSG_VERSION_COPYRIGHT))
MSG_DESCRIPTION = _("The UEFIPT is used to create, " + \
diff --git a/BaseTools/Source/Python/UPT/MkPkg.py b/BaseTools/Source/Python/UPT/MkPkg.py
index 053d115547..49b507e010 100644
--- a/BaseTools/Source/Python/UPT/MkPkg.py
+++ b/BaseTools/Source/Python/UPT/MkPkg.py
@@ -136,7 +136,7 @@ def Main(Options = None):
# strings in your desired encoding before passing them to
# write().
#
- FromFile = os.path.normpath(FileObject.GetURI()).encode('utf_8')
+ FromFile = os.path.normpath(FileObject.GetURI())
FileFullPath = mws.join(WorkspaceDir, FromFile)
if FileFullPath in RePkgDict:
(DpGuid, DpVersion, DpName, Repackage) = RePkgDict[FileFullPath]
diff --git a/BaseTools/Source/Python/UPT/Parser/DecParser.py b/BaseTools/Source/Python/UPT/Parser/DecParser.py
index a88b51d055..51dc4b2bd2 100644
--- a/BaseTools/Source/Python/UPT/Parser/DecParser.py
+++ b/BaseTools/Source/Python/UPT/Parser/DecParser.py
@@ -620,11 +620,11 @@ class _DecPcd(_DecBase):
if not IsValidToken(PCD_TOKEN_PATTERN, Token):
self._LoggerError(ST.ERR_DECPARSE_PCD_TOKEN % Token)
elif not Token.startswith('0x') and not Token.startswith('0X'):
- if long(Token) > 4294967295:
+ if int(Token) > 4294967295:
self._LoggerError(ST.ERR_DECPARSE_PCD_TOKEN_INT % Token)
- Token = hex(long(Token))[:-1]
+ Token = hex(int(Token))
- IntToken = long(Token, 0)
+ IntToken = int(Token, 0)
if (Guid, IntToken) in self.TokenMap:
if self.TokenMap[Guid, IntToken] != CName:
self._LoggerError(ST.ERR_DECPARSE_PCD_TOKEN_UNIQUE%(Token))
@@ -752,7 +752,7 @@ class _DecUserExtension(_DecBase):
class Dec(_DecBase, _DecComments):
def __init__(self, DecFile, Parse = True):
try:
- Content = ConvertSpecialChar(open(DecFile, 'rb').readlines())
+ Content = ConvertSpecialChar(open(DecFile, 'r').readlines())
except BaseException:
Logger.Error(TOOL_NAME, FILE_OPEN_FAILURE, File=DecFile,
ExtraData=ST.ERR_DECPARSE_FILEOPEN % DecFile)
diff --git a/BaseTools/Source/Python/UPT/Parser/DecParserMisc.py b/BaseTools/Source/Python/UPT/Parser/DecParserMisc.py
index c5c35ede78..cd4d87224d 100644
--- a/BaseTools/Source/Python/UPT/Parser/DecParserMisc.py
+++ b/BaseTools/Source/Python/UPT/Parser/DecParserMisc.py
@@ -151,7 +151,7 @@ def IsValidNumValUint8(Token):
else:
Base = 10
try:
- TokenValue = long(Token, Base)
+ TokenValue = int(Token, Base)
except BaseException:
Valid, Cause = IsValidLogicalExpr(Token, True)
if Cause:
@@ -262,7 +262,7 @@ def IsValidPcdDatum(Type, Value):
Value = Value.lstrip('0')
if not Value:
return True, ""
- Value = long(Value, 0)
+ Value = int(Value, 0)
TypeLenMap = {
#
# 0x00 - 0xff
diff --git a/BaseTools/Source/Python/UPT/Parser/InfAsBuiltProcess.py b/BaseTools/Source/Python/UPT/Parser/InfAsBuiltProcess.py
index 029a436cec..3c313a089d 100644
--- a/BaseTools/Source/Python/UPT/Parser/InfAsBuiltProcess.py
+++ b/BaseTools/Source/Python/UPT/Parser/InfAsBuiltProcess.py
@@ -205,7 +205,7 @@ def GetFileLineContent(FileName, WorkSpace, LineNo, OriginalString):
try:
FullFileName = FullFileName.replace('\\', '/')
- Inputfile = open(FullFileName, "rb", 0)
+ Inputfile = open(FullFileName, "r")
try:
FileLinesList = Inputfile.readlines()
except BaseException:
diff --git a/BaseTools/Source/Python/UPT/Parser/InfParser.py b/BaseTools/Source/Python/UPT/Parser/InfParser.py
index cd99262e03..d17d2c887b 100644
--- a/BaseTools/Source/Python/UPT/Parser/InfParser.py
+++ b/BaseTools/Source/Python/UPT/Parser/InfParser.py
@@ -51,7 +51,7 @@ def OpenInfFile(Filename):
FileLinesList = []
try:
- FInputfile = open(Filename, "rb", 0)
+ FInputfile = open(Filename, "r")
try:
FileLinesList = FInputfile.readlines()
except BaseException:
@@ -86,7 +86,7 @@ class InfParser(InfSectionParser):
#
# Call parent class construct function
#
- super(InfParser, self).__init__()
+ super().__init__()
self.WorkspaceDir = WorkspaceDir
self.SupArchList = DT.ARCH_LIST
diff --git a/BaseTools/Source/Python/UPT/Parser/InfSectionParser.py b/BaseTools/Source/Python/UPT/Parser/InfSectionParser.py
index 1f254058d1..44243b467b 100644
--- a/BaseTools/Source/Python/UPT/Parser/InfSectionParser.py
+++ b/BaseTools/Source/Python/UPT/Parser/InfSectionParser.py
@@ -206,7 +206,7 @@ class InfSectionParser(InfDefinSectionParser,
if FilePath in cls.MetaFiles:
return cls.MetaFiles[FilePath]
else:
- ParserObject = super(InfSectionParser, cls).__new__(cls)
+ ParserObject = super().__new__(cls)
cls.MetaFiles[FilePath] = ParserObject
return ParserObject
@@ -227,7 +227,7 @@ class InfSectionParser(InfDefinSectionParser,
self.InfBuildOptionSection = InfBuildOptionsObject()
self.InfLibraryClassSection = InfLibraryClassObject()
self.InfPackageSection = InfPackageObject()
- self.InfPcdSection = InfPcdObject(self.MetaFiles.keys()[0])
+ self.InfPcdSection = InfPcdObject(list(self.MetaFiles.keys())[0])
self.InfSourcesSection = InfSourcesObject()
self.InfUserExtensionSection = InfUserExtensionObject()
self.InfProtocolSection = InfProtocolObject()
@@ -455,7 +455,7 @@ class InfSectionParser(InfDefinSectionParser,
Arch = Match.groups(1)[0].upper()
ArchList.append(Arch)
CommentSoFar = ''
- for Index in xrange(1, len(List)):
+ for Index in range(1, len(List)):
Result = ParseComment(List[Index], DT.ALL_USAGE_TOKENS, TokenDict, [], False)
Usage = Result[0]
Type = Result[1]
diff --git a/BaseTools/Source/Python/UPT/PomAdapter/DecPomAlignment.py b/BaseTools/Source/Python/UPT/PomAdapter/DecPomAlignment.py
index 5dc00affad..5d27d415ea 100644
--- a/BaseTools/Source/Python/UPT/PomAdapter/DecPomAlignment.py
+++ b/BaseTools/Source/Python/UPT/PomAdapter/DecPomAlignment.py
@@ -15,7 +15,6 @@
'''
DecPomAlignment
'''
-from __future__ import print_function
##
# Import Modules
diff --git a/BaseTools/Source/Python/UPT/UPT.py b/BaseTools/Source/Python/UPT/UPT.py
index 004fc5ff2f..930a8c1d4c 100644
--- a/BaseTools/Source/Python/UPT/UPT.py
+++ b/BaseTools/Source/Python/UPT/UPT.py
@@ -21,10 +21,6 @@ UPT
#
import locale
import sys
-encoding = locale.getdefaultlocale()[1]
-if encoding:
- reload(sys)
- sys.setdefaultencoding(encoding)
from Core import FileHook
import os.path
from sys import platform
diff --git a/BaseTools/Source/Python/UPT/UnitTest/DecParserTest.py b/BaseTools/Source/Python/UPT/UnitTest/DecParserTest.py
index 0ea5ea1e0f..567cf03e1d 100644
--- a/BaseTools/Source/Python/UPT/UnitTest/DecParserTest.py
+++ b/BaseTools/Source/Python/UPT/UnitTest/DecParserTest.py
@@ -11,7 +11,6 @@
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-from __future__ import print_function
import os
import unittest
diff --git a/BaseTools/Source/Python/UPT/UnitTest/InfBinarySectionTest.py b/BaseTools/Source/Python/UPT/UnitTest/InfBinarySectionTest.py
index 9a10ec15c4..163e4cf7df 100644
--- a/BaseTools/Source/Python/UPT/UnitTest/InfBinarySectionTest.py
+++ b/BaseTools/Source/Python/UPT/UnitTest/InfBinarySectionTest.py
@@ -11,7 +11,6 @@
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-from __future__ import print_function
import os
#import Object.Parser.InfObject as InfObject
from Object.Parser.InfCommonObject import CurrentLine
diff --git a/BaseTools/Source/Python/UPT/Xml/IniToXml.py b/BaseTools/Source/Python/UPT/Xml/IniToXml.py
index 70d8fb19f2..8125f183be 100644
--- a/BaseTools/Source/Python/UPT/Xml/IniToXml.py
+++ b/BaseTools/Source/Python/UPT/Xml/IniToXml.py
@@ -326,7 +326,7 @@ def IniToXml(IniFile):
CurrentKey = ''
PreMap = None
Map = None
- FileContent = ConvertSpecialChar(open(IniFile, 'rb').readlines())
+ FileContent = ConvertSpecialChar(open(IniFile, 'r').readlines())
LastIndex = 0
for Index in range(0, len(FileContent)):
LastIndex = Index
diff --git a/BaseTools/Source/Python/UPT/Xml/XmlParserMisc.py b/BaseTools/Source/Python/UPT/Xml/XmlParserMisc.py
index d170761aad..bf64d89f17 100644
--- a/BaseTools/Source/Python/UPT/Xml/XmlParserMisc.py
+++ b/BaseTools/Source/Python/UPT/Xml/XmlParserMisc.py
@@ -53,7 +53,7 @@ def ConvertVariableName(VariableName):
if SecondByte != 0:
return None
- if FirstByte not in xrange(0x20, 0x7F):
+ if FirstByte not in range(0x20, 0x7F):
return None
TransferedStr += ('%c')%FirstByte
Index = Index + 2