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:
Zhijux Fan
2018-12-17 15:18:01 +08:00
committed by Feng, Bob C
parent 1590d12315
commit 174a9d3cc8
20 changed files with 84 additions and 235 deletions

View File

@ -44,7 +44,7 @@ class IpiDatabase(object):
Dir = os.path.dirname(DbPath) Dir = os.path.dirname(DbPath)
if not os.path.isdir(Dir): if not os.path.isdir(Dir):
os.mkdir(Dir) os.mkdir(Dir)
self.Conn = sqlite3.connect(unicode(DbPath), isolation_level='DEFERRED') self.Conn = sqlite3.connect(u''.join(DbPath), isolation_level='DEFERRED')
self.Conn.execute("PRAGMA page_size=4096") self.Conn.execute("PRAGMA page_size=4096")
self.Conn.execute("PRAGMA synchronous=OFF") self.Conn.execute("PRAGMA synchronous=OFF")
self.Cur = self.Conn.cursor() self.Cur = self.Conn.cursor()
@ -921,7 +921,7 @@ class IpiDatabase(object):
def __ConvertToSqlString(self, StringList): def __ConvertToSqlString(self, StringList):
if self.DpTable: if self.DpTable:
pass pass
return map(lambda s: s.replace("'", "''"), StringList) return list(map(lambda s: s.replace("'", "''"), StringList))

View File

@ -274,7 +274,7 @@ def GenDefines(ModuleObject):
if not DefinesDict: if not DefinesDict:
continue continue
for Statement in DefinesDict: 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) \ Statement = (u'%s ' % Statement.split(DT.TAB_EQUAL_SPLIT, 1)[0]).ljust(LeftOffset) \
+ u'= %s' % Statement.split(DT.TAB_EQUAL_SPLIT, 1)[1].lstrip() + u'= %s' % Statement.split(DT.TAB_EQUAL_SPLIT, 1)[1].lstrip()
SortedArch = DT.TAB_ARCH_COMMON SortedArch = DT.TAB_ARCH_COMMON
@ -409,7 +409,7 @@ def GenLibraryClasses(ModuleObject):
Statement += '|' + FFE Statement += '|' + FFE
ModuleList = LibraryClass.GetSupModuleList() ModuleList = LibraryClass.GetSupModuleList()
ArchList = LibraryClass.GetSupArchList() ArchList = LibraryClass.GetSupArchList()
for Index in xrange(0, len(ArchList)): for Index in range(0, len(ArchList)):
ArchList[Index] = ConvertArchForInstall(ArchList[Index]) ArchList[Index] = ConvertArchForInstall(ArchList[Index])
ArchList.sort() ArchList.sort()
SortedArch = ' '.join(ArchList) SortedArch = ' '.join(ArchList)
@ -572,7 +572,7 @@ def GenUserExtensions(ModuleObject):
# if not Statement: # if not Statement:
# continue # continue
ArchList = UserExtension.GetSupArchList() ArchList = UserExtension.GetSupArchList()
for Index in xrange(0, len(ArchList)): for Index in range(0, len(ArchList)):
ArchList[Index] = ConvertArchForInstall(ArchList[Index]) ArchList[Index] = ConvertArchForInstall(ArchList[Index])
ArchList.sort() ArchList.sort()
KeyList = [] KeyList = []

View File

@ -124,10 +124,8 @@ def GenHeaderCommentSection(Abstract, Description, Copyright, License, IsBinaryH
# #
# Convert special character to (c), (r) and (tm). # Convert special character to (c), (r) and (tm).
# #
if isinstance(Abstract, unicode): Abstract = ConvertSpecialUnicodes(Abstract)
Abstract = ConvertSpecialUnicodes(Abstract) Description = ConvertSpecialUnicodes(Description)
if isinstance(Description, unicode):
Description = ConvertSpecialUnicodes(Description)
if IsBinaryHeader: if IsBinaryHeader:
Content += CommChar * 2 + TAB_SPACE_SPLIT + TAB_BINARY_HEADER_COMMENT + '\r\n' Content += CommChar * 2 + TAB_SPACE_SPLIT + TAB_BINARY_HEADER_COMMENT + '\r\n'
elif CommChar == TAB_COMMENT_EDK1_SPLIT: elif CommChar == TAB_COMMENT_EDK1_SPLIT:

View File

@ -74,7 +74,7 @@ def ParseHeaderCommentSection(CommentList, FileName = None, IsBinaryHeader = Fal
# first find the last copyright line # first find the last copyright line
# #
Last = 0 Last = 0
for Index in xrange(len(CommentList)-1, 0, -1): for Index in range(len(CommentList)-1, 0, -1):
Line = CommentList[Index][0] Line = CommentList[Index][0]
if _IsCopyrightLine(Line): if _IsCopyrightLine(Line):
Last = Index Last = Index
@ -206,17 +206,15 @@ def ParsePcdErrorCode (Value = None, ContainerFile = None, LineNum = None):
Base = 16 Base = 16
else: else:
Base = 10 Base = 10
ErrorCode = long(Value, Base) ErrorCode = int(Value, Base)
if ErrorCode > PCD_ERR_CODE_MAX_SIZE or ErrorCode < 0: if ErrorCode > PCD_ERR_CODE_MAX_SIZE or ErrorCode < 0:
Logger.Error('Parser', Logger.Error('Parser',
FORMAT_NOT_SUPPORTED, FORMAT_NOT_SUPPORTED,
"The format %s of ErrorCode is not valid, should be UNIT32 type or long type" % Value, "The format %s of ErrorCode is not valid, should be UNIT32 type or long type" % Value,
File = ContainerFile, File = ContainerFile,
Line = LineNum) Line = LineNum)
# ErrorCode = '0x%x' % ErrorCode
# To delete the tailing 'L' return ErrorCode
#
return hex(ErrorCode)[:-1]
except ValueError as XStr: except ValueError as XStr:
if XStr: if XStr:
pass pass

View File

@ -32,7 +32,7 @@ from os import linesep
from os import walk from os import walk
from os import environ from os import environ
import re import re
from UserDict import IterableUserDict from collections import OrderedDict
import Logger.Log as Logger import Logger.Log as Logger
from Logger import StringTable as ST from Logger import StringTable as ST
@ -160,23 +160,35 @@ def RemoveDirectory(Directory, Recursively=False):
# or not # or not
# #
def SaveFileOnChange(File, Content, IsBinaryFile=True): def SaveFileOnChange(File, Content, IsBinaryFile=True):
if not IsBinaryFile:
Content = Content.replace("\n", linesep)
if os.path.exists(File): if os.path.exists(File):
try: if IsBinaryFile:
if Content == __FileHookOpen__(File, "rb").read(): try:
return False if Content == __FileHookOpen__(File, "rb").read():
except BaseException: return False
Logger.Error(None, ToolError.FILE_OPEN_FAILURE, ExtraData=File) except BaseException:
Logger.Error(None, ToolError.FILE_OPEN_FAILURE, ExtraData=File)
else:
try:
if Content == __FileHookOpen__(File, "r").read():
return False
except BaseException:
Logger.Error(None, ToolError.FILE_OPEN_FAILURE, ExtraData=File)
CreateDirectory(os.path.dirname(File)) CreateDirectory(os.path.dirname(File))
try: if IsBinaryFile:
FileFd = __FileHookOpen__(File, "wb") try:
FileFd.write(Content) FileFd = __FileHookOpen__(File, "wb")
FileFd.close() FileFd.write(Content)
except BaseException: FileFd.close()
Logger.Error(None, ToolError.FILE_CREATE_FAILURE, ExtraData=File) except BaseException:
Logger.Error(None, ToolError.FILE_CREATE_FAILURE, ExtraData=File)
else:
try:
FileFd = __FileHookOpen__(File, "w")
FileFd.write(Content)
FileFd.close()
except BaseException:
Logger.Error(None, ToolError.FILE_CREATE_FAILURE, ExtraData=File)
return True return True
@ -288,148 +300,6 @@ def RealPath2(File, Dir='', OverrideDir=''):
return None, None return None, None
## A dict which can access its keys and/or values orderly
#
# The class implements a new kind of dict which its keys or values can be
# accessed in the order they are added into the dict. It guarantees the order
# by making use of an internal list to keep a copy of keys.
#
class Sdict(IterableUserDict):
## Constructor
#
def __init__(self):
IterableUserDict.__init__(self)
self._key_list = []
## [] operator
#
def __setitem__(self, Key, Value):
if Key not in self._key_list:
self._key_list.append(Key)
IterableUserDict.__setitem__(self, Key, Value)
## del operator
#
def __delitem__(self, Key):
self._key_list.remove(Key)
IterableUserDict.__delitem__(self, Key)
## used in "for k in dict" loop to ensure the correct order
#
def __iter__(self):
return self.iterkeys()
## len() support
#
def __len__(self):
return len(self._key_list)
## "in" test support
#
def __contains__(self, Key):
return Key in self._key_list
## indexof support
#
def index(self, Key):
return self._key_list.index(Key)
## insert support
#
def insert(self, Key, Newkey, Newvalue, Order):
Index = self._key_list.index(Key)
if Order == 'BEFORE':
self._key_list.insert(Index, Newkey)
IterableUserDict.__setitem__(self, Newkey, Newvalue)
elif Order == 'AFTER':
self._key_list.insert(Index + 1, Newkey)
IterableUserDict.__setitem__(self, Newkey, Newvalue)
## append support
#
def append(self, Sdict2):
for Key in Sdict2:
if Key not in self._key_list:
self._key_list.append(Key)
IterableUserDict.__setitem__(self, Key, Sdict2[Key])
## hash key
#
def has_key(self, Key):
return Key in self._key_list
## Empty the dict
#
def clear(self):
self._key_list = []
IterableUserDict.clear(self)
## Return a copy of keys
#
def keys(self):
Keys = []
for Key in self._key_list:
Keys.append(Key)
return Keys
## Return a copy of values
#
def values(self):
Values = []
for Key in self._key_list:
Values.append(self[Key])
return Values
## Return a copy of (key, value) list
#
def items(self):
Items = []
for Key in self._key_list:
Items.append((Key, self[Key]))
return Items
## Iteration support
#
def iteritems(self):
return iter(self.items())
## Keys interation support
#
def iterkeys(self):
return iter(self.keys())
## Values interation support
#
def itervalues(self):
return iter(self.values())
## Return value related to a key, and remove the (key, value) from the dict
#
def pop(self, Key, *Dv):
Value = None
if Key in self._key_list:
Value = self[Key]
self.__delitem__(Key)
elif len(Dv) != 0 :
Value = Dv[0]
return Value
## Return (key, value) pair, and remove the (key, value) from the dict
#
def popitem(self):
Key = self._key_list[-1]
Value = self[Key]
self.__delitem__(Key)
return Key, Value
## update method
#
def update(self, Dict=None, **Kwargs):
if Dict is not None:
for Key1, Val1 in Dict.items():
self[Key1] = Val1
if len(Kwargs):
for Key1, Val1 in Kwargs.items():
self[Key1] = Val1
## CommonPath ## CommonPath
# #
# @param PathList: PathList # @param PathList: PathList
@ -437,7 +307,7 @@ class Sdict(IterableUserDict):
def CommonPath(PathList): def CommonPath(PathList):
Path1 = min(PathList).split(os.path.sep) Path1 = min(PathList).split(os.path.sep)
Path2 = max(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]: if Path1[Index] != Path2[Index]:
return os.path.sep.join(Path1[:Index]) return os.path.sep.join(Path1[:Index])
return os.path.sep.join(Path1) return os.path.sep.join(Path1)
@ -890,7 +760,7 @@ def ProcessEdkComment(LineList):
if FindEdkBlockComment: if FindEdkBlockComment:
if FirstPos == -1: if FirstPos == -1:
FirstPos = StartPos FirstPos = StartPos
for Index in xrange(StartPos, EndPos+1): for Index in range(StartPos, EndPos+1):
LineList[Index] = '' LineList[Index] = ''
FindEdkBlockComment = False FindEdkBlockComment = False
elif Line.find("//") != -1 and not Line.startswith("#"): elif Line.find("//") != -1 and not Line.startswith("#"):
@ -957,7 +827,7 @@ def GetLibInstanceInfo(String, WorkSpace, LineNo):
FileLinesList = [] FileLinesList = []
try: try:
FInputfile = open(FullFileName, "rb", 0) FInputfile = open(FullFileName, "r")
try: try:
FileLinesList = FInputfile.readlines() FileLinesList = FInputfile.readlines()
except BaseException: except BaseException:

View File

@ -727,7 +727,7 @@ def IsValidUserId(UserId):
# #
def CheckUTF16FileHeader(File): def CheckUTF16FileHeader(File):
FileIn = open(File, 'rb').read(2) FileIn = open(File, 'rb').read(2)
if FileIn != '\xff\xfe': if FileIn != b'\xff\xfe':
return False return False
return True return True

View File

@ -974,7 +974,7 @@ def GenSection(SectionName, SectionDict, SplitArch=True, NeedBlankLine=False):
ArchList = GetSplitValueList(SectionAttrs, DataType.TAB_COMMENT_SPLIT) ArchList = GetSplitValueList(SectionAttrs, DataType.TAB_COMMENT_SPLIT)
else: else:
ArchList = [SectionAttrs] ArchList = [SectionAttrs]
for Index in xrange(0, len(ArchList)): for Index in range(0, len(ArchList)):
ArchList[Index] = ConvertArchForInstall(ArchList[Index]) ArchList[Index] = ConvertArchForInstall(ArchList[Index])
Section = '[' + SectionName + '.' + (', ' + SectionName + '.').join(ArchList) + ']' Section = '[' + SectionName + '.' + (', ' + SectionName + '.').join(ArchList) + ']'
else: else:

View File

@ -20,7 +20,6 @@ StringUtils
# #
import re import re
import os.path import os.path
from string import strip
import Logger.Log as Logger import Logger.Log as Logger
import Library.DataType as DataType import Library.DataType as DataType
from Logger.ToolError import FORMAT_INVALID 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): 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 ## MergeArches
# #
@ -435,7 +434,7 @@ def GetSingleValueOfKeyFromLines(Lines, Dictionary, CommentCharacter, KeySplitCh
# #
LineList[1] = CleanString(LineList[1], CommentCharacter) LineList[1] = CleanString(LineList[1], CommentCharacter)
if ValueSplitFlag: if ValueSplitFlag:
Value = map(strip, LineList[1].split(ValueSplitCharacter)) Value = list(map(lambda x: x.strip(), LineList[1].split(ValueSplitCharacter)))
else: else:
Value = CleanString(LineList[1], CommentCharacter).splitlines() Value = CleanString(LineList[1], CommentCharacter).splitlines()
@ -632,7 +631,7 @@ def SplitString(String):
# @param StringList: A list for strings to be converted # @param StringList: A list for strings to be converted
# #
def ConvertToSqlString(StringList): def ConvertToSqlString(StringList):
return map(lambda s: s.replace("'", "''"), StringList) return list(map(lambda s: s.replace("'", "''"), StringList))
## Convert To Sql String ## Convert To Sql String
# #
@ -940,23 +939,24 @@ def SplitPcdEntry(String):
def IsMatchArch(Arch1, Arch2): def IsMatchArch(Arch1, Arch2):
if 'COMMON' in Arch1 or 'COMMON' in Arch2: if 'COMMON' in Arch1 or 'COMMON' in Arch2:
return True return True
if isinstance(Arch1, basestring) and isinstance(Arch2, basestring): try:
if Arch1 == Arch2: if isinstance(Arch1, list) and isinstance(Arch2, list):
return True for Item1 in Arch1:
for Item2 in Arch2:
if Item1 == Item2:
return True
if isinstance(Arch1, basestring) and isinstance(Arch2, list): elif isinstance(Arch1, list):
return Arch1 in Arch2 return Arch2 in Arch1
if isinstance(Arch2, basestring) and isinstance(Arch1, list): elif isinstance(Arch2, list):
return Arch2 in Arch1 return Arch1 in Arch2
if isinstance(Arch1, list) and isinstance(Arch2, list): else:
for Item1 in Arch1: if Arch1 == Arch2:
for Item2 in Arch2: return True
if Item1 == Item2: except:
return True return False
return False
# Search all files in FilePath to find the FileName with the largest index # Search all files in FilePath to find the FileName with the largest index
# Return the FileName with index +1 under the FilePath # Return the FileName with index +1 under the FilePath

View File

@ -119,10 +119,12 @@ def UniToHexList(Uni):
# @retval NewUni: The converted unicode string # @retval NewUni: The converted unicode string
# #
def ConvertSpecialUnicodes(Uni): def ConvertSpecialUnicodes(Uni):
NewUni = Uni OldUni = NewUni = Uni
NewUni = NewUni.replace(u'\u00A9', '(c)') NewUni = NewUni.replace(u'\u00A9', '(c)')
NewUni = NewUni.replace(u'\u00AE', '(r)') NewUni = NewUni.replace(u'\u00AE', '(r)')
NewUni = NewUni.replace(u'\u2122', '(tm)') NewUni = NewUni.replace(u'\u2122', '(tm)')
if OldUni == NewUni:
NewUni = OldUni
return NewUni return NewUni
## GetLanguageCode1766 ## GetLanguageCode1766
@ -513,7 +515,7 @@ class UniFileClassObject(object):
FileIn[LineCount-1] = Line FileIn[LineCount-1] = Line
FileIn[LineCount] = '\r\n' FileIn[LineCount] = '\r\n'
LineCount -= 1 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): if (Index == len(FileIn) -1):
FileIn[Index] = '\r\n' FileIn[Index] = '\r\n'
else: else:

View File

@ -180,7 +180,7 @@ def XmlElementData(Dom):
# @param String A XPath style path. # @param String A XPath style path.
# #
def XmlElementList(Dom, String): def XmlElementList(Dom, String):
return map(XmlElementData, XmlList(Dom, String)) return list(map(XmlElementData, XmlList(Dom, String)))
## Get the XML attribute of the current node. ## Get the XML attribute of the current node.

View File

@ -42,7 +42,7 @@ MSG_USAGE_STRING = _("\n"
MSG_VERSION_NUMBER = _("1.1") MSG_VERSION_NUMBER = _("1.1")
MSG_VERSION = _("UEFI Packaging Tool (UEFIPT) - Revision " + \ MSG_VERSION = _("UEFI Packaging Tool (UEFIPT) - Revision " + \
MSG_VERSION_NUMBER) 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_VERSION_COPYRIGHT = _("\n %s\n %s" % (MSG_VERSION, MSG_COPYRIGHT))
MSG_USAGE = _("%s [options]\n%s" % ("UPT", MSG_VERSION_COPYRIGHT)) MSG_USAGE = _("%s [options]\n%s" % ("UPT", MSG_VERSION_COPYRIGHT))
MSG_DESCRIPTION = _("The UEFIPT is used to create, " + \ MSG_DESCRIPTION = _("The UEFIPT is used to create, " + \

View File

@ -622,7 +622,7 @@ class _DecPcd(_DecBase):
elif not Token.startswith('0x') and not Token.startswith('0X'): elif not Token.startswith('0x') and not Token.startswith('0X'):
if int(Token) > 4294967295: if int(Token) > 4294967295:
self._LoggerError(ST.ERR_DECPARSE_PCD_TOKEN_INT % Token) self._LoggerError(ST.ERR_DECPARSE_PCD_TOKEN_INT % Token)
Token = hex(int(Token))[:-1] Token = '0x%x' % int(Token)
IntToken = int(Token, 0) IntToken = int(Token, 0)
if (Guid, IntToken) in self.TokenMap: if (Guid, IntToken) in self.TokenMap:
@ -752,7 +752,7 @@ class _DecUserExtension(_DecBase):
class Dec(_DecBase, _DecComments): class Dec(_DecBase, _DecComments):
def __init__(self, DecFile, Parse = True): def __init__(self, DecFile, Parse = True):
try: try:
Content = ConvertSpecialChar(open(DecFile, 'rb').readlines()) Content = ConvertSpecialChar(open(DecFile, 'r').readlines())
except BaseException: except BaseException:
Logger.Error(TOOL_NAME, FILE_OPEN_FAILURE, File=DecFile, Logger.Error(TOOL_NAME, FILE_OPEN_FAILURE, File=DecFile,
ExtraData=ST.ERR_DECPARSE_FILEOPEN % DecFile) ExtraData=ST.ERR_DECPARSE_FILEOPEN % DecFile)

View File

@ -151,7 +151,7 @@ def IsValidNumValUint8(Token):
else: else:
Base = 10 Base = 10
try: try:
TokenValue = long(Token, Base) TokenValue = int(Token, Base)
except BaseException: except BaseException:
Valid, Cause = IsValidLogicalExpr(Token, True) Valid, Cause = IsValidLogicalExpr(Token, True)
if Cause: if Cause:
@ -262,30 +262,10 @@ def IsValidPcdDatum(Type, Value):
Value = Value.lstrip('0') Value = Value.lstrip('0')
if not Value: if not Value:
return True, "" return True, ""
Value = long(Value, 0) Value = int(Value, 0)
TypeLenMap = { MAX_VAL_TYPE = {"BOOLEAN": 0x01, 'UINT8': 0xFF, 'UINT16': 0xFFFF, 'UINT32': 0xFFFFFFFF,
# 'UINT64': 0xFFFFFFFFFFFFFFFF}
# 0x00 - 0xff if Value > MAX_VAL_TYPE[Type]:
#
'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:
return False, ST.ERR_DECPARSE_PCD_INT_EXCEED % (StrVal, Type) return False, ST.ERR_DECPARSE_PCD_INT_EXCEED % (StrVal, Type)
except BaseException: except BaseException:
Valid, Cause = IsValidLogicalExpr(Value, True) Valid, Cause = IsValidLogicalExpr(Value, True)

View File

@ -205,7 +205,7 @@ def GetFileLineContent(FileName, WorkSpace, LineNo, OriginalString):
try: try:
FullFileName = FullFileName.replace('\\', '/') FullFileName = FullFileName.replace('\\', '/')
Inputfile = open(FullFileName, "rb", 0) Inputfile = open(FullFileName, "r")
try: try:
FileLinesList = Inputfile.readlines() FileLinesList = Inputfile.readlines()
except BaseException: except BaseException:
@ -247,7 +247,7 @@ def GetGuidVerFormLibInstance(Guid, Version, WorkSpace, CurrentInfFileName):
continue continue
InfFile = InfFile.replace('\\', '/') InfFile = InfFile.replace('\\', '/')
if InfFile not in GlobalData.gLIBINSTANCEDICT: if InfFile not in GlobalData.gLIBINSTANCEDICT:
InfFileObj = open(InfFile, "rb", 0) InfFileObj = open(InfFile, "r")
GlobalData.gLIBINSTANCEDICT[InfFile] = InfFileObj GlobalData.gLIBINSTANCEDICT[InfFile] = InfFileObj
else: else:
InfFileObj = GlobalData.gLIBINSTANCEDICT[InfFile] InfFileObj = GlobalData.gLIBINSTANCEDICT[InfFile]

View File

@ -51,7 +51,7 @@ def OpenInfFile(Filename):
FileLinesList = [] FileLinesList = []
try: try:
FInputfile = open(Filename, "rb", 0) FInputfile = open(Filename, "r")
try: try:
FileLinesList = FInputfile.readlines() FileLinesList = FInputfile.readlines()
except BaseException: except BaseException:
@ -86,7 +86,7 @@ class InfParser(InfSectionParser):
# #
# Call parent class construct function # Call parent class construct function
# #
super(InfParser, self).__init__() InfSectionParser.__init__()
self.WorkspaceDir = WorkspaceDir self.WorkspaceDir = WorkspaceDir
self.SupArchList = DT.ARCH_LIST self.SupArchList = DT.ARCH_LIST

View File

@ -227,7 +227,7 @@ class InfSectionParser(InfDefinSectionParser,
self.InfBuildOptionSection = InfBuildOptionsObject() self.InfBuildOptionSection = InfBuildOptionsObject()
self.InfLibraryClassSection = InfLibraryClassObject() self.InfLibraryClassSection = InfLibraryClassObject()
self.InfPackageSection = InfPackageObject() self.InfPackageSection = InfPackageObject()
self.InfPcdSection = InfPcdObject(self.MetaFiles.keys()[0]) self.InfPcdSection = InfPcdObject(list(self.MetaFiles.keys())[0])
self.InfSourcesSection = InfSourcesObject() self.InfSourcesSection = InfSourcesObject()
self.InfUserExtensionSection = InfUserExtensionObject() self.InfUserExtensionSection = InfUserExtensionObject()
self.InfProtocolSection = InfProtocolObject() self.InfProtocolSection = InfProtocolObject()
@ -455,7 +455,7 @@ class InfSectionParser(InfDefinSectionParser,
Arch = Match.groups(1)[0].upper() Arch = Match.groups(1)[0].upper()
ArchList.append(Arch) ArchList.append(Arch)
CommentSoFar = '' 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) Result = ParseComment(List[Index], DT.ALL_USAGE_TOKENS, TokenDict, [], False)
Usage = Result[0] Usage = Result[0]
Type = Result[1] Type = Result[1]

View File

@ -133,7 +133,7 @@ class InfPomAlignment(ModuleObject):
# #
# Should only have one ArchString Item. # Should only have one ArchString Item.
# #
ArchString = RecordSet.keys()[0] ArchString = list(RecordSet.keys())[0]
ArchList = GetSplitValueList(ArchString, ' ') ArchList = GetSplitValueList(ArchString, ' ')
ArchList = ConvertArchList(ArchList) ArchList = ConvertArchList(ArchList)
HasCalledFlag = False HasCalledFlag = False

View File

@ -21,6 +21,7 @@ UPT
# #
import locale import locale
import sys import sys
from imp import reload
encoding = locale.getdefaultlocale()[1] encoding = locale.getdefaultlocale()[1]
if encoding: if encoding:
reload(sys) reload(sys)

View File

@ -326,7 +326,7 @@ def IniToXml(IniFile):
CurrentKey = '' CurrentKey = ''
PreMap = None PreMap = None
Map = None Map = None
FileContent = ConvertSpecialChar(open(IniFile, 'rb').readlines()) FileContent = ConvertSpecialChar(open(IniFile, 'r').readlines())
LastIndex = 0 LastIndex = 0
for Index in range(0, len(FileContent)): for Index in range(0, len(FileContent)):
LastIndex = Index LastIndex = Index

View File

@ -53,7 +53,7 @@ def ConvertVariableName(VariableName):
if SecondByte != 0: if SecondByte != 0:
return None return None
if FirstByte not in xrange(0x20, 0x7F): if FirstByte not in range(0x20, 0x7F):
return None return None
TransferedStr += ('%c')%FirstByte TransferedStr += ('%c')%FirstByte
Index = Index + 2 Index = Index + 2