]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/Ecc/Exception.py
BaseTools: Clean up source files
[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 # This program and the accompanying materials
6 # are licensed and made available under the terms and conditions of the BSD License
7 # which accompanies this distribution. The full text of the license may be found at
8 # http://opensource.org/licenses/bsd-license.php
9 #
10 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 #
13
14 ##
15 # Import Modules
16 #
17 from __future__ import print_function
18 from Xml.XmlRoutines import *
19 import Common.LongFilePathOs as os
20
21 # ExceptionXml to parse Exception Node of XML file
22 class ExceptionXml(object):
23 def __init__(self):
24 self.KeyWord = ''
25 self.ErrorID = ''
26 self.FilePath = ''
27
28 def FromXml(self, Item, Key):
29 self.KeyWord = XmlElement(Item, '%s/KeyWord' % Key)
30 self.ErrorID = XmlElement(Item, '%s/ErrorID' % Key)
31 self.FilePath = os.path.normpath(XmlElement(Item, '%s/FilePath' % Key))
32
33 def __str__(self):
34 return 'ErrorID = %s KeyWord = %s FilePath = %s' %(self.ErrorID, self.KeyWord, self.FilePath)
35
36 # ExceptionListXml to parse Exception Node List of XML file
37 class ExceptionListXml(object):
38 def __init__(self):
39 self.List = []
40
41 def FromXmlFile(self, FilePath):
42 XmlContent = XmlParseFile(FilePath)
43 for Item in XmlList(XmlContent, '/ExceptionList/Exception'):
44 Exp = ExceptionXml()
45 Exp.FromXml(Item, 'Exception')
46 self.List.append(Exp)
47
48 def ToList(self):
49 RtnList = []
50 for Item in self.List:
51 #RtnList.append((Item.ErrorID, Item.KeyWord, Item.FilePath))
52 RtnList.append((Item.ErrorID, Item.KeyWord))
53
54 return RtnList
55
56 def __str__(self):
57 RtnStr = ''
58 if self.List:
59 for Item in self.List:
60 RtnStr = RtnStr + str(Item) + '\n'
61 return RtnStr
62
63 # A class to check exception
64 class ExceptionCheck(object):
65 def __init__(self, FilePath = None):
66 self.ExceptionList = []
67 self.ExceptionListXml = ExceptionListXml()
68 self.LoadExceptionListXml(FilePath)
69
70 def LoadExceptionListXml(self, FilePath):
71 if FilePath and os.path.isfile(FilePath):
72 self.ExceptionListXml.FromXmlFile(FilePath)
73 self.ExceptionList = self.ExceptionListXml.ToList()
74
75 def IsException(self, ErrorID, KeyWord, FileID=-1):
76 if (str(ErrorID), KeyWord.replace('\r\n', '\n')) in self.ExceptionList:
77 return True
78 else:
79 return False
80
81 ##
82 #
83 # This acts like the main() function for the script, unless it is 'import'ed into another
84 # script.
85 #
86 if __name__ == '__main__':
87 El = ExceptionCheck('C:\\Hess\\Project\\BuildTool\\src\\Ecc\\exception.xml')
88 print(El.ExceptionList)