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