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