BaseTools: Refactor python except statements

Convert "except ... ," to "except ... as" to be compatible with python3.
Based on "futurize -f lib2to3.fixes.fix_except"

Contributed-under: TianoCore Contribution Agreement 1.1
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Signed-off-by: Gary Lin <glin@suse.com>
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
This commit is contained in:
Gary Lin
2018-06-25 18:31:25 +08:00
committed by Yonghong Zhu
parent 00eb12a2c7
commit 5b0671c1e5
46 changed files with 254 additions and 250 deletions

View File

@@ -394,7 +394,7 @@ def VerifyRemoveModuleDep(Path, DpPackagePathList):
return False
else:
return True
except FatalError, ErrCode:
except FatalError as ErrCode:
if ErrCode.message == EDK1_INF_ERROR:
Logger.Warn("UPT",
ST.WRN_EDK1_INF_FOUND%Path)
@@ -446,7 +446,7 @@ def VerifyReplaceModuleDep(Path, DpPackagePathList, OtherPkgList):
return False
else:
return True
except FatalError, ErrCode:
except FatalError as ErrCode:
if ErrCode.message == EDK1_INF_ERROR:
Logger.Warn("UPT",
ST.WRN_EDK1_INF_FOUND%Path)

View File

@@ -155,7 +155,7 @@ class DistributionPackageClass(object):
ModuleObj.GetName(), \
ModuleObj.GetCombinePath())] = ModuleObj
PackageObj.SetModuleDict(ModuleDict)
except FatalError, ErrCode:
except FatalError as ErrCode:
if ErrCode.message == EDK1_INF_ERROR:
Logger.Warn("UPT",
ST.WRN_EDK1_INF_FOUND%Filename)
@@ -181,7 +181,7 @@ class DistributionPackageClass(object):
ModuleObj.GetName(),
ModuleObj.GetCombinePath())
self.ModuleSurfaceArea[ModuleKey] = ModuleObj
except FatalError, ErrCode:
except FatalError as ErrCode:
if ErrCode.message == EDK1_INF_ERROR:
Logger.Error("UPT",
EDK1_INF_ERROR,

View File

@@ -230,7 +230,7 @@ class IpiDatabase(object):
self._AddDp(DpObj.Header.GetGuid(), DpObj.Header.GetVersion(), \
NewDpPkgFileName, DpPkgFileName, RePackage)
except sqlite3.IntegrityError, DetailMsg:
except sqlite3.IntegrityError as DetailMsg:
Logger.Error("UPT",
UPT_DB_UPDATE_ERROR,
ST.ERR_UPT_DB_UPDATE_ERROR,

View File

@@ -51,7 +51,7 @@ class PackageFile:
self._Files = {}
for Filename in self._ZipFile.namelist():
self._Files[os.path.normpath(Filename)] = Filename
except BaseException, Xstr:
except BaseException as Xstr:
Logger.Error("PackagingTool", FILE_OPEN_FAILURE,
ExtraData="%s (%s)" % (FileName, str(Xstr)))
@@ -106,7 +106,7 @@ class PackageFile:
ExtraData="[%s] in %s" % (Which, self._FileName))
try:
FileContent = self._ZipFile.read(self._Files[Which])
except BaseException, Xstr:
except BaseException as Xstr:
Logger.Error("PackagingTool", FILE_DECOMPRESS_FAILURE,
ExtraData="[%s] in %s (%s)" % (Which, \
self._FileName, \
@@ -119,14 +119,14 @@ class PackageFile:
return
else:
ToFile = __FileHookOpen__(ToDest, 'wb')
except BaseException, Xstr:
except BaseException as Xstr:
Logger.Error("PackagingTool", FILE_OPEN_FAILURE,
ExtraData="%s (%s)" % (ToDest, str(Xstr)))
try:
ToFile.write(FileContent)
ToFile.close()
except BaseException, Xstr:
except BaseException as Xstr:
Logger.Error("PackagingTool", FILE_WRITE_FAILURE,
ExtraData="%s (%s)" % (ToDest, str(Xstr)))
@@ -228,7 +228,7 @@ class PackageFile:
return
Logger.Info("packing ..." + File)
self._ZipFile.write(File, ArcName)
except BaseException, Xstr:
except BaseException as Xstr:
Logger.Error("PackagingTool", FILE_COMPRESS_FAILURE,
ExtraData="%s (%s)" % (File, str(Xstr)))
@@ -242,7 +242,7 @@ class PackageFile:
if os.path.splitext(ArcName)[1].lower() == '.pkg':
Data = Data.encode('utf_8')
self._ZipFile.writestr(ArcName, Data)
except BaseException, Xstr:
except BaseException as Xstr:
Logger.Error("PackagingTool", FILE_COMPRESS_FAILURE,
ExtraData="%s (%s)" % (ArcName, str(Xstr)))

View File

@@ -537,7 +537,7 @@ def Main(Options = None):
Options, Dep, WorkspaceDir, DataBase)
ReturnCode = 0
except FatalError, XExcept:
except FatalError as XExcept:
ReturnCode = XExcept.args[0]
if Logger.GetLevel() <= Logger.DEBUG_9:
Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + format_exc())

View File

@@ -92,7 +92,7 @@ def Main(Options = None):
DataBase = GlobalData.gDB
InventoryDistInstalled(DataBase)
ReturnCode = 0
except FatalError, XExcept:
except FatalError as XExcept:
ReturnCode = XExcept.args[0]
if Logger.GetLevel() <= Logger.DEBUG_9:
Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + format_exc())

View File

@@ -217,7 +217,7 @@ def ParsePcdErrorCode (Value = None, ContainerFile = None, LineNum = None):
# To delete the tailing 'L'
#
return hex(ErrorCode)[:-1]
except ValueError, XStr:
except ValueError as XStr:
if XStr:
pass
Logger.Error('Parser',

View File

@@ -297,7 +297,7 @@ class _LogicalExpressionParser(_ExprBase):
try:
if self.LogicalExpression() not in [self.ARITH, self.LOGICAL, self.REALLOGICAL, self.STRINGITEM]:
return False, ST.ERR_EXPR_LOGICAL % self.Token
except _ExprError, XExcept:
except _ExprError as XExcept:
return False, XExcept.Error
self.SkipWhitespace()
if self.Index != self.Len:
@@ -327,7 +327,7 @@ class _ValidRangeExpressionParser(_ExprBase):
try:
if self.RangeExpression() not in [self.HEX, self.INT]:
return False, ST.ERR_EXPR_RANGE % self.Token
except _ExprError, XExcept:
except _ExprError as XExcept:
return False, XExcept.Error
self.SkipWhitespace()
@@ -423,7 +423,7 @@ class _ValidListExpressionParser(_ExprBase):
try:
if self.ListExpression() not in [self.NUM]:
return False, ST.ERR_EXPR_LIST % self.Token
except _ExprError, XExcept:
except _ExprError as XExcept:
return False, XExcept.Error
self.SkipWhitespace()
@@ -457,7 +457,7 @@ class _StringTestParser(_ExprBase):
return False, ST.ERR_EXPR_EMPTY
try:
self.StringTest()
except _ExprError, XExcept:
except _ExprError as XExcept:
return False, XExcept.Error
return True, ''

View File

@@ -327,9 +327,9 @@ class UniFileClassObject(object):
if len(Lang) != 3:
try:
FileIn = codecs.open(File.Path, mode='rb', encoding='utf_8').readlines()
except UnicodeError, Xstr:
except UnicodeError as Xstr:
FileIn = codecs.open(File.Path, mode='rb', encoding='utf_16').readlines()
except UnicodeError, Xstr:
except UnicodeError as Xstr:
FileIn = codecs.open(File.Path, mode='rb', encoding='utf_16_le').readlines()
except:
EdkLogger.Error("Unicode File Parser",
@@ -436,7 +436,7 @@ class UniFileClassObject(object):
try:
FileIn = codecs.open(File.Path, mode='rb', encoding='utf_8').readlines()
except UnicodeError, Xstr:
except UnicodeError as Xstr:
FileIn = codecs.open(File.Path, mode='rb', encoding='utf_16').readlines()
except UnicodeError:
FileIn = codecs.open(File.Path, mode='rb', encoding='utf_16_le').readlines()
@@ -1042,7 +1042,7 @@ class UniFileClassObject(object):
ExtraData=FilaPath)
try:
FileIn = codecs.open(FilaPath, mode='rb', encoding='utf_8').readlines()
except UnicodeError, Xstr:
except UnicodeError as Xstr:
FileIn = codecs.open(FilaPath, mode='rb', encoding='utf_16').readlines()
except UnicodeError:
FileIn = codecs.open(FilaPath, mode='rb', encoding='utf_16_le').readlines()

View File

@@ -224,6 +224,6 @@ def XmlParseFile(FileName):
Dom = xml.dom.minidom.parse(XmlFile)
XmlFile.close()
return Dom
except BaseException, XExcept:
except BaseException as XExcept:
XmlFile.close()
Logger.Error('\nUPT', PARSER_ERROR, XExcept, File=FileName, RaiseError=True)

View File

@@ -213,7 +213,7 @@ def Main(Options = None):
Logger.Quiet(ST.MSG_FINISH)
ReturnCode = 0
except FatalError, XExcept:
except FatalError as XExcept:
ReturnCode = XExcept.args[0]
if Logger.GetLevel() <= Logger.DEBUG_9:
Logger.Quiet(ST.MSG_PYTHON_ON % \

View File

@@ -71,7 +71,7 @@ def Main(Options = None):
InstallDp(DistPkg, DpPkgFileName, ContentZipFile, Options, Dep, WorkspaceDir, DataBase)
ReturnCode = 0
except FatalError, XExcept:
except FatalError as XExcept:
ReturnCode = XExcept.args[0]
if Logger.GetLevel() <= Logger.DEBUG_9:
Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(),

View File

@@ -157,7 +157,7 @@ def Main(Options = None):
ReturnCode = 0
except FatalError, XExcept:
except FatalError as XExcept:
ReturnCode = XExcept.args[0]
if Logger.GetLevel() <= Logger.DEBUG_9:
Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + \

View File

@@ -68,12 +68,12 @@ def Main(Options=None):
else:
Logger.Quiet(ST.MSG_TEST_INSTALL_FAIL)
except TE.FatalError, XExcept:
except TE.FatalError as XExcept:
ReturnCode = XExcept.args[0]
if Logger.GetLevel() <= Logger.DEBUG_9:
Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + format_exc())
except Exception, x:
except Exception as x:
ReturnCode = TE.CODE_ERROR
Logger.Error(
"\nTestInstallPkg",

View File

@@ -179,7 +179,7 @@ def Main():
try:
GlobalData.gWORKSPACE, GlobalData.gPACKAGE_PATH = GetWorkspace()
except FatalError, XExcept:
except FatalError as XExcept:
if Logger.GetLevel() <= Logger.DEBUG_9:
Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + format_exc())
return XExcept.args[0]
@@ -294,7 +294,7 @@ def Main():
return OPTION_MISSING
ReturnCode = RunModule(Opt)
except FatalError, XExcept:
except FatalError as XExcept:
ReturnCode = XExcept.args[0]
if Logger.GetLevel() <= Logger.DEBUG_9:
Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + \