public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Feng, Bob C" <bob.c.feng@intel.com>
To: edk2-devel@lists.01.org
Cc: Zhijux Fan <zhijux.fan@intel.com>,
	Bob Feng <bob.c.feng@intel.com>,
	Liming Gao <liming.gao@intel.com>,
	Yonghong Zhu <yonghong.zhu@intel.com>
Subject: [Patch 12/33] BaseTools/UPT:merge UPT Tool use Python2 and Python3
Date: Tue, 29 Jan 2019 10:05:49 +0800	[thread overview]
Message-ID: <20190129020610.14300-13-bob.c.feng@intel.com> (raw)
In-Reply-To: <20190129020610.14300-1-bob.c.feng@intel.com>

From: Zhijux Fan <zhijux.fan@intel.com>

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>
---
 BaseTools/Source/Python/UPT/Core/IpiDb.py                 |   4 ++--
 BaseTools/Source/Python/UPT/GenMetaFile/GenInfFile.py     |   6 +++---
 BaseTools/Source/Python/UPT/Library/CommentGenerating.py  |   6 ++----
 BaseTools/Source/Python/UPT/Library/CommentParsing.py     |  10 ++++------
 BaseTools/Source/Python/UPT/Library/Misc.py               | 190 ++++++++++++++++++++++++++++++----------------------------------------------------------------------------------------------------------------------------------------------------------------
 BaseTools/Source/Python/UPT/Library/ParserValidate.py     |   2 +-
 BaseTools/Source/Python/UPT/Library/Parsing.py            |   2 +-
 BaseTools/Source/Python/UPT/Library/StringUtils.py        |  36 ++++++++++++++++++------------------
 BaseTools/Source/Python/UPT/Library/UniClassObject.py     |   6 ++++--
 BaseTools/Source/Python/UPT/Library/Xml/XmlRoutines.py    |   2 +-
 BaseTools/Source/Python/UPT/Logger/StringTable.py         |   2 +-
 BaseTools/Source/Python/UPT/Parser/DecParser.py           |   4 ++--
 BaseTools/Source/Python/UPT/Parser/DecParserMisc.py       |  30 +++++-------------------------
 BaseTools/Source/Python/UPT/Parser/InfAsBuiltProcess.py   |   4 ++--
 BaseTools/Source/Python/UPT/Parser/InfParser.py           |   4 ++--
 BaseTools/Source/Python/UPT/Parser/InfSectionParser.py    |   4 ++--
 BaseTools/Source/Python/UPT/PomAdapter/InfPomAlignment.py |   2 +-
 BaseTools/Source/Python/UPT/UPT.py                        |   1 +
 BaseTools/Source/Python/UPT/Xml/IniToXml.py               |   2 +-
 BaseTools/Source/Python/UPT/Xml/XmlParserMisc.py          |   2 +-
 20 files changed, 84 insertions(+), 235 deletions(-)

diff --git a/BaseTools/Source/Python/UPT/Core/IpiDb.py b/BaseTools/Source/Python/UPT/Core/IpiDb.py
index a781d358c8..48defeac7e 100644
--- a/BaseTools/Source/Python/UPT/Core/IpiDb.py
+++ b/BaseTools/Source/Python/UPT/Core/IpiDb.py
@@ -42,11 +42,11 @@ import platform as pf
 class IpiDatabase(object):
     def __init__(self, DbPath, Workspace):
         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(u''.join(DbPath), isolation_level='DEFERRED')
         self.Conn.execute("PRAGMA page_size=4096")
         self.Conn.execute("PRAGMA synchronous=OFF")
         self.Cur = self.Conn.cursor()
         self.DpTable = 'DpInfo'
         self.PkgTable = 'PkgInfo'
@@ -919,10 +919,10 @@ class IpiDatabase(object):
     # @param StringList:  A list for strings to be converted
     #
     def __ConvertToSqlString(self, StringList):
         if self.DpTable:
             pass
-        return map(lambda s: s.replace("'", "''"), StringList)
+        return list(map(lambda s: s.replace("'", "''"), StringList))
 
 
 
 
diff --git a/BaseTools/Source/Python/UPT/GenMetaFile/GenInfFile.py b/BaseTools/Source/Python/UPT/GenMetaFile/GenInfFile.py
index c2a240a884..1f8b3f163e 100644
--- a/BaseTools/Source/Python/UPT/GenMetaFile/GenInfFile.py
+++ b/BaseTools/Source/Python/UPT/GenMetaFile/GenInfFile.py
@@ -272,11 +272,11 @@ def GenDefines(ModuleObject):
     for UserExtension in ModuleObject.GetUserExtensionList():
         DefinesDict = UserExtension.GetDefinesDict()
         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
             if Statement.strip().startswith(DT.TAB_INF_DEFINES_CUSTOM_MAKEFILE):
                 pos = Statement.find(DT.TAB_VALUE_SPLIT)
@@ -407,11 +407,11 @@ def GenLibraryClasses(ModuleObject):
             Statement += Name
             if FFE:
                 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)
             KeyList = []
             if not ModuleList or IsAllModuleList(ModuleList):
@@ -570,11 +570,11 @@ def GenUserExtensions(ModuleObject):
         Statement = UserExtension.GetStatement()
 # Comment the code to support user extension without any statement just the section header in []
 #         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 = []
         CommonPreFix = ''
         if UserExtension.GetUserID():
diff --git a/BaseTools/Source/Python/UPT/Library/CommentGenerating.py b/BaseTools/Source/Python/UPT/Library/CommentGenerating.py
index 4726629695..bd3514bc49 100644
--- a/BaseTools/Source/Python/UPT/Library/CommentGenerating.py
+++ b/BaseTools/Source/Python/UPT/Library/CommentGenerating.py
@@ -122,14 +122,12 @@ def GenHeaderCommentSection(Abstract, Description, Copyright, License, IsBinaryH
     Content = ''
 
     #
     # Convert special character to (c), (r) and (tm).
     #
-    if isinstance(Abstract, unicode):
-        Abstract = ConvertSpecialUnicodes(Abstract)
-    if isinstance(Description, unicode):
-        Description = ConvertSpecialUnicodes(Description)
+    Abstract = ConvertSpecialUnicodes(Abstract)
+    Description = ConvertSpecialUnicodes(Description)
     if IsBinaryHeader:
         Content += CommChar * 2 + TAB_SPACE_SPLIT + TAB_BINARY_HEADER_COMMENT + '\r\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'
diff --git a/BaseTools/Source/Python/UPT/Library/CommentParsing.py b/BaseTools/Source/Python/UPT/Library/CommentParsing.py
index 285812c9c2..a09a530ffb 100644
--- a/BaseTools/Source/Python/UPT/Library/CommentParsing.py
+++ b/BaseTools/Source/Python/UPT/Library/CommentParsing.py
@@ -72,11 +72,11 @@ 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
             break
 
@@ -204,21 +204,19 @@ def ParsePcdErrorCode (Value = None, ContainerFile = None, LineNum = None):
     try:
         if Value.strip().startswith((TAB_HEX_START, TAB_CAPHEX_START)):
             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]
+        ErrorCode = '0x%x' % ErrorCode
+        return ErrorCode
     except ValueError as XStr:
         if XStr:
             pass
         Logger.Error('Parser',
                     FORMAT_NOT_SUPPORTED,
diff --git a/BaseTools/Source/Python/UPT/Library/Misc.py b/BaseTools/Source/Python/UPT/Library/Misc.py
index 8c2a6787f0..d69b161420 100644
--- a/BaseTools/Source/Python/UPT/Library/Misc.py
+++ b/BaseTools/Source/Python/UPT/Library/Misc.py
@@ -30,11 +30,11 @@ from os import remove
 from os import rmdir
 from os import linesep
 from os import walk
 from os import environ
 import re
-from UserDict import IterableUserDict
+from collections import OrderedDict
 
 import Logger.Log as Logger
 from Logger import StringTable as ST
 from Logger import ToolError
 from Library import GlobalData
@@ -158,27 +158,39 @@ def RemoveDirectory(Directory, Recursively=False):
 # @param      Content:         The new content of the file
 # @param      IsBinaryFile:    The flag indicating if the file is binary file
 #                              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
-        except BaseException:
-            Logger.Error(None, ToolError.FILE_OPEN_FAILURE, ExtraData=File)
+        if IsBinaryFile:
+            try:
+                if Content == __FileHookOpen__(File, "rb").read():
+                    return False
+            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))
-    try:
-        FileFd = __FileHookOpen__(File, "wb")
-        FileFd.write(Content)
-        FileFd.close()
-    except BaseException:
-        Logger.Error(None, ToolError.FILE_CREATE_FAILURE, ExtraData=File)
+    if IsBinaryFile:
+        try:
+            FileFd = __FileHookOpen__(File, "wb")
+            FileFd.write(Content)
+            FileFd.close()
+        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
 
 ## Get all files of a directory
 #
@@ -286,160 +298,18 @@ def RealPath2(File, Dir='', OverrideDir=''):
         else:
             return NewFile, ''
 
     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
 #
 # @param PathList: PathList
 #
 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)
 
 ## PathClass
@@ -888,11 +758,11 @@ def ProcessEdkComment(LineList):
                 Count = Count + 1
 
             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("#"):
             #
             # handling cpp style comment
@@ -955,11 +825,11 @@ def GetLibInstanceInfo(String, WorkSpace, LineNo):
         return False
     if IsValidFileFlag:
         FileLinesList = []
 
         try:
-            FInputfile = open(FullFileName, "rb", 0)
+            FInputfile = open(FullFileName, "r")
             try:
                 FileLinesList = FInputfile.readlines()
             except BaseException:
                 Logger.Error("InfParser",
                              ToolError.FILE_READ_FAILURE,
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
@@ -725,9 +725,9 @@ def IsValidUserId(UserId):
 #
 # Check if a UTF16-LE file has a BOM header
 #
 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..3eca8e3849 100644
--- a/BaseTools/Source/Python/UPT/Library/Parsing.py
+++ b/BaseTools/Source/Python/UPT/Library/Parsing.py
@@ -972,11 +972,11 @@ def GenSection(SectionName, SectionDict, SplitArch=True, NeedBlankLine=False):
             else:
                 if SectionName != 'UserExtensions':
                     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:
             Section = '[' + SectionName + ']'
         Content += '\n' + Section + '\n'
diff --git a/BaseTools/Source/Python/UPT/Library/StringUtils.py b/BaseTools/Source/Python/UPT/Library/StringUtils.py
index 2be382fa17..90946337d0 100644
--- a/BaseTools/Source/Python/UPT/Library/StringUtils.py
+++ b/BaseTools/Source/Python/UPT/Library/StringUtils.py
@@ -18,11 +18,10 @@ StringUtils
 ##
 # Import Modules
 #
 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
 from Logger.ToolError import PARSER_ERROR
 from Logger import StringTable as ST
@@ -42,11 +41,11 @@ gMACRO_PATTERN = re.compile("\$\(([_A-Z][_A-Z0-9]*)\)", re.UNICODE)
 # @param SplitTag:  The split key, default is DataType.TAB_VALUE_SPLIT
 # @param MaxSplit:  The max number of split values, default is -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
 #
 # Find a key's all arches in dict, add the new arch to the list
 # If not exist any arch, set the arch directly
@@ -433,11 +432,11 @@ def GetSingleValueOfKeyFromLines(Lines, Dictionary, CommentCharacter, KeySplitCh
                 #
                 # Remove comments and white spaces
                 #
                 LineList[1] = CleanString(LineList[1], CommentCharacter)
                 if ValueSplitFlag:
-                    Value = map(strip, LineList[1].split(ValueSplitCharacter))
+                    Value = list(map(lambda x: x.strip(), LineList[1].split(ValueSplitCharacter)))
                 else:
                     Value = CleanString(LineList[1], CommentCharacter).splitlines()
 
                 if Key[0] in Dictionary:
                     if Key[0] not in Keys:
@@ -630,11 +629,11 @@ def SplitString(String):
 # Replace "'" with "''" in each item of StringList
 #
 # @param StringList:  A list for strings to be converted
 #
 def ConvertToSqlString(StringList):
-    return map(lambda s: s.replace("'", "''"), StringList)
+    return list(map(lambda s: s.replace("'", "''"), StringList))
 
 ## Convert To Sql String
 #
 # Replace "'" with "''" in the String
 #
@@ -938,27 +937,28 @@ def SplitPcdEntry(String):
 # @param Arch2
 #
 def IsMatchArch(Arch1, Arch2):
     if 'COMMON' in Arch1 or 'COMMON' in Arch2:
         return True
-    if isinstance(Arch1, basestring) and isinstance(Arch2, basestring):
-        if Arch1 == Arch2:
-            return True
-
-    if isinstance(Arch1, basestring) and isinstance(Arch2, list):
-        return Arch1 in Arch2
+    try:
+        if isinstance(Arch1, list) and isinstance(Arch2, list):
+            for Item1 in Arch1:
+                for Item2 in Arch2:
+                    if Item1 == Item2:
+                        return True
 
-    if isinstance(Arch2, basestring) and isinstance(Arch1, list):
-        return Arch2 in Arch1
+        elif isinstance(Arch1, list):
+            return Arch2 in Arch1
 
-    if isinstance(Arch1, list) and isinstance(Arch2, list):
-        for Item1 in Arch1:
-            for Item2 in Arch2:
-                if Item1 == Item2:
-                    return True
+        elif isinstance(Arch2, list):
+            return Arch1 in Arch2
 
-    return False
+        else:
+            if Arch1 == Arch2:
+                return True
+    except:
+        return False
 
 # Search all files in FilePath to find the FileName with the largest index
 # Return the FileName with index +1 under the FilePath
 #
 def GetUniFileName(FilePath, FileName):
diff --git a/BaseTools/Source/Python/UPT/Library/UniClassObject.py b/BaseTools/Source/Python/UPT/Library/UniClassObject.py
index cd575d5a34..bd7804b753 100644
--- a/BaseTools/Source/Python/UPT/Library/UniClassObject.py
+++ b/BaseTools/Source/Python/UPT/Library/UniClassObject.py
@@ -117,14 +117,16 @@ def UniToHexList(Uni):
 # @param Uni:    The python unicode string
 #
 # @retval NewUni:  The converted unicode string
 #
 def ConvertSpecialUnicodes(Uni):
-    NewUni = Uni
+    OldUni = NewUni = Uni
     NewUni = NewUni.replace(u'\u00A9', '(c)')
     NewUni = NewUni.replace(u'\u00AE', '(r)')
     NewUni = NewUni.replace(u'\u2122', '(tm)')
+    if OldUni == NewUni:
+        NewUni = OldUni
     return NewUni
 
 ## GetLanguageCode1766
 #
 # Check the language code read from .UNI file and convert RFC 4646 codes to RFC 1766 codes
@@ -511,11 +513,11 @@ class UniFileClassObject(object):
                 if FileIn[LineCount].strip().startswith('#language'):
                     Line = Line + FileIn[LineCount]
                     FileIn[LineCount-1] = Line
                     FileIn[LineCount] = '\r\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'
                         else:
                             FileIn[Index] = FileIn[Index + 1]
                     continue
diff --git a/BaseTools/Source/Python/UPT/Library/Xml/XmlRoutines.py b/BaseTools/Source/Python/UPT/Library/Xml/XmlRoutines.py
index ee158f33d9..b24e3ed01b 100644
--- a/BaseTools/Source/Python/UPT/Library/Xml/XmlRoutines.py
+++ b/BaseTools/Source/Python/UPT/Library/Xml/XmlRoutines.py
@@ -178,11 +178,11 @@ def XmlElementData(Dom):
 #
 # @param  Dom                The root XML DOM object.
 # @param  String             A XPath style path.
 #
 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.
 #
 # Return a single XML attribute named Attribute from the current root Dom.
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
@@ -40,11 +40,11 @@ MSG_USAGE_STRING = _("\n"
 # Version and Copyright
 #
 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, " + \
                     "install or remove a UEFI Distribution Package. " + \
                     "If WORKSPACE environment variable is present, " + \
diff --git a/BaseTools/Source/Python/UPT/Parser/DecParser.py b/BaseTools/Source/Python/UPT/Parser/DecParser.py
index 8f3d60df57..f7eeb84127 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 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:
             if self.TokenMap[Guid, IntToken] != CName:
                 self._LoggerError(ST.ERR_DECPARSE_PCD_TOKEN_UNIQUE%(Token))
@@ -750,11 +750,11 @@ class _DecUserExtension(_DecBase):
 # Top dec parser
 #
 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..9ec3462c77 100644
--- a/BaseTools/Source/Python/UPT/Parser/DecParserMisc.py
+++ b/BaseTools/Source/Python/UPT/Parser/DecParserMisc.py
@@ -149,11 +149,11 @@ def IsValidNumValUint8(Token):
     if Token.lower().startswith('0x'):
         Base = 16
     else:
         Base = 10
     try:
-        TokenValue = long(Token, Base)
+        TokenValue = int(Token, Base)
     except BaseException:
         Valid, Cause = IsValidLogicalExpr(Token, True)
         if Cause:
             pass
     if not Valid:
@@ -260,34 +260,14 @@ def IsValidPcdDatum(Type, Value):
             if Value and not Value.startswith('0x') \
                 and not Value.startswith('0X'):
                 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)
         if not Valid:
             return False, Cause
diff --git a/BaseTools/Source/Python/UPT/Parser/InfAsBuiltProcess.py b/BaseTools/Source/Python/UPT/Parser/InfAsBuiltProcess.py
index 029a436cec..c314892adf 100644
--- a/BaseTools/Source/Python/UPT/Parser/InfAsBuiltProcess.py
+++ b/BaseTools/Source/Python/UPT/Parser/InfAsBuiltProcess.py
@@ -203,11 +203,11 @@ def GetFileLineContent(FileName, WorkSpace, LineNo, OriginalString):
 
     FileLinesList = []
 
     try:
         FullFileName = FullFileName.replace('\\', '/')
-        Inputfile = open(FullFileName, "rb", 0)
+        Inputfile = open(FullFileName, "r")
         try:
             FileLinesList = Inputfile.readlines()
         except BaseException:
             Logger.Error("InfParser", ToolError.FILE_READ_FAILURE, ST.ERR_FILE_OPEN_FAILURE, File=FullFileName)
         finally:
@@ -245,11 +245,11 @@ def GetGuidVerFormLibInstance(Guid, Version, WorkSpace, CurrentInfFileName):
         try:
             if InfFile.strip().upper() == CurrentInfFileName.strip().upper():
                 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]
 
         except BaseException:
diff --git a/BaseTools/Source/Python/UPT/Parser/InfParser.py b/BaseTools/Source/Python/UPT/Parser/InfParser.py
index cd99262e03..5df7320324 100644
--- a/BaseTools/Source/Python/UPT/Parser/InfParser.py
+++ b/BaseTools/Source/Python/UPT/Parser/InfParser.py
@@ -49,11 +49,11 @@ from Parser.InfParserMisc import IsBinaryInf
 #
 def OpenInfFile(Filename):
     FileLinesList = []
 
     try:
-        FInputfile = open(Filename, "rb", 0)
+        FInputfile = open(Filename, "r")
         try:
             FileLinesList = FInputfile.readlines()
         except BaseException:
             Logger.Error("InfParser",
                          FILE_READ_FAILURE,
@@ -84,11 +84,11 @@ class InfParser(InfSectionParser):
     def __init__(self, Filename = None, WorkspaceDir = None):
 
         #
         # Call parent class construct function
         #
-        super(InfParser, self).__init__()
+        InfSectionParser.__init__()
 
         self.WorkspaceDir    = WorkspaceDir
         self.SupArchList     = DT.ARCH_LIST
         self.EventList    = []
         self.HobList      = []
diff --git a/BaseTools/Source/Python/UPT/Parser/InfSectionParser.py b/BaseTools/Source/Python/UPT/Parser/InfSectionParser.py
index 1f254058d1..d9c9d41fcb 100644
--- a/BaseTools/Source/Python/UPT/Parser/InfSectionParser.py
+++ b/BaseTools/Source/Python/UPT/Parser/InfSectionParser.py
@@ -225,11 +225,11 @@ class InfSectionParser(InfDefinSectionParser,
         #
         self.InfDefSection = InfDefObject()
         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()
         self.InfPpiSection = InfPpiObject()
         self.InfGuidSection = InfGuidObject()
@@ -453,11 +453,11 @@ class InfSectionParser(InfDefinSectionParser,
                 ArchList = []
                 for Match in ReFindHobArchRe.finditer(HobSectionStr):
                     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]
                 HelpText = Result[3]
 
diff --git a/BaseTools/Source/Python/UPT/PomAdapter/InfPomAlignment.py b/BaseTools/Source/Python/UPT/PomAdapter/InfPomAlignment.py
index c055089f2c..2e83c247ed 100644
--- a/BaseTools/Source/Python/UPT/PomAdapter/InfPomAlignment.py
+++ b/BaseTools/Source/Python/UPT/PomAdapter/InfPomAlignment.py
@@ -131,11 +131,11 @@ class InfPomAlignment(ModuleObject):
         #
         RecordSet = self.Parser.InfDefSection.Defines
         #
         # Should only have one ArchString Item.
         #
-        ArchString = RecordSet.keys()[0]
+        ArchString = list(RecordSet.keys())[0]
         ArchList = GetSplitValueList(ArchString, ' ')
         ArchList = ConvertArchList(ArchList)
         HasCalledFlag = False
         #
         # Get data from Sdict()
diff --git a/BaseTools/Source/Python/UPT/UPT.py b/BaseTools/Source/Python/UPT/UPT.py
index 004fc5ff2f..55b63a3ca1 100644
--- a/BaseTools/Source/Python/UPT/UPT.py
+++ b/BaseTools/Source/Python/UPT/UPT.py
@@ -19,10 +19,11 @@ UPT
 
 ## import modules
 #
 import locale
 import sys
+from imp import reload
 encoding = locale.getdefaultlocale()[1]
 if encoding:
     reload(sys)
     sys.setdefaultencoding(encoding)
 from Core import FileHook
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
@@ -324,11 +324,11 @@ def IniToXml(IniFile):
 
     SectionName = ''
     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
         Line = FileContent[Index].strip()
         if Line == '' or Line.startswith(';'):
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
@@ -51,11 +51,11 @@ def ConvertVariableName(VariableName):
         FirstByte = int(ValueList[Index], 16)
         SecondByte = int(ValueList[Index + 1], 16)
         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
 
     return 'L"' + TransferedStr + '"'
-- 
2.20.1.windows.1



  parent reply	other threads:[~2019-01-29  2:06 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-29  2:05 [Patch v2 00/33] BaseTools python3 migration patch set Feng, Bob C
2019-01-29  2:05 ` [Patch 01/33] BaseTool:Rename xrange() to range() Feng, Bob C
2019-01-29  2:05 ` [Patch 02/33] BaseTools:use iterate list to replace the itertools Feng, Bob C
2019-01-29  2:05 ` [Patch 03/33] BaseTools: Rename iteritems to items Feng, Bob C
2019-01-29  2:05 ` [Patch 04/33] BaseTools: replace get_bytes_le() to bytes_le Feng, Bob C
2019-01-29  2:05 ` [Patch 05/33] BaseTools: use OrderedDict instead of sdict Feng, Bob C
2019-01-29  2:05 ` [Patch 06/33] BaseTools: nametuple not have verbose parameter in python3 Feng, Bob C
2019-01-29  2:05 ` [Patch 07/33] BaseTools: Remove unnecessary super function Feng, Bob C
2019-01-29  2:05 ` [Patch 08/33] BaseTools: replace long by int Feng, Bob C
2019-01-29  2:05 ` [Patch 09/33] BaseTools:Solve the data sorting problem use python3 Feng, Bob C
2019-01-29  2:05 ` [Patch 10/33] BaseTools: Update argparse arguments since it not have version now Feng, Bob C
2019-01-29  2:05 ` [Patch 11/33] BaseTools:Similar to octal data rectification Feng, Bob C
2019-01-29  2:05 ` Feng, Bob C [this message]
2019-01-29  2:05 ` [Patch 13/33] BaseTools: update Test scripts support python3 Feng, Bob C
2019-01-29  2:05 ` [Patch 14/33] BaseTools/Scripts: Porting PackageDocumentTools code to use Python3 Feng, Bob C
2019-01-29  2:05 ` [Patch 15/33] Basetools: It went wrong when use os.linesep Feng, Bob C
2019-01-29  2:05 ` [Patch 16/33] BaseTools:Fv BaseAddress must set If it not set Feng, Bob C
2019-01-29  2:05 ` [Patch 17/33] BaseTools: Make sure AllPcdList valid Feng, Bob C
2019-01-29  2:05 ` [Patch 18/33] BaseTools:TestTools character encoding issue Feng, Bob C
2019-01-29  2:05 ` [Patch 19/33] BaseTools:Double carriage return inserted from Trim.py on Python3 Feng, Bob C
2019-01-29  2:05 ` [Patch 20/33] BaseTools:File open failed for VPD MapFile Feng, Bob C
2019-01-29  2:05 ` [Patch 21/33] BaseTools: change the Division Operator Feng, Bob C
2019-01-29  2:05 ` [Patch 22/33] BaseTools:There is extra blank line in datalog Feng, Bob C
2019-01-29  2:06 ` [Patch 23/33] BaseTools: Similar to octal data rectification Feng, Bob C
2019-01-29  2:06 ` [Patch 24/33] BaseTools: Update windows and linux run scripts file to use Python3 Feng, Bob C
2019-01-29  2:06 ` [Patch 25/33] BaseTools:Update build tool to print python version information Feng, Bob C
2019-01-29  2:06 ` [Patch 26/33] BaseTools:Linux Python highest version check Feng, Bob C
2019-01-29  2:06 ` [Patch 27/33] BaseTools: Update PYTHON env to PYTHON_COMMAND Feng, Bob C
2019-01-29  2:06 ` [Patch 28/33] BaseTools:Fixed Rsa issue and a set define issue Feng, Bob C
2019-01-29  2:06 ` [Patch 29/33] BaseTools:ord() don't match in py2 and py3 Feng, Bob C
2019-01-29  2:06 ` [Patch 30/33] BaseTools: the list and iterator translation Feng, Bob C
2019-01-29  2:06 ` [Patch 31/33] BaseTools: Handle the bytes and str difference Feng, Bob C
2019-01-29  2:06 ` [Patch 32/33] BaseTools: ECC tool Python3 adaption Feng, Bob C
     [not found]   ` <20190902190211.GZ29255@bivouac.eciton.net>
2019-09-02 19:04     ` [edk2] " Leif Lindholm
2019-09-04  2:10       ` [edk2-devel] " Bob Feng
2019-09-04  8:38         ` Leif Lindholm
2019-09-04  9:12           ` Bob Feng
2019-09-04  9:51             ` Leif Lindholm
2019-09-05  5:39               ` Bob Feng
2019-09-05 10:37                 ` Leif Lindholm
2019-09-05 13:53                   ` Laszlo Ersek
2019-01-29  2:06 ` [Patch v2 33/33] BaseTools: Eot " Feng, Bob C
2019-01-29 13:07 ` [Patch v2 00/33] BaseTools python3 migration patch set Laszlo Ersek
2019-01-30  1:52   ` Gao, Liming
2019-01-30  5:25     ` Feng, Bob C
2019-01-31  8:23       ` Gao, Liming
2019-02-01  3:13         ` Feng, Bob C
2019-02-01  8:50           ` Laszlo Ersek
2019-01-30  2:59   ` Feng, Bob C
  -- strict thread matches above, loose matches on Subject: below --
2019-01-25  4:55 [Patch " Feng, Bob C
2019-01-25  4:56 ` [Patch 12/33] BaseTools/UPT:merge UPT Tool use Python2 and Python3 Feng, Bob C

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190129020610.14300-13-bob.c.feng@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox