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