BaseTools: Handle the bytes and str difference
Deal with bytes and str is different, remove the unicode() Using utcfromtimestamp instead of fromtimestamp. Cc: Liming Gao <liming.gao@intel.com> Cc: Yonghong Zhu <yonghong.zhu@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Yunhua Feng <yunhuax.feng@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com>
This commit is contained in:
committed by
Yonghong Zhu
parent
a09f4c91f7
commit
86e6cf98a8
@@ -14,7 +14,6 @@
|
||||
import os
|
||||
from . import LongFilePathOsPath
|
||||
from Common.LongFilePathSupport import LongFilePath
|
||||
from Common.LongFilePathSupport import UniToStr
|
||||
import time
|
||||
|
||||
path = LongFilePathOsPath
|
||||
@@ -63,7 +62,7 @@ def listdir(path):
|
||||
List = []
|
||||
uList = os.listdir(u"%s" % LongFilePath(path))
|
||||
for Item in uList:
|
||||
List.append(UniToStr(Item))
|
||||
List.append(Item)
|
||||
return List
|
||||
|
||||
environ = os.environ
|
||||
|
@@ -1,7 +1,7 @@
|
||||
## @file
|
||||
# Override built in function file.open to provide support for long file path
|
||||
#
|
||||
# Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.<BR>
|
||||
# Copyright (c) 2014 - 2018, Intel Corporation. All rights reserved.<BR>
|
||||
# This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
@@ -49,15 +49,3 @@ def CopyLongFilePath(src, dst):
|
||||
with open(LongFilePath(src), 'rb') as fsrc:
|
||||
with open(LongFilePath(dst), 'wb') as fdst:
|
||||
shutil.copyfileobj(fsrc, fdst)
|
||||
|
||||
## Convert a python unicode string to a normal string
|
||||
#
|
||||
# Convert a python unicode string to a normal string
|
||||
# UniToStr(u'I am a string') is 'I am a string'
|
||||
#
|
||||
# @param Uni: The python unicode string
|
||||
#
|
||||
# @retval: The formatted normal string
|
||||
#
|
||||
def UniToStr(Uni):
|
||||
return repr(Uni)[2:-1]
|
||||
|
@@ -454,9 +454,6 @@ def RemoveDirectory(Directory, Recursively=False):
|
||||
# @retval False If the file content is the same
|
||||
#
|
||||
def SaveFileOnChange(File, Content, IsBinaryFile=True):
|
||||
if not IsBinaryFile:
|
||||
Content = Content.replace("\n", os.linesep)
|
||||
|
||||
if os.path.exists(File):
|
||||
try:
|
||||
if isinstance(Content, bytes):
|
||||
@@ -1308,7 +1305,7 @@ def ParseDevPathValue (Value):
|
||||
if err:
|
||||
raise BadExpression("DevicePath: %s" % str(err))
|
||||
Size = len(out.split())
|
||||
out = ','.join(out.split())
|
||||
out = ','.join(out.decode(encoding='utf-8', errors='ignore').split())
|
||||
return '{' + out + '}', Size
|
||||
|
||||
def ParseFieldValue (Value):
|
||||
@@ -1347,7 +1344,7 @@ def ParseFieldValue (Value):
|
||||
if Value[0] == '"' and Value[-1] == '"':
|
||||
Value = Value[1:-1]
|
||||
try:
|
||||
Value = "'" + uuid.UUID(Value).get_bytes_le() + "'"
|
||||
Value = "{" + ','.join([str(i) for i in uuid.UUID(Value).bytes_le]) + "}"
|
||||
except ValueError as Message:
|
||||
raise BadExpression(Message)
|
||||
Value, Size = ParseFieldValue(Value)
|
||||
@@ -1871,7 +1868,7 @@ class PeImageClass():
|
||||
ByteArray = array.array('B')
|
||||
ByteArray.fromfile(PeObject, 4)
|
||||
# PE signature should be 'PE\0\0'
|
||||
if ByteArray.tostring() != 'PE\0\0':
|
||||
if ByteArray.tostring() != b'PE\0\0':
|
||||
self.ErrorInfo = self.FileName + ' has no valid PE signature PE00'
|
||||
return
|
||||
|
||||
|
@@ -815,11 +815,7 @@ def GetHelpTextList(HelpTextClassList):
|
||||
return List
|
||||
|
||||
def StringToArray(String):
|
||||
if isinstance(String, unicode):
|
||||
if len(unicode) == 0:
|
||||
return "{0x00,0x00}"
|
||||
return "{%s,0x00,0x00}" % ",".join("0x%02x,0x00" % ord(C) for C in String)
|
||||
elif String.startswith('L"'):
|
||||
if String.startswith('L"'):
|
||||
if String == "L\"\"":
|
||||
return "{0x00,0x00}"
|
||||
else:
|
||||
@@ -842,9 +838,7 @@ def StringToArray(String):
|
||||
return '{%s,0,0}' % ','.join(String.split())
|
||||
|
||||
def StringArrayLength(String):
|
||||
if isinstance(String, unicode):
|
||||
return (len(String) + 1) * 2 + 1;
|
||||
elif String.startswith('L"'):
|
||||
if String.startswith('L"'):
|
||||
return (len(String) - 3 + 1) * 2
|
||||
elif String.startswith('"'):
|
||||
return (len(String) - 2 + 1)
|
||||
|
@@ -91,18 +91,18 @@ class VpdInfoFile:
|
||||
if (Vpd is None):
|
||||
EdkLogger.error("VpdInfoFile", BuildToolError.ATTRIBUTE_UNKNOWN_ERROR, "Invalid VPD PCD entry.")
|
||||
|
||||
if not (Offset >= 0 or Offset == "*"):
|
||||
if not (Offset >= "0" or Offset == "*"):
|
||||
EdkLogger.error("VpdInfoFile", BuildToolError.PARAMETER_INVALID, "Invalid offset parameter: %s." % Offset)
|
||||
|
||||
if Vpd.DatumType == TAB_VOID:
|
||||
if Vpd.MaxDatumSize <= 0:
|
||||
if Vpd.MaxDatumSize <= "0":
|
||||
EdkLogger.error("VpdInfoFile", BuildToolError.PARAMETER_INVALID,
|
||||
"Invalid max datum size for VPD PCD %s.%s" % (Vpd.TokenSpaceGuidCName, Vpd.TokenCName))
|
||||
elif Vpd.DatumType in TAB_PCD_NUMERIC_TYPES:
|
||||
if not Vpd.MaxDatumSize:
|
||||
Vpd.MaxDatumSize = MAX_SIZE_TYPE[Vpd.DatumType]
|
||||
else:
|
||||
if Vpd.MaxDatumSize <= 0:
|
||||
if Vpd.MaxDatumSize <= "0":
|
||||
EdkLogger.error("VpdInfoFile", BuildToolError.PARAMETER_INVALID,
|
||||
"Invalid max datum size for VPD PCD %s.%s" % (Vpd.TokenSpaceGuidCName, Vpd.TokenCName))
|
||||
|
||||
@@ -126,7 +126,7 @@ class VpdInfoFile:
|
||||
"Invalid parameter FilePath: %s." % FilePath)
|
||||
|
||||
Content = FILE_COMMENT_TEMPLATE
|
||||
Pcds = sorted(self._VpdArray.keys())
|
||||
Pcds = sorted(self._VpdArray.keys(), key=lambda x: x.TokenCName)
|
||||
for Pcd in Pcds:
|
||||
i = 0
|
||||
PcdTokenCName = Pcd.TokenCName
|
||||
@@ -248,7 +248,7 @@ def CallExtenalBPDGTool(ToolPath, VpdFileName):
|
||||
except Exception as X:
|
||||
EdkLogger.error("BPDG", BuildToolError.COMMAND_FAILURE, ExtraData=str(X))
|
||||
(out, error) = PopenObject.communicate()
|
||||
print(out)
|
||||
print(out.decode(encoding='utf-8', errors='ignore'))
|
||||
while PopenObject.returncode is None :
|
||||
PopenObject.wait()
|
||||
|
||||
|
Reference in New Issue
Block a user