]>
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 - 2018, Intel Corporation. All rights reserved.<BR>
5 # SPDX-License-Identifier: BSD-2-Clause-Patent
11 from __future__
import print_function
12 from __future__
import absolute_import
13 from Ecc
.Xml
.XmlRoutines
import *
14 import Common
.LongFilePathOs
as os
16 # ExceptionXml to parse Exception Node of XML file
17 class ExceptionXml(object):
23 def FromXml(self
, Item
, Key
):
24 self
.KeyWord
= XmlElement(Item
, '%s/KeyWord' % Key
)
25 self
.ErrorID
= XmlElement(Item
, '%s/ErrorID' % Key
)
26 self
.FilePath
= os
.path
.normpath(XmlElement(Item
, '%s/FilePath' % Key
))
29 return 'ErrorID = %s KeyWord = %s FilePath = %s' %(self
.ErrorID
, self
.KeyWord
, self
.FilePath
)
31 # ExceptionListXml to parse Exception Node List of XML file
32 class ExceptionListXml(object):
36 def FromXmlFile(self
, FilePath
):
37 XmlContent
= XmlParseFile(FilePath
)
38 for Item
in XmlList(XmlContent
, '/ExceptionList/Exception'):
40 Exp
.FromXml(Item
, 'Exception')
45 for Item
in self
.List
:
46 #RtnList.append((Item.ErrorID, Item.KeyWord, Item.FilePath))
47 RtnList
.append((Item
.ErrorID
, Item
.KeyWord
))
54 for Item
in self
.List
:
55 RtnStr
= RtnStr
+ str(Item
) + '\n'
58 # A class to check exception
59 class ExceptionCheck(object):
60 def __init__(self
, FilePath
= None):
61 self
.ExceptionList
= []
62 self
.ExceptionListXml
= ExceptionListXml()
63 self
.LoadExceptionListXml(FilePath
)
65 def LoadExceptionListXml(self
, FilePath
):
66 if FilePath
and os
.path
.isfile(FilePath
):
67 self
.ExceptionListXml
.FromXmlFile(FilePath
)
68 self
.ExceptionList
= self
.ExceptionListXml
.ToList()
70 def IsException(self
, ErrorID
, KeyWord
, FileID
=-1):
71 if (str(ErrorID
), KeyWord
.replace('\r\n', '\n')) in self
.ExceptionList
:
78 # This acts like the main() function for the script, unless it is 'import'ed into another
81 if __name__
== '__main__':
82 El
= ExceptionCheck('C:\\Hess\\Project\\BuildTool\\src\\Ecc\\exception.xml')
83 print(El
.ExceptionList
)