]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/Ecc/Exception.py
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / BaseTools / Source / Python / Ecc / Exception.py
CommitLineData
30fdf114
LG
1## @file\r
2# This file is used to parse exception items found by ECC tool\r
3#\r
f7496d71 4# Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r
2e351cbe 5# SPDX-License-Identifier: BSD-2-Clause-Patent\r
30fdf114
LG
6#\r
7\r
8##\r
9# Import Modules\r
10#\r
72443dd2 11from __future__ import print_function\r
b6f6b636 12from __future__ import absolute_import\r
855698fb 13from Ecc.Xml.XmlRoutines import *\r
1be2ed90 14import Common.LongFilePathOs as os\r
30fdf114
LG
15\r
16# ExceptionXml to parse Exception Node of XML file\r
17class ExceptionXml(object):\r
18 def __init__(self):\r
19 self.KeyWord = ''\r
20 self.ErrorID = ''\r
21 self.FilePath = ''\r
f7496d71 22\r
30fdf114
LG
23 def FromXml(self, Item, Key):\r
24 self.KeyWord = XmlElement(Item, '%s/KeyWord' % Key)\r
25 self.ErrorID = XmlElement(Item, '%s/ErrorID' % Key)\r
26 self.FilePath = os.path.normpath(XmlElement(Item, '%s/FilePath' % Key))\r
f7496d71 27\r
30fdf114
LG
28 def __str__(self):\r
29 return 'ErrorID = %s KeyWord = %s FilePath = %s' %(self.ErrorID, self.KeyWord, self.FilePath)\r
30\r
31# ExceptionListXml to parse Exception Node List of XML file\r
32class ExceptionListXml(object):\r
33 def __init__(self):\r
34 self.List = []\r
f7496d71 35\r
30fdf114
LG
36 def FromXmlFile(self, FilePath):\r
37 XmlContent = XmlParseFile(FilePath)\r
38 for Item in XmlList(XmlContent, '/ExceptionList/Exception'):\r
39 Exp = ExceptionXml()\r
40 Exp.FromXml(Item, 'Exception')\r
41 self.List.append(Exp)\r
f7496d71 42\r
30fdf114
LG
43 def ToList(self):\r
44 RtnList = []\r
45 for Item in self.List:\r
46 #RtnList.append((Item.ErrorID, Item.KeyWord, Item.FilePath))\r
47 RtnList.append((Item.ErrorID, Item.KeyWord))\r
f7496d71 48\r
30fdf114 49 return RtnList\r
f7496d71 50\r
30fdf114
LG
51 def __str__(self):\r
52 RtnStr = ''\r
53 if self.List:\r
54 for Item in self.List:\r
55 RtnStr = RtnStr + str(Item) + '\n'\r
56 return RtnStr\r
57\r
58# A class to check exception\r
59class ExceptionCheck(object):\r
60 def __init__(self, FilePath = None):\r
61 self.ExceptionList = []\r
62 self.ExceptionListXml = ExceptionListXml()\r
63 self.LoadExceptionListXml(FilePath)\r
64\r
65 def LoadExceptionListXml(self, FilePath):\r
66 if FilePath and os.path.isfile(FilePath):\r
67 self.ExceptionListXml.FromXmlFile(FilePath)\r
68 self.ExceptionList = self.ExceptionListXml.ToList()\r
f7496d71 69\r
30fdf114 70 def IsException(self, ErrorID, KeyWord, FileID=-1):\r
bcd999d2 71 if (str(ErrorID), KeyWord.replace('\r\n', '\n')) in self.ExceptionList:\r
30fdf114
LG
72 return True\r
73 else:\r
74 return False\r
75\r
76##\r
77#\r
78# This acts like the main() function for the script, unless it is 'import'ed into another\r
79# script.\r
80#\r
81if __name__ == '__main__':\r
82 El = ExceptionCheck('C:\\Hess\\Project\\BuildTool\\src\\Ecc\\exception.xml')\r
72443dd2 83 print(El.ExceptionList)\r