]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/Ecc/Exception.py
BaseTools: Use absolute import in Ecc
[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 __future__ import absolute_import
19 from .Xml.XmlRoutines import *
20 import Common.LongFilePathOs as os
21
22 # ExceptionXml to parse Exception Node of XML file
23 class ExceptionXml(object):
24 def __init__(self):
25 self.KeyWord = ''
26 self.ErrorID = ''
27 self.FilePath = ''
28
29 def FromXml(self, Item, Key):
30 self.KeyWord = XmlElement(Item, '%s/KeyWord' % Key)
31 self.ErrorID = XmlElement(Item, '%s/ErrorID' % Key)
32 self.FilePath = os.path.normpath(XmlElement(Item, '%s/FilePath' % Key))
33
34 def __str__(self):
35 return 'ErrorID = %s KeyWord = %s FilePath = %s' %(self.ErrorID, self.KeyWord, self.FilePath)
36
37 # ExceptionListXml to parse Exception Node List of XML file
38 class ExceptionListXml(object):
39 def __init__(self):
40 self.List = []
41
42 def FromXmlFile(self, FilePath):
43 XmlContent = XmlParseFile(FilePath)
44 for Item in XmlList(XmlContent, '/ExceptionList/Exception'):
45 Exp = ExceptionXml()
46 Exp.FromXml(Item, 'Exception')
47 self.List.append(Exp)
48
49 def ToList(self):
50 RtnList = []
51 for Item in self.List:
52 #RtnList.append((Item.ErrorID, Item.KeyWord, Item.FilePath))
53 RtnList.append((Item.ErrorID, Item.KeyWord))
54
55 return RtnList
56
57 def __str__(self):
58 RtnStr = ''
59 if self.List:
60 for Item in self.List:
61 RtnStr = RtnStr + str(Item) + '\n'
62 return RtnStr
63
64 # A class to check exception
65 class ExceptionCheck(object):
66 def __init__(self, FilePath = None):
67 self.ExceptionList = []
68 self.ExceptionListXml = ExceptionListXml()
69 self.LoadExceptionListXml(FilePath)
70
71 def LoadExceptionListXml(self, FilePath):
72 if FilePath and os.path.isfile(FilePath):
73 self.ExceptionListXml.FromXmlFile(FilePath)
74 self.ExceptionList = self.ExceptionListXml.ToList()
75
76 def IsException(self, ErrorID, KeyWord, FileID=-1):
77 if (str(ErrorID), KeyWord.replace('\r\n', '\n')) in self.ExceptionList:
78 return True
79 else:
80 return False
81
82 ##
83 #
84 # This acts like the main() function for the script, unless it is 'import'ed into another
85 # script.
86 #
87 if __name__ == '__main__':
88 El = ExceptionCheck('C:\\Hess\\Project\\BuildTool\\src\\Ecc\\exception.xml')
89 print(El.ExceptionList)