mirror of
https://github.com/Dasharo/edk2-upstream.git
synced 2026-06-13 19:16:19 -07:00
Running the vulture tool on the UPT/Library folder gave the following report. Remove the unnecessary code. - UPT/Library/CommentGenerating.py:50: unused function 'GenGenericComment' (60% confidence) - UPT/Library/CommentGenerating.py:172: unused function 'GenInfPcdTailComment' (60% confidence) - UPT/Library/CommentGenerating.py:185: unused function 'GenInfProtocolPPITailComment' (60% confidence) - UPT/Library/CommentGenerating.py:203: unused function 'GenInfGuidTailComment' (60% confidence) - UPT/Library/Misc.py:504: unused class 'MergeCommentDict' (60% confidence) - UPT/Library/Misc.py:527: unused function 'GenDummyHelpTextObj' (60% confidence) - UPT/Library/ParserValidate.py:110: unused function 'IsValidInfComponentType' (60% confidence) - UPT/Library/ParserValidate.py:122: unused function 'IsValidToolFamily' (60% confidence) - UPT/Library/ParserValidate.py:134: unused function 'IsValidToolTagName' (60% confidence) - UPT/Library/ParserValidate.py:465: unused function 'IsValidBuildNumber' (60% confidence) - UPT/Library/ParserValidate.py:478: unused function 'IsValidDepex' (60% confidence) - UPT/Library/ParserValidate.py:546: unused function 'IsValidVersionString' (60% confidence) - UPT/Library/ParserValidate.py:721: unused function 'CheckUTF16FileHeader' (60% confidence) - UPT/Library/Parsing.py:52: unused function 'GetBuildOption' (60% confidence) - UPT/Library/Parsing.py💯 unused function 'GetLibraryClassOfInf' (60% confidence) - UPT/Library/Parsing.py:150: unused function 'GetPcd' (60% confidence) - UPT/Library/Parsing.py:177: unused function 'GetFeatureFlagPcd' (60% confidence) - UPT/Library/Parsing.py:201: unused function 'GetDynamicDefaultPcd' (60% confidence) - UPT/Library/Parsing.py:227: unused function 'GetDynamicHiiPcd' (60% confidence) - UPT/Library/Parsing.py:254: unused function 'GetDynamicVpdPcd' (60% confidence) - UPT/Library/Parsing.py:277: unused function 'GetComponent' (60% confidence) - UPT/Library/Parsing.py:392: unused function 'GetExec' (60% confidence) - UPT/Library/Parsing.py:416: unused function 'GetComponents' (60% confidence) - UPT/Library/Parsing.py:532: unused function 'GetSource' (60% confidence) - UPT/Library/Parsing.py:581: unused function 'GetGuidsProtocolsPpisOfInf' (60% confidence) - UPT/Library/Parsing.py:595: unused function 'GetGuidsProtocolsPpisOfDec' (60% confidence) - UPT/Library/Parsing.py:645: unused function 'GetPcdOfInf' (60% confidence) - UPT/Library/Parsing.py:682: unused function 'GetPcdOfDec' (60% confidence) - UPT/Library/Parsing.py:739: unused function 'InsertSectionItems' (60% confidence) - UPT/Library/Parsing.py:776: unused function 'GenMetaDatSectionItem' (60% confidence) - UPT/Library/StringUtils.py:87: unused function 'GetLibraryClassesWithModuleType' (60% confidence) - UPT/Library/StringUtils.py:107: unused function 'GetDynamics' (60% confidence) - UPT/Library/StringUtils.py:350: unused function 'GetMultipleValuesOfKeyFromLines' (60% confidence) - UPT/Library/StringUtils.py:396: unused function 'GetSingleValueOfKeyFromLines' (60% confidence) - UPT/Library/StringUtils.py:463: unused function 'PreCheck' (60% confidence) - UPT/Library/StringUtils.py:675: unused function 'StringArrayLength' (60% confidence) - UPT/Library/StringUtils.py:718: unused function 'IsHexDigit' (60% confidence) - UPT/Library/UniClassObject.py:86: unused function 'UniToStr' (60% confidence) - UPT/Library/UniClassObject.py:227: unused attribute 'StringNameByteList' (60% confidence) - UPT/Library/UniClassObject.py:237: unused attribute 'StringNameByteList' (60% confidence) - UPT/Library/UniClassObject.py:377: unused method 'GetIncludeFile' (60% confidence) - UPT/Library/UniClassObject.py:947: unused method 'FindStringValue' (60% confidence) - UPT/Library/UniClassObject.py:957: unused method 'FindByToken' (60% confidence) - UPT/Library/UniClassObject.py:1022: unused method 'ReadIncludeUNIfile' (60% confidence) - UPT/Library/StringUtils.py:718: unused function 'IsHexDigit' (60% confidence) - UPT/Library/Xml/XmlRoutines.py:176: unused function 'XmlElementList' (60% confidence) - UPT/Library/Xml/XmlRoutines.py:202: unused function 'XmlNodeName' (60% confidence) Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
183 lines
5.6 KiB
Python
183 lines
5.6 KiB
Python
## @file
|
|
# This is an XML API that uses a syntax similar to XPath, but it is written in
|
|
# standard python so that no extra python packages are required to use it.
|
|
#
|
|
# Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
|
|
#
|
|
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
|
#
|
|
|
|
'''
|
|
XmlRoutines
|
|
'''
|
|
|
|
##
|
|
# Import Modules
|
|
#
|
|
import xml.dom.minidom
|
|
import re
|
|
import codecs
|
|
from Logger.ToolError import PARSER_ERROR
|
|
import Logger.Log as Logger
|
|
|
|
## Create a element of XML
|
|
#
|
|
# @param Name
|
|
# @param String
|
|
# @param NodeList
|
|
# @param AttributeList
|
|
#
|
|
def CreateXmlElement(Name, String, NodeList, AttributeList):
|
|
Doc = xml.dom.minidom.Document()
|
|
Element = Doc.createElement(Name)
|
|
if String != '' and String is not None:
|
|
Element.appendChild(Doc.createTextNode(String))
|
|
|
|
for Item in NodeList:
|
|
if isinstance(Item, type([])):
|
|
Key = Item[0]
|
|
Value = Item[1]
|
|
if Key != '' and Key is not None and Value != '' and Value is not None:
|
|
Node = Doc.createElement(Key)
|
|
Node.appendChild(Doc.createTextNode(Value))
|
|
Element.appendChild(Node)
|
|
else:
|
|
Element.appendChild(Item)
|
|
for Item in AttributeList:
|
|
Key = Item[0]
|
|
Value = Item[1]
|
|
if Key != '' and Key is not None and Value != '' and Value is not None:
|
|
Element.setAttribute(Key, Value)
|
|
|
|
return Element
|
|
|
|
## Get a list of XML nodes using XPath style syntax.
|
|
#
|
|
# Return a list of XML DOM nodes from the root Dom specified by XPath String.
|
|
# If the input Dom or String is not valid, then an empty list is returned.
|
|
#
|
|
# @param Dom The root XML DOM node.
|
|
# @param String A XPath style path.
|
|
#
|
|
def XmlList(Dom, String):
|
|
if String is None or String == "" or Dom is None or Dom == "":
|
|
return []
|
|
if Dom.nodeType == Dom.DOCUMENT_NODE:
|
|
Dom = Dom.documentElement
|
|
if String[0] == "/":
|
|
String = String[1:]
|
|
TagList = String.split('/')
|
|
Nodes = [Dom]
|
|
Index = 0
|
|
End = len(TagList) - 1
|
|
while Index <= End:
|
|
ChildNodes = []
|
|
for Node in Nodes:
|
|
if Node.nodeType == Node.ELEMENT_NODE and Node.tagName == \
|
|
TagList[Index]:
|
|
if Index < End:
|
|
ChildNodes.extend(Node.childNodes)
|
|
else:
|
|
ChildNodes.append(Node)
|
|
Nodes = ChildNodes
|
|
ChildNodes = []
|
|
Index += 1
|
|
|
|
return Nodes
|
|
|
|
|
|
## Get a single XML node using XPath style syntax.
|
|
#
|
|
# Return a single XML DOM node from the root Dom specified by XPath String.
|
|
# If the input Dom or String is not valid, then an empty string is returned.
|
|
#
|
|
# @param Dom The root XML DOM node.
|
|
# @param String A XPath style path.
|
|
#
|
|
def XmlNode(Dom, String):
|
|
if String is None or String == "" or Dom is None or Dom == "":
|
|
return None
|
|
if Dom.nodeType == Dom.DOCUMENT_NODE:
|
|
Dom = Dom.documentElement
|
|
if String[0] == "/":
|
|
String = String[1:]
|
|
TagList = String.split('/')
|
|
Index = 0
|
|
End = len(TagList) - 1
|
|
ChildNodes = [Dom]
|
|
while Index <= End:
|
|
for Node in ChildNodes:
|
|
if Node.nodeType == Node.ELEMENT_NODE and \
|
|
Node.tagName == TagList[Index]:
|
|
if Index < End:
|
|
ChildNodes = Node.childNodes
|
|
else:
|
|
return Node
|
|
break
|
|
Index += 1
|
|
return None
|
|
|
|
|
|
## Get a single XML element using XPath style syntax.
|
|
#
|
|
# Return a single XML element from the root Dom specified by XPath String.
|
|
# If the input Dom or String is not valid, then an empty string is returned.
|
|
#
|
|
# @param Dom The root XML DOM object.
|
|
# @param Strin A XPath style path.
|
|
#
|
|
def XmlElement(Dom, String):
|
|
try:
|
|
return XmlNode(Dom, String).firstChild.data.strip()
|
|
except BaseException:
|
|
return ""
|
|
|
|
## Get a single XML element using XPath style syntax.
|
|
#
|
|
# Similar with XmlElement, but do not strip all the leading and tailing space
|
|
# and newline, instead just remove the newline and spaces introduced by
|
|
# toprettyxml()
|
|
#
|
|
# @param Dom The root XML DOM object.
|
|
# @param Strin A XPath style path.
|
|
#
|
|
def XmlElement2(Dom, String):
|
|
try:
|
|
HelpStr = XmlNode(Dom, String).firstChild.data
|
|
gRemovePrettyRe = re.compile(r"""(?:(\n *) )(.*)\1""", re.DOTALL)
|
|
HelpStr = re.sub(gRemovePrettyRe, r"\2", HelpStr)
|
|
return HelpStr
|
|
except BaseException:
|
|
return ""
|
|
|
|
## Get the XML attribute of the current node.
|
|
#
|
|
# Return a single XML attribute named Attribute from the current root Dom.
|
|
# If the input Dom or Attribute is not valid, then an empty string is returned.
|
|
#
|
|
# @param Dom The root XML DOM object.
|
|
# @param Attribute The name of Attribute.
|
|
#
|
|
def XmlAttribute(Dom, Attribute):
|
|
try:
|
|
return Dom.getAttribute(Attribute)
|
|
except BaseException:
|
|
return ''
|
|
|
|
## Parse an XML file.
|
|
#
|
|
# Parse the input XML file named FileName and return a XML DOM it stands for.
|
|
# If the input File is not a valid XML file, then an empty string is returned.
|
|
#
|
|
# @param FileName The XML file name.
|
|
#
|
|
def XmlParseFile(FileName):
|
|
try:
|
|
XmlFile = codecs.open(FileName, 'rb')
|
|
Dom = xml.dom.minidom.parse(XmlFile)
|
|
XmlFile.close()
|
|
return Dom
|
|
except BaseException as XExcept:
|
|
XmlFile.close()
|
|
Logger.Error('\nUPT', PARSER_ERROR, XExcept, File=FileName, RaiseError=True)
|