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