]>
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 __future__
import print_function
18 from Xml
.XmlRoutines
import *
19 import Common
.LongFilePathOs
as os
21 # ExceptionXml to parse Exception Node of XML file
22 class ExceptionXml(object):
28 def FromXml(self
, Item
, Key
):
29 self
.KeyWord
= XmlElement(Item
, '%s/KeyWord' % Key
)
30 self
.ErrorID
= XmlElement(Item
, '%s/ErrorID' % Key
)
31 self
.FilePath
= os
.path
.normpath(XmlElement(Item
, '%s/FilePath' % Key
))
34 return 'ErrorID = %s KeyWord = %s FilePath = %s' %(self
.ErrorID
, self
.KeyWord
, self
.FilePath
)
36 # ExceptionListXml to parse Exception Node List of XML file
37 class ExceptionListXml(object):
41 def FromXmlFile(self
, FilePath
):
42 XmlContent
= XmlParseFile(FilePath
)
43 for Item
in XmlList(XmlContent
, '/ExceptionList/Exception'):
45 Exp
.FromXml(Item
, 'Exception')
50 for Item
in self
.List
:
51 #RtnList.append((Item.ErrorID, Item.KeyWord, Item.FilePath))
52 RtnList
.append((Item
.ErrorID
, Item
.KeyWord
))
59 for Item
in self
.List
:
60 RtnStr
= RtnStr
+ str(Item
) + '\n'
63 # A class to check exception
64 class ExceptionCheck(object):
65 def __init__(self
, FilePath
= None):
66 self
.ExceptionList
= []
67 self
.ExceptionListXml
= ExceptionListXml()
68 self
.LoadExceptionListXml(FilePath
)
70 def LoadExceptionListXml(self
, FilePath
):
71 if FilePath
and os
.path
.isfile(FilePath
):
72 self
.ExceptionListXml
.FromXmlFile(FilePath
)
73 self
.ExceptionList
= self
.ExceptionListXml
.ToList()
75 def IsException(self
, ErrorID
, KeyWord
, FileID
=-1):
76 if (str(ErrorID
), KeyWord
.replace('\r\n', '\n')) in self
.ExceptionList
:
83 # This acts like the main() function for the script, unless it is 'import'ed into another
86 if __name__
== '__main__':
87 El
= ExceptionCheck('C:\\Hess\\Project\\BuildTool\\src\\Ecc\\exception.xml')
88 print(El
.ExceptionList
)