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