]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/Ecc/Exception.py
2 # This file is used to parse exception items found by ECC tool
4 # Copyright (c) 2009 - 2017, 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
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.
17 from Xml
.XmlRoutines
import *
18 import Common
.LongFilePathOs
as os
20 # ExceptionXml to parse Exception Node of XML file
21 class ExceptionXml(object):
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
))
33 return 'ErrorID = %s KeyWord = %s FilePath = %s' %(self
.ErrorID
, self
.KeyWord
, self
.FilePath
)
35 # ExceptionListXml to parse Exception Node List of XML file
36 class ExceptionListXml(object):
40 def FromXmlFile(self
, FilePath
):
41 XmlContent
= XmlParseFile(FilePath
)
42 for Item
in XmlList(XmlContent
, '/ExceptionList/Exception'):
44 Exp
.FromXml(Item
, 'Exception')
49 for Item
in self
.List
:
50 #RtnList.append((Item.ErrorID, Item.KeyWord, Item.FilePath))
51 RtnList
.append((Item
.ErrorID
, Item
.KeyWord
))
58 for Item
in self
.List
:
59 RtnStr
= RtnStr
+ str(Item
) + '\n'
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
)
69 def LoadExceptionListXml(self
, FilePath
):
70 if FilePath
and os
.path
.isfile(FilePath
):
71 self
.ExceptionListXml
.FromXmlFile(FilePath
)
72 self
.ExceptionList
= self
.ExceptionListXml
.ToList()
74 def IsException(self
, ErrorID
, KeyWord
, FileID
=-1):
75 if (str(ErrorID
), KeyWord
.replace('\r\n', '\n')) in self
.ExceptionList
:
82 # This acts like the main() function for the script, unless it is 'import'ed into another
85 if __name__
== '__main__':
86 El
= ExceptionCheck('C:\\Hess\\Project\\BuildTool\\src\\Ecc\\exception.xml')
87 print El
.ExceptionList