summaryrefslogtreecommitdiffstats
path: root/BaseTools/Source/Python/UPT/Library
diff options
context:
space:
mode:
authorLiming Gao <liming.gao@intel.com>2018-10-15 08:27:53 +0800
committerLiming Gao <liming.gao@intel.com>2018-10-15 08:29:14 +0800
commit1ccc4d895dd8d659d016efcd6ef8a48749aba1d0 (patch)
tree0d5f58643cc72275887d3bb322813609906a9334 /BaseTools/Source/Python/UPT/Library
parent678f85131238622e576705117e299d81cff755c9 (diff)
downloadedk2-1ccc4d895dd8d659d016efcd6ef8a48749aba1d0.tar.gz
edk2-1ccc4d895dd8d659d016efcd6ef8a48749aba1d0.tar.bz2
edk2-1ccc4d895dd8d659d016efcd6ef8a48749aba1d0.zip
Revert BaseTools: PYTHON3 migration
This reverts commit 6693f359b3c213513c5096a06c6f67244a44dc52.. 678f85131238622e576705117e299d81cff755c9. Python3 migration is the fundamental change. It requires every developer to install Python3. Before this migration, the well communication and wide verification must be done. But now, most people is not aware of this change, and not try it. So, Python3 migration is reverted and be moved to edk2-staging Python3 branch for the edk2 user evaluation. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Liming Gao <liming.gao@intel.com>
Diffstat (limited to 'BaseTools/Source/Python/UPT/Library')
-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.py17
-rw-r--r--BaseTools/Source/Python/UPT/Library/UniClassObject.py21
8 files changed, 63 insertions, 54 deletions
diff --git a/BaseTools/Source/Python/UPT/Library/CommentGenerating.py b/BaseTools/Source/Python/UPT/Library/CommentGenerating.py
index 78d3c91581..4726629695 100644
--- a/BaseTools/Source/Python/UPT/Library/CommentGenerating.py
+++ b/BaseTools/Source/Python/UPT/Library/CommentGenerating.py
@@ -124,46 +124,50 @@ 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 + '\n'
+ 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 + '\n'
+ TAB_HEADER_COMMENT + '\r\n'
else:
- Content += CommChar * 2 + TAB_SPACE_SPLIT + TAB_HEADER_COMMENT + '\n'
+ Content += CommChar * 2 + TAB_SPACE_SPLIT + TAB_HEADER_COMMENT + '\r\n'
if Abstract:
- Abstract = Abstract.rstrip('\n')
- Content += CommChar + TAB_SPACE_SPLIT + ('\n' + CommChar + TAB_SPACE_SPLIT).join(GetSplitValueList\
+ Abstract = Abstract.rstrip('\r\n')
+ Content += CommChar + TAB_SPACE_SPLIT + ('\r\n' + CommChar + TAB_SPACE_SPLIT).join(GetSplitValueList\
(Abstract, '\n'))
- Content += '\n' + CommChar + '\n'
+ Content += '\r\n' + CommChar + '\r\n'
else:
- Content += CommChar + '\n'
+ Content += CommChar + '\r\n'
if Description:
- Description = Description.rstrip('\n')
- Content += CommChar + TAB_SPACE_SPLIT + ('\n' + CommChar + TAB_SPACE_SPLIT).join(GetSplitValueList\
+ Description = Description.rstrip('\r\n')
+ Content += CommChar + TAB_SPACE_SPLIT + ('\r\n' + CommChar + TAB_SPACE_SPLIT).join(GetSplitValueList\
(Description, '\n'))
- Content += '\n' + CommChar + '\n'
+ Content += '\r\n' + CommChar + '\r\n'
#
# There is no '#\n' line to separate multiple copyright lines in code base
#
if Copyright:
- Copyright = Copyright.rstrip('\n')
- Content += CommChar + TAB_SPACE_SPLIT + ('\n' + CommChar + TAB_SPACE_SPLIT).join\
+ Copyright = Copyright.rstrip('\r\n')
+ Content += CommChar + TAB_SPACE_SPLIT + ('\r\n' + CommChar + TAB_SPACE_SPLIT).join\
(GetSplitValueList(Copyright, '\n'))
- Content += '\n' + CommChar + '\n'
+ Content += '\r\n' + CommChar + '\r\n'
if License:
- License = License.rstrip('\n')
- Content += CommChar + TAB_SPACE_SPLIT + ('\n' + CommChar + TAB_SPACE_SPLIT).join(GetSplitValueList\
+ License = License.rstrip('\r\n')
+ Content += CommChar + TAB_SPACE_SPLIT + ('\r\n' + CommChar + TAB_SPACE_SPLIT).join(GetSplitValueList\
(License, '\n'))
- Content += '\n' + CommChar + '\n'
+ Content += '\r\n' + CommChar + '\r\n'
if CommChar == TAB_COMMENT_EDK1_SPLIT:
- Content += CommChar + TAB_SPACE_SPLIT + TAB_STAR + TAB_COMMENT_EDK1_END + '\n'
+ Content += CommChar + TAB_SPACE_SPLIT + TAB_STAR + TAB_COMMENT_EDK1_END + '\r\n'
else:
- Content += CommChar * 2 + '\n'
+ Content += CommChar * 2 + '\r\n'
return Content
diff --git a/BaseTools/Source/Python/UPT/Library/CommentParsing.py b/BaseTools/Source/Python/UPT/Library/CommentParsing.py
index 8f9fec7595..285812c9c2 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 range(len(CommentList)-1, 0, -1):
+ for Index in xrange(len(CommentList)-1, 0, -1):
Line = CommentList[Index][0]
if _IsCopyrightLine(Line):
Last = Index
@@ -206,14 +206,17 @@ def ParsePcdErrorCode (Value = None, ContainerFile = None, LineNum = None):
Base = 16
else:
Base = 10
- ErrorCode = int(Value, Base)
+ ErrorCode = long(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)
- return hex(ErrorCode)
+ #
+ # To delete the tailing 'L'
+ #
+ return hex(ErrorCode)[:-1]
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 35b963ed0f..2e0253ab51 100644
--- a/BaseTools/Source/Python/UPT/Library/ExpressionValidate.py
+++ b/BaseTools/Source/Python/UPT/Library/ExpressionValidate.py
@@ -14,6 +14,7 @@
'''
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 f9ca8f32e0..8c2a6787f0 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 collections import UserDict as IterableUserDict
+from UserDict import IterableUserDict
import Logger.Log as Logger
from Logger import StringTable as ST
@@ -160,23 +160,19 @@ 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 isinstance(Content, bytes):
- if Content == __FileHookOpen__(File, "rb").read():
- return False
- else:
- if Content == __FileHookOpen__(File, "r").read():
- return False
+ if Content == __FileHookOpen__(File, "rb").read():
+ return False
except BaseException:
Logger.Error(None, ToolError.FILE_OPEN_FAILURE, ExtraData=File)
CreateDirectory(os.path.dirname(File))
try:
- if isinstance(Content, bytes):
- FileFd = __FileHookOpen__(File, "wb")
- else:
- FileFd = __FileHookOpen__(File, "w")
+ FileFd = __FileHookOpen__(File, "wb")
FileFd.write(Content)
FileFd.close()
except BaseException:
@@ -441,7 +437,7 @@ class Sdict(IterableUserDict):
def CommonPath(PathList):
Path1 = min(PathList).split(os.path.sep)
Path2 = max(PathList).split(os.path.sep)
- for Index in range(min(len(Path1), len(Path2))):
+ for Index in xrange(min(len(Path1), len(Path2))):
if Path1[Index] != Path2[Index]:
return os.path.sep.join(Path1[:Index])
return os.path.sep.join(Path1)
@@ -894,7 +890,7 @@ def ProcessEdkComment(LineList):
if FindEdkBlockComment:
if FirstPos == -1:
FirstPos = StartPos
- for Index in range(StartPos, EndPos+1):
+ for Index in xrange(StartPos, EndPos+1):
LineList[Index] = ''
FindEdkBlockComment = False
elif Line.find("//") != -1 and not Line.startswith("#"):
@@ -961,7 +957,7 @@ def GetLibInstanceInfo(String, WorkSpace, LineNo):
FileLinesList = []
try:
- FInputfile = open(FullFileName, "r")
+ FInputfile = open(FullFileName, "rb", 0)
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 87d156fa4c..31b9b68cd5 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 != b'\xff\xfe':
+ if FileIn != '\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 0564080d35..81729d6cdb 100644
--- a/BaseTools/Source/Python/UPT/Library/Parsing.py
+++ b/BaseTools/Source/Python/UPT/Library/Parsing.py
@@ -16,6 +16,7 @@
'''
Parsing
'''
+from __future__ import absolute_import
##
# Import Modules
@@ -973,7 +974,7 @@ def GenSection(SectionName, SectionDict, SplitArch=True, NeedBlankLine=False):
ArchList = GetSplitValueList(SectionAttrs, DataType.TAB_COMMENT_SPLIT)
else:
ArchList = [SectionAttrs]
- for Index in range(0, len(ArchList)):
+ for Index in xrange(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 011eb98ca6..2be382fa17 100644
--- a/BaseTools/Source/Python/UPT/Library/StringUtils.py
+++ b/BaseTools/Source/Python/UPT/Library/StringUtils.py
@@ -20,6 +20,7 @@ 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
@@ -43,7 +44,7 @@ gMACRO_PATTERN = re.compile("\$\(([_A-Z][_A-Z0-9]*)\)", re.UNICODE)
#
#
def GetSplitValueList(String, SplitTag=DataType.TAB_VALUE_SPLIT, MaxSplit= -1):
- return list(map(lambda l: l.strip(), String.split(SplitTag, MaxSplit)))
+ return map(lambda l: l.strip(), String.split(SplitTag, MaxSplit))
## MergeArches
#
@@ -434,7 +435,7 @@ def GetSingleValueOfKeyFromLines(Lines, Dictionary, CommentCharacter, KeySplitCh
#
LineList[1] = CleanString(LineList[1], CommentCharacter)
if ValueSplitFlag:
- Value = map(lambda x: x.strip(), LineList[1].split(ValueSplitCharacter))
+ Value = map(strip, LineList[1].split(ValueSplitCharacter))
else:
Value = CleanString(LineList[1], CommentCharacter).splitlines()
@@ -501,7 +502,7 @@ def PreCheck(FileName, FileContent, SupSectionTag):
#
# Regenerate FileContent
#
- NewFileContent = NewFileContent + Line + '\n'
+ NewFileContent = NewFileContent + Line + '\r\n'
if IsFailed:
Logger.Error("Parser", FORMAT_INVALID, Line=LineNo, File=FileName, RaiseError=Logger.IS_RAISE_ERROR)
@@ -679,7 +680,9 @@ def GetHelpTextList(HelpTextClassList):
# @param String: the source string
#
def StringArrayLength(String):
- if String.startswith('L"'):
+ if isinstance(String, unicode):
+ return (len(String) + 1) * 2 + 1
+ elif String.startswith('L"'):
return (len(String) - 3 + 1) * 2
elif String.startswith('"'):
return (len(String) - 2 + 1)
@@ -937,14 +940,14 @@ def SplitPcdEntry(String):
def IsMatchArch(Arch1, Arch2):
if 'COMMON' in Arch1 or 'COMMON' in Arch2:
return True
- if isinstance(Arch1, str) and isinstance(Arch2, str):
+ if isinstance(Arch1, basestring) and isinstance(Arch2, basestring):
if Arch1 == Arch2:
return True
- if isinstance(Arch1, str) and isinstance(Arch2, list):
+ if isinstance(Arch1, basestring) and isinstance(Arch2, list):
return Arch1 in Arch2
- if isinstance(Arch2, str) and isinstance(Arch1, list):
+ if isinstance(Arch2, basestring) 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 549f278b05..670cf3b4ee 100644
--- a/BaseTools/Source/Python/UPT/Library/UniClassObject.py
+++ b/BaseTools/Source/Python/UPT/Library/UniClassObject.py
@@ -14,6 +14,7 @@
"""
Collect all defined strings in multiple uni files
"""
+from __future__ import print_function
##
# Import Modules
@@ -246,9 +247,9 @@ def FormatUniEntry(StrTokenName, TokenValueList, ContainerFile):
for SubValue in ValueList:
if SubValue.strip():
SubValueContent += \
- ' ' * (PreFormatLength + len('#language en-US ')) + '\"%s\\n\"' % SubValue.strip() + '\n'
+ ' ' * (PreFormatLength + len('#language en-US ')) + '\"%s\\n\"' % SubValue.strip() + '\r\n'
SubValueContent = SubValueContent[(PreFormatLength + len('#language en-US ')):SubValueContent.rfind('\\n')] \
- + '\"' + '\n'
+ + '\"' + '\r\n'
SubContent += ' '*PreFormatLength + '#language %-5s ' % Lang + SubValueContent
if SubContent:
SubContent = StrTokenName + ' '*(PreFormatLength - len(StrTokenName)) + SubContent[PreFormatLength:]
@@ -290,7 +291,7 @@ class StringDefClassObject(object):
def UpdateValue(self, Value = None):
if Value is not None:
if self.StringValue:
- self.StringValue = self.StringValue + '\n' + Value
+ self.StringValue = self.StringValue + '\r\n' + Value
else:
self.StringValue = Value
self.StringValueByteList = UniToHexList(self.StringValue)
@@ -464,7 +465,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 + '\n'
+ self.UniFileHeader += Line + '\r\n'
continue
#
@@ -510,11 +511,11 @@ class UniFileClassObject(object):
if FileIn[LineCount].strip().startswith('#language'):
Line = Line + FileIn[LineCount]
FileIn[LineCount-1] = Line
- FileIn[LineCount] = '\n'
+ FileIn[LineCount] = '\r\n'
LineCount -= 1
- for Index in range (LineCount + 1, len (FileIn) - 1):
+ for Index in xrange (LineCount + 1, len (FileIn) - 1):
if (Index == len(FileIn) -1):
- FileIn[Index] = '\n'
+ FileIn[Index] = '\r\n'
else:
FileIn[Index] = FileIn[Index + 1]
continue
@@ -866,12 +867,12 @@ class UniFileClassObject(object):
Value = Value + Lines[IndexJ].strip()[1:-1]
CombineToken = False
else:
- Value = Value + Lines[IndexJ].strip()[1:-1] + '\n'
+ Value = Value + Lines[IndexJ].strip()[1:-1] + '\r\n'
else:
IndexI = IndexJ
break
- if Value.endswith('\n'):
- Value = Value[: Value.rfind('\n')]
+ if Value.endswith('\r\n'):
+ Value = Value[: Value.rfind('\r\n')]
Language = GetLanguageCode(Language, self.IsCompatibleMode, self.File)
self.AddStringToList(Name, Language, Value)
continue