Dir = os.path.dirname(DbPath)\r
if not os.path.isdir(Dir):\r
os.mkdir(Dir)\r
- self.Conn = sqlite3.connect(unicode(DbPath), isolation_level='DEFERRED')\r
+ self.Conn = sqlite3.connect(u''.join(DbPath), isolation_level='DEFERRED')\r
self.Conn.execute("PRAGMA page_size=4096")\r
self.Conn.execute("PRAGMA synchronous=OFF")\r
self.Cur = self.Conn.cursor()\r
def __ConvertToSqlString(self, StringList):\r
if self.DpTable:\r
pass\r
- return map(lambda s: s.replace("'", "''"), StringList)\r
+ return list(map(lambda s: s.replace("'", "''"), StringList))\r
\r
\r
\r
if not DefinesDict:\r
continue\r
for Statement in DefinesDict:\r
- if Statement.split(DT.TAB_EQUAL_SPLIT) > 1:\r
+ if len(Statement.split(DT.TAB_EQUAL_SPLIT)) > 1:\r
Statement = (u'%s ' % Statement.split(DT.TAB_EQUAL_SPLIT, 1)[0]).ljust(LeftOffset) \\r
+ u'= %s' % Statement.split(DT.TAB_EQUAL_SPLIT, 1)[1].lstrip()\r
SortedArch = DT.TAB_ARCH_COMMON\r
Statement += '|' + FFE\r
ModuleList = LibraryClass.GetSupModuleList()\r
ArchList = LibraryClass.GetSupArchList()\r
- for Index in xrange(0, len(ArchList)):\r
+ for Index in range(0, len(ArchList)):\r
ArchList[Index] = ConvertArchForInstall(ArchList[Index])\r
ArchList.sort()\r
SortedArch = ' '.join(ArchList)\r
# if not Statement:\r
# continue\r
ArchList = UserExtension.GetSupArchList()\r
- for Index in xrange(0, len(ArchList)):\r
+ for Index in range(0, len(ArchList)):\r
ArchList[Index] = ConvertArchForInstall(ArchList[Index])\r
ArchList.sort()\r
KeyList = []\r
#\r
# Convert special character to (c), (r) and (tm).\r
#\r
- if isinstance(Abstract, unicode):\r
- Abstract = ConvertSpecialUnicodes(Abstract)\r
- if isinstance(Description, unicode):\r
- Description = ConvertSpecialUnicodes(Description)\r
+ Abstract = ConvertSpecialUnicodes(Abstract)\r
+ Description = ConvertSpecialUnicodes(Description)\r
if IsBinaryHeader:\r
Content += CommChar * 2 + TAB_SPACE_SPLIT + TAB_BINARY_HEADER_COMMENT + '\r\n'\r
elif CommChar == TAB_COMMENT_EDK1_SPLIT:\r
# first find the last copyright line\r
#\r
Last = 0\r
- for Index in xrange(len(CommentList)-1, 0, -1):\r
+ for Index in range(len(CommentList)-1, 0, -1):\r
Line = CommentList[Index][0]\r
if _IsCopyrightLine(Line):\r
Last = Index\r
Base = 16\r
else:\r
Base = 10\r
- ErrorCode = long(Value, Base)\r
+ ErrorCode = int(Value, Base)\r
if ErrorCode > PCD_ERR_CODE_MAX_SIZE or ErrorCode < 0:\r
Logger.Error('Parser',\r
FORMAT_NOT_SUPPORTED,\r
"The format %s of ErrorCode is not valid, should be UNIT32 type or long type" % Value,\r
File = ContainerFile,\r
Line = LineNum)\r
- #\r
- # To delete the tailing 'L'\r
- #\r
- return hex(ErrorCode)[:-1]\r
+ ErrorCode = '0x%x' % ErrorCode\r
+ return ErrorCode\r
except ValueError as XStr:\r
if XStr:\r
pass\r
from os import walk\r
from os import environ\r
import re\r
-from UserDict import IterableUserDict\r
+from collections import OrderedDict\r
\r
import Logger.Log as Logger\r
from Logger import StringTable as ST\r
# or not\r
#\r
def SaveFileOnChange(File, Content, IsBinaryFile=True):\r
- if not IsBinaryFile:\r
- Content = Content.replace("\n", linesep)\r
-\r
if os.path.exists(File):\r
- try:\r
- if Content == __FileHookOpen__(File, "rb").read():\r
- return False\r
- except BaseException:\r
- Logger.Error(None, ToolError.FILE_OPEN_FAILURE, ExtraData=File)\r
+ if IsBinaryFile:\r
+ try:\r
+ if Content == __FileHookOpen__(File, "rb").read():\r
+ return False\r
+ except BaseException:\r
+ Logger.Error(None, ToolError.FILE_OPEN_FAILURE, ExtraData=File)\r
+ else:\r
+ try:\r
+ if Content == __FileHookOpen__(File, "r").read():\r
+ return False\r
+ except BaseException:\r
+ Logger.Error(None, ToolError.FILE_OPEN_FAILURE, ExtraData=File)\r
\r
CreateDirectory(os.path.dirname(File))\r
- try:\r
- FileFd = __FileHookOpen__(File, "wb")\r
- FileFd.write(Content)\r
- FileFd.close()\r
- except BaseException:\r
- Logger.Error(None, ToolError.FILE_CREATE_FAILURE, ExtraData=File)\r
+ if IsBinaryFile:\r
+ try:\r
+ FileFd = __FileHookOpen__(File, "wb")\r
+ FileFd.write(Content)\r
+ FileFd.close()\r
+ except BaseException:\r
+ Logger.Error(None, ToolError.FILE_CREATE_FAILURE, ExtraData=File)\r
+ else:\r
+ try:\r
+ FileFd = __FileHookOpen__(File, "w")\r
+ FileFd.write(Content)\r
+ FileFd.close()\r
+ except BaseException:\r
+ Logger.Error(None, ToolError.FILE_CREATE_FAILURE, ExtraData=File)\r
\r
return True\r
\r
\r
return None, None\r
\r
-## A dict which can access its keys and/or values orderly\r
-#\r
-# The class implements a new kind of dict which its keys or values can be\r
-# accessed in the order they are added into the dict. It guarantees the order\r
-# by making use of an internal list to keep a copy of keys.\r
-#\r
-class Sdict(IterableUserDict):\r
- ## Constructor\r
- #\r
- def __init__(self):\r
- IterableUserDict.__init__(self)\r
- self._key_list = []\r
-\r
- ## [] operator\r
- #\r
- def __setitem__(self, Key, Value):\r
- if Key not in self._key_list:\r
- self._key_list.append(Key)\r
- IterableUserDict.__setitem__(self, Key, Value)\r
-\r
- ## del operator\r
- #\r
- def __delitem__(self, Key):\r
- self._key_list.remove(Key)\r
- IterableUserDict.__delitem__(self, Key)\r
-\r
- ## used in "for k in dict" loop to ensure the correct order\r
- #\r
- def __iter__(self):\r
- return self.iterkeys()\r
-\r
- ## len() support\r
- #\r
- def __len__(self):\r
- return len(self._key_list)\r
-\r
- ## "in" test support\r
- #\r
- def __contains__(self, Key):\r
- return Key in self._key_list\r
-\r
- ## indexof support\r
- #\r
- def index(self, Key):\r
- return self._key_list.index(Key)\r
-\r
- ## insert support\r
- #\r
- def insert(self, Key, Newkey, Newvalue, Order):\r
- Index = self._key_list.index(Key)\r
- if Order == 'BEFORE':\r
- self._key_list.insert(Index, Newkey)\r
- IterableUserDict.__setitem__(self, Newkey, Newvalue)\r
- elif Order == 'AFTER':\r
- self._key_list.insert(Index + 1, Newkey)\r
- IterableUserDict.__setitem__(self, Newkey, Newvalue)\r
-\r
- ## append support\r
- #\r
- def append(self, Sdict2):\r
- for Key in Sdict2:\r
- if Key not in self._key_list:\r
- self._key_list.append(Key)\r
- IterableUserDict.__setitem__(self, Key, Sdict2[Key])\r
- ## hash key\r
- #\r
- def has_key(self, Key):\r
- return Key in self._key_list\r
-\r
- ## Empty the dict\r
- #\r
- def clear(self):\r
- self._key_list = []\r
- IterableUserDict.clear(self)\r
-\r
- ## Return a copy of keys\r
- #\r
- def keys(self):\r
- Keys = []\r
- for Key in self._key_list:\r
- Keys.append(Key)\r
- return Keys\r
-\r
- ## Return a copy of values\r
- #\r
- def values(self):\r
- Values = []\r
- for Key in self._key_list:\r
- Values.append(self[Key])\r
- return Values\r
-\r
- ## Return a copy of (key, value) list\r
- #\r
- def items(self):\r
- Items = []\r
- for Key in self._key_list:\r
- Items.append((Key, self[Key]))\r
- return Items\r
-\r
- ## Iteration support\r
- #\r
- def iteritems(self):\r
- return iter(self.items())\r
-\r
- ## Keys interation support\r
- #\r
- def iterkeys(self):\r
- return iter(self.keys())\r
-\r
- ## Values interation support\r
- #\r
- def itervalues(self):\r
- return iter(self.values())\r
-\r
- ## Return value related to a key, and remove the (key, value) from the dict\r
- #\r
- def pop(self, Key, *Dv):\r
- Value = None\r
- if Key in self._key_list:\r
- Value = self[Key]\r
- self.__delitem__(Key)\r
- elif len(Dv) != 0 :\r
- Value = Dv[0]\r
- return Value\r
-\r
- ## Return (key, value) pair, and remove the (key, value) from the dict\r
- #\r
- def popitem(self):\r
- Key = self._key_list[-1]\r
- Value = self[Key]\r
- self.__delitem__(Key)\r
- return Key, Value\r
- ## update method\r
- #\r
- def update(self, Dict=None, **Kwargs):\r
- if Dict is not None:\r
- for Key1, Val1 in Dict.items():\r
- self[Key1] = Val1\r
- if len(Kwargs):\r
- for Key1, Val1 in Kwargs.items():\r
- self[Key1] = Val1\r
-\r
## CommonPath\r
#\r
# @param PathList: PathList\r
def CommonPath(PathList):\r
Path1 = min(PathList).split(os.path.sep)\r
Path2 = max(PathList).split(os.path.sep)\r
- for Index in xrange(min(len(Path1), len(Path2))):\r
+ for Index in range(min(len(Path1), len(Path2))):\r
if Path1[Index] != Path2[Index]:\r
return os.path.sep.join(Path1[:Index])\r
return os.path.sep.join(Path1)\r
if FindEdkBlockComment:\r
if FirstPos == -1:\r
FirstPos = StartPos\r
- for Index in xrange(StartPos, EndPos+1):\r
+ for Index in range(StartPos, EndPos+1):\r
LineList[Index] = ''\r
FindEdkBlockComment = False\r
elif Line.find("//") != -1 and not Line.startswith("#"):\r
FileLinesList = []\r
\r
try:\r
- FInputfile = open(FullFileName, "rb", 0)\r
+ FInputfile = open(FullFileName, "r")\r
try:\r
FileLinesList = FInputfile.readlines()\r
except BaseException:\r
#\r
def CheckUTF16FileHeader(File):\r
FileIn = open(File, 'rb').read(2)\r
- if FileIn != '\xff\xfe':\r
+ if FileIn != b'\xff\xfe':\r
return False\r
\r
return True\r
ArchList = GetSplitValueList(SectionAttrs, DataType.TAB_COMMENT_SPLIT)\r
else:\r
ArchList = [SectionAttrs]\r
- for Index in xrange(0, len(ArchList)):\r
+ for Index in range(0, len(ArchList)):\r
ArchList[Index] = ConvertArchForInstall(ArchList[Index])\r
Section = '[' + SectionName + '.' + (', ' + SectionName + '.').join(ArchList) + ']'\r
else:\r
#\r
import re\r
import os.path\r
-from string import strip\r
import Logger.Log as Logger\r
import Library.DataType as DataType\r
from Logger.ToolError import FORMAT_INVALID\r
#\r
#\r
def GetSplitValueList(String, SplitTag=DataType.TAB_VALUE_SPLIT, MaxSplit= -1):\r
- return map(lambda l: l.strip(), String.split(SplitTag, MaxSplit))\r
+ return list(map(lambda l: l.strip(), String.split(SplitTag, MaxSplit)))\r
\r
## MergeArches\r
#\r
#\r
LineList[1] = CleanString(LineList[1], CommentCharacter)\r
if ValueSplitFlag:\r
- Value = map(strip, LineList[1].split(ValueSplitCharacter))\r
+ Value = list(map(lambda x: x.strip(), LineList[1].split(ValueSplitCharacter)))\r
else:\r
Value = CleanString(LineList[1], CommentCharacter).splitlines()\r
\r
# @param StringList: A list for strings to be converted\r
#\r
def ConvertToSqlString(StringList):\r
- return map(lambda s: s.replace("'", "''"), StringList)\r
+ return list(map(lambda s: s.replace("'", "''"), StringList))\r
\r
## Convert To Sql String\r
#\r
def IsMatchArch(Arch1, Arch2):\r
if 'COMMON' in Arch1 or 'COMMON' in Arch2:\r
return True\r
- if isinstance(Arch1, basestring) and isinstance(Arch2, basestring):\r
- if Arch1 == Arch2:\r
- return True\r
-\r
- if isinstance(Arch1, basestring) and isinstance(Arch2, list):\r
- return Arch1 in Arch2\r
+ try:\r
+ if isinstance(Arch1, list) and isinstance(Arch2, list):\r
+ for Item1 in Arch1:\r
+ for Item2 in Arch2:\r
+ if Item1 == Item2:\r
+ return True\r
\r
- if isinstance(Arch2, basestring) and isinstance(Arch1, list):\r
- return Arch2 in Arch1\r
+ elif isinstance(Arch1, list):\r
+ return Arch2 in Arch1\r
\r
- if isinstance(Arch1, list) and isinstance(Arch2, list):\r
- for Item1 in Arch1:\r
- for Item2 in Arch2:\r
- if Item1 == Item2:\r
- return True\r
+ elif isinstance(Arch2, list):\r
+ return Arch1 in Arch2\r
\r
- return False\r
+ else:\r
+ if Arch1 == Arch2:\r
+ return True\r
+ except:\r
+ return False\r
\r
# Search all files in FilePath to find the FileName with the largest index\r
# Return the FileName with index +1 under the FilePath\r
# @retval NewUni: The converted unicode string\r
#\r
def ConvertSpecialUnicodes(Uni):\r
- NewUni = Uni\r
+ OldUni = NewUni = Uni\r
NewUni = NewUni.replace(u'\u00A9', '(c)')\r
NewUni = NewUni.replace(u'\u00AE', '(r)')\r
NewUni = NewUni.replace(u'\u2122', '(tm)')\r
+ if OldUni == NewUni:\r
+ NewUni = OldUni\r
return NewUni\r
\r
## GetLanguageCode1766\r
FileIn[LineCount-1] = Line\r
FileIn[LineCount] = '\r\n'\r
LineCount -= 1\r
- for Index in xrange (LineCount + 1, len (FileIn) - 1):\r
+ for Index in range (LineCount + 1, len (FileIn) - 1):\r
if (Index == len(FileIn) -1):\r
FileIn[Index] = '\r\n'\r
else:\r
# @param String A XPath style path.\r
#\r
def XmlElementList(Dom, String):\r
- return map(XmlElementData, XmlList(Dom, String))\r
+ return list(map(XmlElementData, XmlList(Dom, String)))\r
\r
\r
## Get the XML attribute of the current node.\r
MSG_VERSION_NUMBER = _("1.1")\r
MSG_VERSION = _("UEFI Packaging Tool (UEFIPT) - Revision " + \\r
MSG_VERSION_NUMBER)\r
-MSG_COPYRIGHT = _("Copyright (c) 2011 - 2016 Intel Corporation All Rights Reserved.")\r
+MSG_COPYRIGHT = _("Copyright (c) 2011 - 2018 Intel Corporation All Rights Reserved.")\r
MSG_VERSION_COPYRIGHT = _("\n %s\n %s" % (MSG_VERSION, MSG_COPYRIGHT))\r
MSG_USAGE = _("%s [options]\n%s" % ("UPT", MSG_VERSION_COPYRIGHT))\r
MSG_DESCRIPTION = _("The UEFIPT is used to create, " + \\r
elif not Token.startswith('0x') and not Token.startswith('0X'):\r
if int(Token) > 4294967295:\r
self._LoggerError(ST.ERR_DECPARSE_PCD_TOKEN_INT % Token)\r
- Token = hex(int(Token))[:-1]\r
+ Token = '0x%x' % int(Token)\r
\r
IntToken = int(Token, 0)\r
if (Guid, IntToken) in self.TokenMap:\r
class Dec(_DecBase, _DecComments):\r
def __init__(self, DecFile, Parse = True):\r
try:\r
- Content = ConvertSpecialChar(open(DecFile, 'rb').readlines())\r
+ Content = ConvertSpecialChar(open(DecFile, 'r').readlines())\r
except BaseException:\r
Logger.Error(TOOL_NAME, FILE_OPEN_FAILURE, File=DecFile,\r
ExtraData=ST.ERR_DECPARSE_FILEOPEN % DecFile)\r
else:\r
Base = 10\r
try:\r
- TokenValue = long(Token, Base)\r
+ TokenValue = int(Token, Base)\r
except BaseException:\r
Valid, Cause = IsValidLogicalExpr(Token, True)\r
if Cause:\r
Value = Value.lstrip('0')\r
if not Value:\r
return True, ""\r
- Value = long(Value, 0)\r
- TypeLenMap = {\r
- #\r
- # 0x00 - 0xff\r
- #\r
- 'UINT8' : 2,\r
- #\r
- # 0x0000 - 0xffff\r
- #\r
- 'UINT16' : 4,\r
- #\r
- # 0x00000000 - 0xffffffff\r
- #\r
- 'UINT32' : 8,\r
- #\r
- # 0x0 - 0xffffffffffffffff\r
- #\r
- 'UINT64' : 16\r
- }\r
- HexStr = hex(Value)\r
- #\r
- # First two chars of HexStr are 0x and tail char is L\r
- #\r
- if TypeLenMap[Type] < len(HexStr) - 3:\r
+ Value = int(Value, 0)\r
+ MAX_VAL_TYPE = {"BOOLEAN": 0x01, 'UINT8': 0xFF, 'UINT16': 0xFFFF, 'UINT32': 0xFFFFFFFF,\r
+ 'UINT64': 0xFFFFFFFFFFFFFFFF}\r
+ if Value > MAX_VAL_TYPE[Type]:\r
return False, ST.ERR_DECPARSE_PCD_INT_EXCEED % (StrVal, Type)\r
except BaseException:\r
Valid, Cause = IsValidLogicalExpr(Value, True)\r
\r
try:\r
FullFileName = FullFileName.replace('\\', '/')\r
- Inputfile = open(FullFileName, "rb", 0)\r
+ Inputfile = open(FullFileName, "r")\r
try:\r
FileLinesList = Inputfile.readlines()\r
except BaseException:\r
continue\r
InfFile = InfFile.replace('\\', '/')\r
if InfFile not in GlobalData.gLIBINSTANCEDICT:\r
- InfFileObj = open(InfFile, "rb", 0)\r
+ InfFileObj = open(InfFile, "r")\r
GlobalData.gLIBINSTANCEDICT[InfFile] = InfFileObj\r
else:\r
InfFileObj = GlobalData.gLIBINSTANCEDICT[InfFile]\r
FileLinesList = []\r
\r
try:\r
- FInputfile = open(Filename, "rb", 0)\r
+ FInputfile = open(Filename, "r")\r
try:\r
FileLinesList = FInputfile.readlines()\r
except BaseException:\r
#\r
# Call parent class construct function\r
#\r
- super(InfParser, self).__init__()\r
+ InfSectionParser.__init__()\r
\r
self.WorkspaceDir = WorkspaceDir\r
self.SupArchList = DT.ARCH_LIST\r
self.InfBuildOptionSection = InfBuildOptionsObject()\r
self.InfLibraryClassSection = InfLibraryClassObject()\r
self.InfPackageSection = InfPackageObject()\r
- self.InfPcdSection = InfPcdObject(self.MetaFiles.keys()[0])\r
+ self.InfPcdSection = InfPcdObject(list(self.MetaFiles.keys())[0])\r
self.InfSourcesSection = InfSourcesObject()\r
self.InfUserExtensionSection = InfUserExtensionObject()\r
self.InfProtocolSection = InfProtocolObject()\r
Arch = Match.groups(1)[0].upper()\r
ArchList.append(Arch)\r
CommentSoFar = ''\r
- for Index in xrange(1, len(List)):\r
+ for Index in range(1, len(List)):\r
Result = ParseComment(List[Index], DT.ALL_USAGE_TOKENS, TokenDict, [], False)\r
Usage = Result[0]\r
Type = Result[1]\r
#\r
# Should only have one ArchString Item.\r
#\r
- ArchString = RecordSet.keys()[0]\r
+ ArchString = list(RecordSet.keys())[0]\r
ArchList = GetSplitValueList(ArchString, ' ')\r
ArchList = ConvertArchList(ArchList)\r
HasCalledFlag = False\r
#\r
import locale\r
import sys\r
+from imp import reload\r
encoding = locale.getdefaultlocale()[1]\r
if encoding:\r
reload(sys)\r
CurrentKey = ''\r
PreMap = None\r
Map = None\r
- FileContent = ConvertSpecialChar(open(IniFile, 'rb').readlines())\r
+ FileContent = ConvertSpecialChar(open(IniFile, 'r').readlines())\r
LastIndex = 0\r
for Index in range(0, len(FileContent)):\r
LastIndex = Index\r
if SecondByte != 0:\r
return None\r
\r
- if FirstByte not in xrange(0x20, 0x7F):\r
+ if FirstByte not in range(0x20, 0x7F):\r
return None\r
TransferedStr += ('%c')%FirstByte\r
Index = Index + 2\r