本文整理汇总了Python中xml.etree.ElementTree.remove方法的典型用法代码示例。如果您正苦于以下问题:Python ElementTree.remove方法的具体用法?Python ElementTree.remove怎么用?Python ElementTree.remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xml.etree.ElementTree
的用法示例。
在下文中一共展示了ElementTree.remove方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: newSubChapterTitle
# 需要导入模块: from xml.etree import ElementTree [as 别名]
# 或者: from xml.etree.ElementTree import remove [as 别名]
def newSubChapterTitle(self, parent_tag, tag, title):
if tag in self.report_elements:
ET.remove(self.report_elements[tag])
#del self.report_elements[tag] # will be overwritten anyway
div = ET.SubElement(self.report_elements[parent_tag], "div" )
h3 = ET.SubElement(div, "h3" )
h3.text = title
self.report_elements[tag] = div
self.textAdded.emit()
示例2: newReportTitle
# 需要导入模块: from xml.etree import ElementTree [as 别名]
# 或者: from xml.etree.ElementTree import remove [as 别名]
def newReportTitle(self, parent_tag, tag, title, authors, date):
if tag in self.report_elements:
ET.remove(self.report_elements[tag])
#del self.report_elements[tag] # will be overwritten anyway
div = ET.SubElement(self.report_elements[parent_tag], "div" )
h1 = ET.SubElement(div, "h1" )
h1.text = title
par_date = ET.SubElement(div, "p" )
par_date.text = "Creation date: " + date
par_authors = ET.SubElement(div, "p" )
par_authors.text = "Experimenter: " + authors
self.report_elements[tag] = h1
self.textAdded.emit()
示例3: ConfigXmlWriter
# 需要导入模块: from xml.etree import ElementTree [as 别名]
# 或者: from xml.etree.ElementTree import remove [as 别名]
class ConfigXmlWriter(RcbXmlReaderWriter):
def __init__(self, createNew):
Logutil.log('init ConfigXmlWriter', util.LOG_LEVEL_INFO)
self.createNew = createNew
if(createNew):
configFile = os.path.join(util.getAddonInstallPath(), 'resources', 'database', 'config_template.xml')
else:
configFile = util.getConfigXmlPath()
if(not os.path.isfile(configFile)):
Logutil.log('File config.xml does not exist. Place a valid config file here: ' + str(configFile), util.LOG_LEVEL_ERROR)
else:
self.tree = ElementTree().parse(configFile)
""" Functions for generating XML objects from objects """
def getXmlAttributesForRomCollection(self, rc):
return {'id': str(rc.id), 'name': rc.name}
def getXmlElementsForRomCollection(self, rc):
elements = []
# String attributes
for e in ['gameclient', 'emulatorCmd', 'emulatorParams', 'preCmd', 'postCmd',
'saveStatePath', 'saveStateParams']:
try:
el = Element(e, {})
el.text = getattr(rc, e)
elements.append(el)
except AttributeError as exc:
# Skip any errors
pass
# Non-string attributes
for e in ['useBuiltinEmulator', 'useEmuSolo', 'usePopen', 'ignoreOnScan', 'allowUpdate', 'autoplayVideoMain',
'autoplayVideoInfo', 'useFoldernameAsGamename', 'maxFolderDepth', 'doNotExtractZipFiles',
'makeLocalCopy', 'diskPrefix']:
try:
el = Element(e, {})
el.text = str(getattr(rc, e))
elements.append(el)
except AttributeError as exc:
# Skip any errors
pass
for romPath in rc.romPaths:
el = Element('romPath', {})
el.text = romPath
elements.append(el)
return elements
def getXmlAttributesForSite(self, site):
attrs = {'name': site.name, 'path': site.path}
return attrs
def getXmlElementsForSite(self, site):
""" Not needed """
pass
def writeRomCollections(self, romCollections, isEdit):
Logutil.log('write Rom Collections', util.LOG_LEVEL_INFO)
romCollectionsXml = self.tree.find('RomCollections')
#HACK: remove all Rom Collections and create new
if(isEdit):
for romCollectionXml in romCollectionsXml.findall('RomCollection'):
romCollectionsXml.remove(romCollectionXml)
for romCollection in romCollections.values():
Logutil.log('write Rom Collection: ' + str(romCollection.name), util.LOG_LEVEL_INFO)
romCollectionXml = SubElement(romCollectionsXml, 'RomCollection', self.getXmlAttributesForRomCollection(romCollection))
for subel in self.getXmlElementsForRomCollection(romCollection):
romCollectionXml.append(subel)
for mediaPath in romCollection.mediaPaths:
success, message = self.searchConfigObjects('FileTypes/FileType', mediaPath.fileType.name, 'FileType')
if(not success):
return False, message
SubElement(romCollectionXml, 'mediaPath', {'type': mediaPath.fileType.name}).text = mediaPath.path
#image placing
if(not self.createNew):
#in case of an update we have to create new options
if(romCollection.name == 'MAME' and not self.createNew):
self.addFileTypesForMame()
self.addImagePlacingForMame()
if(romCollection.imagePlacingMain != None and romCollection.imagePlacingMain.name != ''):
#.........这里部分代码省略.........
示例4: __init__
# 需要导入模块: from xml.etree import ElementTree [as 别名]
# 或者: from xml.etree.ElementTree import remove [as 别名]
class ConfigXmlWriter:
def __init__(self, createNew):
Logutil.log('init ConfigXmlWriter', util.LOG_LEVEL_INFO)
self.createNew = createNew
if(createNew):
configFile = os.path.join(util.getAddonInstallPath(), 'resources', 'database', 'config_template.xml')
else:
configFile = util.getConfigXmlPath()
if(not os.path.isfile(configFile)):
Logutil.log('File config.xml does not exist. Place a valid config file here: ' +str(configFile), util.LOG_LEVEL_ERROR)
return False, util.localize(32003)
self.tree = ElementTree().parse(configFile)
def writeRomCollections(self, romCollections, isEdit):
Logutil.log('write Rom Collections', util.LOG_LEVEL_INFO)
romCollectionsXml = self.tree.find('RomCollections')
#HACK: remove all Rom Collections and create new
if(isEdit):
for romCollectionXml in romCollectionsXml.findall('RomCollection'):
romCollectionsXml.remove(romCollectionXml)
for romCollection in romCollections.values():
Logutil.log('write Rom Collection: ' +str(romCollection.name), util.LOG_LEVEL_INFO)
romCollectionXml = SubElement(romCollectionsXml, 'RomCollection', {'id' : str(romCollection.id), 'name' : romCollection.name})
SubElement(romCollectionXml, 'useBuiltinEmulator').text = str(romCollection.useBuiltinEmulator)
SubElement(romCollectionXml, 'gameclient').text = romCollection.gameclient
SubElement(romCollectionXml, 'emulatorCmd').text = romCollection.emulatorCmd
SubElement(romCollectionXml, 'emulatorParams').text = romCollection.emulatorParams
for romPath in romCollection.romPaths:
SubElement(romCollectionXml, 'romPath').text = romPath
SubElement(romCollectionXml, 'saveStatePath').text = romCollection.saveStatePath
SubElement(romCollectionXml, 'saveStateParams').text = romCollection.saveStateParams
for mediaPath in romCollection.mediaPaths:
success, message = self.searchConfigObjects('FileTypes/FileType', mediaPath.fileType.name, 'FileType')
if(not success):
return False, message
SubElement(romCollectionXml, 'mediaPath', {'type' : mediaPath.fileType.name}).text = mediaPath.path
SubElement(romCollectionXml, 'preCmd').text = romCollection.preCmd
SubElement(romCollectionXml, 'postCmd').text = romCollection.postCmd
SubElement(romCollectionXml, 'useEmuSolo').text = str(romCollection.useEmuSolo)
SubElement(romCollectionXml, 'usePopen').text = str(romCollection.usePopen)
SubElement(romCollectionXml, 'ignoreOnScan').text = str(romCollection.ignoreOnScan)
SubElement(romCollectionXml, 'allowUpdate').text = str(romCollection.allowUpdate)
SubElement(romCollectionXml, 'autoplayVideoMain').text = str(romCollection.autoplayVideoMain)
SubElement(romCollectionXml, 'autoplayVideoInfo').text = str(romCollection.autoplayVideoInfo)
SubElement(romCollectionXml, 'useFoldernameAsGamename').text = str(romCollection.useFoldernameAsGamename)
SubElement(romCollectionXml, 'maxFolderDepth').text = str(romCollection.maxFolderDepth)
SubElement(romCollectionXml, 'doNotExtractZipFiles').text = str(romCollection.doNotExtractZipFiles)
SubElement(romCollectionXml, 'diskPrefix').text = str(romCollection.diskPrefix)
if (os.environ.get( "OS", "xbox" ) == "xbox"):
SubElement(romCollectionXml, 'xboxCreateShortcut').text = str(romCollection.xboxCreateShortcut)
SubElement(romCollectionXml, 'xboxCreateShortcutAddRomfile').text = str(romCollection.xboxCreateShortcutAddRomfile)
SubElement(romCollectionXml, 'xboxCreateShortcutUseShortGamename').text = str(romCollection.xboxCreateShortcutUseShortGamename)
#image placing
if(not self.createNew):
#in case of an update we have to create new options
if(romCollection.name == 'MAME' and not self.createNew):
self.addFileTypesForMame()
self.addImagePlacingForMame()
if(romCollection.imagePlacingMain != None and romCollection.imagePlacingMain.name != ''):
success, message = self.searchConfigObjects('ImagePlacing/fileTypeFor', romCollection.imagePlacingMain.name, 'ImagePlacing')
if(not success):
return False, message
SubElement(romCollectionXml, 'imagePlacingMain').text = romCollection.imagePlacingMain.name
else:
SubElement(romCollectionXml, 'imagePlacingMain').text = 'gameinfobig'
if(romCollection.imagePlacingInfo != None and romCollection.imagePlacingInfo.name != ''):
success, message = self.searchConfigObjects('ImagePlacing/fileTypeFor', romCollection.imagePlacingInfo.name, 'ImagePlacing')
if(not success):
return False, message
SubElement(romCollectionXml, 'imagePlacingInfo').text = romCollection.imagePlacingInfo.name
else:
SubElement(romCollectionXml, 'imagePlacingInfo').text = 'gameinfosmall'
if(romCollection.scraperSites == None or len(romCollection.scraperSites) == 0):
SubElement(romCollectionXml, 'scraper', {'name' : 'thegamesdb.net', 'replaceKeyString' : '', 'replaceValueString' : ''})
SubElement(romCollectionXml, 'scraper', {'name' : 'archive.vg', 'replaceKeyString' : '', 'replaceValueString' : ''})
#.........这里部分代码省略.........