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