BaseTools/UPT:merge UPT Tool use Python2 and Python3
In UPT Tool,merge python2 and python3 Cc: Bob Feng <bob.c.feng@intel.com> Cc: Liming Gao <liming.gao@intel.com> Cc: Yonghong Zhu <yonghong.zhu@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Zhiju.Fan <zhijux.fan@intel.com> Tested-by: Laszlo Ersek <lersek@redhat.com> Tested-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Reviewed-by: Liming Gao <liming.gao@intel.com> Reviewed-by: Bob Feng <bob.c.feng@intel.com>
This commit is contained in:
@ -622,7 +622,7 @@ class _DecPcd(_DecBase):
|
||||
elif not Token.startswith('0x') and not Token.startswith('0X'):
|
||||
if int(Token) > 4294967295:
|
||||
self._LoggerError(ST.ERR_DECPARSE_PCD_TOKEN_INT % Token)
|
||||
Token = hex(int(Token))[:-1]
|
||||
Token = '0x%x' % int(Token)
|
||||
|
||||
IntToken = int(Token, 0)
|
||||
if (Guid, IntToken) in self.TokenMap:
|
||||
@ -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)
|
||||
|
@ -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,30 +262,10 @@ def IsValidPcdDatum(Type, Value):
|
||||
Value = Value.lstrip('0')
|
||||
if not Value:
|
||||
return True, ""
|
||||
Value = long(Value, 0)
|
||||
TypeLenMap = {
|
||||
#
|
||||
# 0x00 - 0xff
|
||||
#
|
||||
'UINT8' : 2,
|
||||
#
|
||||
# 0x0000 - 0xffff
|
||||
#
|
||||
'UINT16' : 4,
|
||||
#
|
||||
# 0x00000000 - 0xffffffff
|
||||
#
|
||||
'UINT32' : 8,
|
||||
#
|
||||
# 0x0 - 0xffffffffffffffff
|
||||
#
|
||||
'UINT64' : 16
|
||||
}
|
||||
HexStr = hex(Value)
|
||||
#
|
||||
# First two chars of HexStr are 0x and tail char is L
|
||||
#
|
||||
if TypeLenMap[Type] < len(HexStr) - 3:
|
||||
Value = int(Value, 0)
|
||||
MAX_VAL_TYPE = {"BOOLEAN": 0x01, 'UINT8': 0xFF, 'UINT16': 0xFFFF, 'UINT32': 0xFFFFFFFF,
|
||||
'UINT64': 0xFFFFFFFFFFFFFFFF}
|
||||
if Value > MAX_VAL_TYPE[Type]:
|
||||
return False, ST.ERR_DECPARSE_PCD_INT_EXCEED % (StrVal, Type)
|
||||
except BaseException:
|
||||
Valid, Cause = IsValidLogicalExpr(Value, True)
|
||||
|
@ -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:
|
||||
@ -247,7 +247,7 @@ def GetGuidVerFormLibInstance(Guid, Version, WorkSpace, CurrentInfFileName):
|
||||
continue
|
||||
InfFile = InfFile.replace('\\', '/')
|
||||
if InfFile not in GlobalData.gLIBINSTANCEDICT:
|
||||
InfFileObj = open(InfFile, "rb", 0)
|
||||
InfFileObj = open(InfFile, "r")
|
||||
GlobalData.gLIBINSTANCEDICT[InfFile] = InfFileObj
|
||||
else:
|
||||
InfFileObj = GlobalData.gLIBINSTANCEDICT[InfFile]
|
||||
|
@ -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__()
|
||||
InfSectionParser.__init__()
|
||||
|
||||
self.WorkspaceDir = WorkspaceDir
|
||||
self.SupArchList = DT.ARCH_LIST
|
||||
|
@ -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]
|
||||
|
Reference in New Issue
Block a user