本文整理汇总了Python中xml.etree.ElementTree.SubElement.attrib['id']方法的典型用法代码示例。如果您正苦于以下问题:Python SubElement.attrib['id']方法的具体用法?Python SubElement.attrib['id']怎么用?Python SubElement.attrib['id']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xml.etree.ElementTree.SubElement
的用法示例。
在下文中一共展示了SubElement.attrib['id']方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: adjust_visual_scenes
# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import attrib['id'] [as 别名]
def adjust_visual_scenes(self):
logging.info('Adjusting Visual Scenes.')
scenes = self.root.find('library_visual_scenes')
if scenes is None:
logging.error('No scenes.')
return
vis_scene = scenes[0]
root_nodes = list(vis_scene)
logging.info('Creating CryExport Node.')
cryexportnode = SubElement(vis_scene, 'node')
cryexportnode.attrib['id'] = 'CryExportNode_{0}'.format(self.config['scenename'])
extra = SubElement(cryexportnode, 'extra')
tech = SubElement(extra, 'technique', profile='CryEngine')
props = SubElement(tech, 'properties')
ft = 'fileType={0}'.format(self.config['filetype'])
flags = [ft]
if self.config['donotmerge']:
flags.append('DoNotMerge')
if self.config['customnormals']:
flags.append('CustomNormals')
if self.config['f32']:
flags.append('UseF32VertexFormat')
props.text = '\n\t\t'.join(flags)
logging.info('Applied flags "{0}" to CryExport Node.'.format(' '.join(flags)))
# Remove nodes.
for node in root_nodes:
vis_scene.remove(node)
cryexportnode.append(node)
logging.info('Reparented nodes.')
self.recursive_adjust_nodes(cryexportnode)
logging.info('Finished adjusting Visual Scenes.')
示例2: _add_span
# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import attrib['id'] [as 别名]
def _add_span(oElement, sText, sClass=None, sId=None):
"""Add a span element to the element oElement"""
oSpan = SubElement(oElement, "span")
oSpan.text = sText
if sClass:
oSpan.attrib['class'] = sClass
if sId:
oSpan.attrib['id'] = sId
示例3: index_for_img
# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import attrib['id'] [as 别名]
def index_for_img(src):
if not scope['images'].has_key(src):
scope['images'][src] = scope['ext_start'] + scope['next_gid']
tile = SubElement(npc_tileset, 'tile')
tile.attrib['id'] = str(scope['next_gid'])
scope['next_gid'] += 1
img = SubElement(tile, 'image')
img.attrib['source'] = relative_img_path(src)
return scope['images'][src]
示例4: main
# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import attrib['id'] [as 别名]
def main():
if len(sys.argv) not in [3,4]:
print '==============================================================================='
print 'AddUnlabeledSchemeToResidueType.py reads in a cara repository file and modifies'
print 'the residue-type definitions to include a labeling scheme with N14 and C12.'
print 'A labeling scheme called \'unlabeled\' is added for this purpose.'
print ''
print 'Usage: AddUnlabeledSchemeToResidueType.py infile.cara outfile.cara'
print 'Number of arguments given: %d'%(len(sys.argv)-1)
print 'An optional third argument names which project to modify, if'
print 'there is more than one project in a repository. '
print '=============================================================================='
return
infile = sys.argv[1]
outfile = sys.argv[2]
if exists(outfile):
print '\nOutput file \'%s\' exists. Choose a new name to avoid overwriting.\n'%outfile
return
tree = ET.parse(infile)
root = tree.getroot()
projects = root.findall('project')
# Select a project according to command-line input, defaulting to the first project
if len(sys.argv) == 4:
projectName = sys.argv[3]
project = getProject(projectName,projects)
if not project:
print 'No project found with name \"%s\".'%projectName
return
else:
project = projects[0]
if not project:
print 'No project found.'
return
# Find existing schemes & make a new one by incrementing the highest existing ID number
library = root.find('library')
schemes = library.findall('scheme')
numSchemes = len(schemes)
if numSchemes > 0:
schemeIDs = [int(scheme.get('id')) for scheme in schemes]
schemeIDs.sort()
newIDnum = schemeIDs[numSchemes-1]+1
newID = '%d'%newIDnum
else:
newID = '1'
newscheme = SubElement(library,'scheme')
newscheme.attrib['id'] = newID
newscheme.attrib['name'] = 'unlabeled%s'%newID
# Modify residue-type
residueTypes = library.findall('residue-type')
for residueType in residueTypes:
atoms = residueType.findall('atom')
for atom in atoms:
if atom.get('name')[0]=='N':
newscheme = SubElement(atom,'scheme')
newscheme.attrib['id'] = newID
newscheme.attrib['type'] = 'N14'
elif atom.get('name')[0]=='C':
newscheme = SubElement(atom,'scheme')
newscheme.attrib['id'] = newID
newscheme.attrib['type'] = 'C12'
tree.write(outfile)
示例5: Element
# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import attrib['id'] [as 别名]
for network in networks:
if network.find('name').text == opts.network:
break
else:
sys.stderr.write('error: network not found: %s\n' % opts.network)
sys.exit(1)
networkid = network.attrib['id']
# Prepare the XML and create the VM
vm = Element('vm')
name = SubElement(vm, 'name')
name.text = args[0]
memory = SubElement(vm, 'memory')
memory.text = str(opts.memory * 1024**2)
cluster = SubElement(vm, 'cluster')
cluster.attrib['id'] = clusterid
template = SubElement(vm, 'template')
template.attrib['id'] = templateid
link = links.find('link[@rel="vms"]')
url = link.attrib['href']
status, vm = make_request(api, 'POST', url, headers, vm)
if status not in (http.CREATED, http.ACCEPTED):
sys.stderr.write('error: failed to create vm: status %s\n' % status)
sys.exit(1)
# Add the nic
nic = Element('nic')
name = SubElement(nic, 'name')
name.text = 'eth0'
type = SubElement(nic, 'type')
type.text = 'PV'
示例6: main
# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import attrib['id'] [as 别名]
def main():
if len(sys.argv) not in [3,4]:
print '==============================================================================='
print 'AddILVlabelingScheme.py reads in a cara repository file and modifies the'
print 'residue-type definitions to include a labeling scheme with 12C and 2H'
print 'except at methyl groups of I, L, and V.'
print ''
print 'A labeling scheme called \'ILVnoesy\' is added for this purpose.'
print ''
print 'Usage: AddILVlabelingScheme.py infile.cara outfile.cara'
print 'Number of arguments given: %d'%(len(sys.argv)-1)
print 'An optional third argument names which project to modify, if'
print 'there is more than one project in a repository. '
print '=============================================================================='
return
infile = sys.argv[1]
outfile = sys.argv[2]
if infile == outfile:
print '\nPlease do not overwrite your original file. Try again.\n'
return
tree = ET.parse(infile)
root = tree.getroot()
projects = root.findall('project')
# Select a project according to command-line input, defaulting to the first project
if len(sys.argv) == 4:
projectName = sys.argv[3]
project = getProject(projectName,projects)
if not project:
print 'No project found with name \"%s\".'%projectName
return
else:
project = projects[0]
if not project:
print 'No project found.'
return
# Find existing schemes & make a new one by incrementing the highest existing ID number
library = root.find('library')
schemes = library.findall('scheme')
numSchemes = len(schemes)
if numSchemes > 0:
schemeIDs = [int(scheme.get('id')) for scheme in schemes]
schemeIDs.sort()
newIDnum = schemeIDs[numSchemes-1]+1
newID = '%d'%newIDnum
else:
newID = '1'
newscheme = SubElement(library,'scheme')
newscheme.attrib['id'] = newID
newscheme.attrib['name'] = 'ILVnoesy15N-%s'%newID
# Modify residue-type
residueTypes = library.findall('residue-type')
for residueType in residueTypes:
if residueType.get('letter') not in ('I','L','V'):
atoms = residueType.findall('atom')
for atom in atoms:
if atom.get('name')[0]=='C':
newscheme = SubElement(atom,'scheme')
newscheme.attrib['id'] = newID
newscheme.attrib['type'] = 'C12'
elif atom.get('name')[0]=='H' and atom.get('name')!='H':
newscheme = SubElement(atom,'scheme')
newscheme.attrib['id'] = newID
newscheme.attrib['type'] = 'H2'
elif residueType.get('letter')=='L':
atoms = residueType.findall('atom')
for atom in atoms:
if atom.get('name')[0]=='C' and atom.get('name')[0:2]!='CD':
newscheme = SubElement(atom,'scheme')
newscheme.attrib['id'] = newID
newscheme.attrib['type'] = 'C12'
elif atom.get('name')[0]=='H' and atom.get('name')[0:2]!='HD' and atom.get('name')!='H':
newscheme = SubElement(atom,'scheme')
newscheme.attrib['id'] = newID
newscheme.attrib['type'] = 'H2'
elif residueType.get('letter')=='V':
atoms = residueType.findall('atom')
for atom in atoms:
if atom.get('name')[0]=='C' and atom.get('name')[0:2]!='CG':
newscheme = SubElement(atom,'scheme')
newscheme.attrib['id'] = newID
newscheme.attrib['type'] = 'C12'
elif atom.get('name')[0]=='H' and atom.get('name')[0:2]!='HG' and atom.get('name')!='H':
newscheme = SubElement(atom,'scheme')
newscheme.attrib['id'] = newID
newscheme.attrib['type'] = 'H2'
elif residueType.get('letter')=='I':
atoms = residueType.findall('atom')
for atom in atoms:
if atom.get('name')[0]=='C' and atom.get('name')[0:2]!='CD':
newscheme = SubElement(atom,'scheme')
newscheme.attrib['id'] = newID
#.........这里部分代码省略.........
示例7: Browse
# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import attrib['id'] [as 别名]
def Browse(self, request, objectID, browseFlag, filter, startingIndex, requestedCount, sortCriteria):
# determine the host:port of content
host = request.headers.getHeader('host').split(':',1)[0]
port = CoreHttpConfig.HTTP_PORT
# break up the objectID into segments. objectIDs have the following form:
# 0/<artist>/<album>/<song>
segments = objectID.split('/')
if len(segments) < 1 or segments[0] != '0':
raise UPNPError(701, "ObjectID %i is invalid" % objectID)
# generate the DIDL envelope
didl = Element("DIDL-Lite")
didl.attrib["xmlns"] = "urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"
didl.attrib["xmlns:upnp"] = "urn:schemas-upnp-org:metadata-1-0/upnp/"
didl.attrib["xmlns:dc"] = "http://purl.org/dc/elements/1.1/"
# browse the metadata of one specific item
if browseFlag == 'BrowseMetadata':
if len(segments) == 1:
container = SubElement(didl, 'container')
container.attrib['id'] = objectID
container.attrib['parentID'] = '-1'
container.attrib['restricted'] = '1'
container.attrib['childCount'] = '2'
SubElement(container, 'dc:title').text = 'Media on Higgins'
SubElement(container, 'upnp:class').text = 'object.container.storageFolder'
elif len(segments) > 1:
if segments[1] == 'music':
if len(segments) == 2:
container = SubElement(didl, 'container')
container.attrib['id'] = objectID
container.attrib['parentID'] = '0'
container.attrib['restricted'] = '1'
container.attrib['childCount'] = str(len(Artist.objects.all()))
SubElement(container, 'dc:title').text = 'Music'
SubElement(container, 'upnp:class').text = 'object.container.storageFolder'
elif len(segments) == 3:
artist = Artist.objects.get(id=int(segments[2]))
container = SubElement(didl, 'container')
container.attrib['id'] = objectID
container.attrib['parentID'] = '/'.join(segments[:1])
container.attrib['restricted'] = '1'
container.attrib['childCount'] = str(len(Album.objects.filter(artist=artist)))
SubElement(container, 'dc:title').text = str(artist.name)
SubElement(container, 'upnp:class').text = 'object.container.person.musicArtist'
elif len(segments) == 4:
album = Album.objects.get(id=int(segments[3]), artist=int(segments[2]))
container = SubElement(didl, 'container')
container.attrib['id'] = objectID
container.attrib['parentID'] = '/'.join(segments[:1])
container.attrib['restricted'] = '1'
container.attrib['childCount'] = str(len(Song.objects.filter(album=album)))
SubElement(container, 'dc:title').text = str(album.name)
SubElement(container, 'upnp:class').text = 'object.container.album.musicAlbum'
if segments[1] == 'playlists':
if len(segments) == 2:
container = SubElement(didl, 'container')
container.attrib['id'] = objectID
container.attrib['parentID'] = '0'
container.attrib['restricted'] = '1'
container.attrib['childCount'] = str(len(Playlist.objects.all()))
SubElement(container, 'dc:title').text = 'Playlists'
SubElement(container, 'upnp:class').text = 'object.container.storageFolder'
elif len(segments) == 3:
playlist = Playlist.objects.get(id=int(segments[2]))
container = SubElement(didl, 'container')
container.attrib['id'] = objectID
container.attrib['parentID'] = '/'.join(segments[:1])
container.attrib['restricted'] = '1'
container.attrib['childCount'] = str(len(playlist))
SubElement(container, 'dc:title').text = str(playlist.name)
SubElement(container, 'upnp:class').text = 'object.container.playlistContainer'
total_matches = 1
number_returned = 1
elif browseFlag == 'BrowseDirectChildren':
def getMatches(startingIndex, requestedCount, qset):
# don't return more than 100 items
total_matches = len(qset)
if requestedCount > 100 or requestedCount == 0:
requestedCount = 100
if startingIndex >= total_matches:
raise UPNPError(402, "startingIndex %i is out of range" % startingIndex)
if startingIndex + requestedCount > total_matches:
requestedCount = total_matches - startingIndex
matches = qset[startingIndex:startingIndex + requestedCount]
number_returned = len(matches)
retval = (matches, total_matches, number_returned)
logger.log_debug("getMatches: %s" % str(retval))
return retval
# determine the number of matches
if len(segments) == 1:
container = SubElement(didl, "container")
container.attrib["id"] = '0/music'
container.attrib["parentID"] = '0'
container.attrib["restricted"] = "1"
container.attrib['childCount'] = str(len(Album.objects.all()))
SubElement(container, "upnp:class").text = "object.container.storageFolder"
SubElement(container, "dc:title").text = 'Music'
container = SubElement(didl, "container")
container.attrib["id"] = '0/playlists'
container.attrib["parentID"] = '0'
container.attrib["restricted"] = "1"
#.........这里部分代码省略.........
示例8: processPageTypes
# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import attrib['id'] [as 别名]
def processPageTypes(self, pagetype, mainTag):
linkTypes = {"people":["crisis-refs", "organization-refs"], "organizations":[ "crisis-refs", "person-refs"], "crises":["organization-refs", "person-refs"]}
pageType = SubElement(mainTag, pagetype)
tags = []
childType = ""
if (pagetype == "people"):
tags = Person.all()
childType = "person"
elif (pagetype == "organizations"):
tags = Organization.all()
childType = "organization"
else:
#print pagetype
tags = Crisis.all()
childType = "crisis"
for t in tags:
# element instantiation and unique id
child = SubElement(pageType, childType)
child.attrib['id'] = t.key().name()
# general info block
name = SubElement(child, 'name')
name.text = str(t.name)
if t.alternate_names != None :
alternate_names = SubElement(child, 'alternate-names')
alternate_names.text = t.alternate_names
category = SubElement(child, 'kind')
category.text = t.category
description = SubElement(child, 'description')
description.text = t.description
# location block
location = SubElement(child, 'location')
if t.city != None :
city = SubElement(location, 'city')
city.text = str(t.city)
if t.state != None :
state = SubElement(location, 'state')
state.text = str(t.state)
country = SubElement(location, 'country')
country.text = str(t.country)
if t.latitude != None:
latitude = SubElement(location, 'latitude')
latitude.text = str(t.latitude)
if (t.latitude != None):
longitude = SubElement(location, 'longitude')
longitude.text = str(t.longitude)
# image block
if t.image_source != None :
images = SubElement(child, "images")
c = 0
for l in t.image_source :
image = SubElement(images, "image")
image_source = SubElement(image, 'source')
image_source.text = str(l)
i = 0
for k in t.image_description :
if i == c :
image_description = SubElement(image, 'description')
image_description.text = str(k)
i += 1
c += 1
# map block
if t.map_source != None :
maps = SubElement(child, "maps")
c = 0
for l in t.map_source :
map = SubElement(maps, "map")
map_source = SubElement(map, 'source')
map_source.text = str(l)
i = 0
for k in t.map_description :
if i == c :
map_description = SubElement(map, 'description')
map_description.text = str(k)
i += 1
c += 1
# videos block
if t.videos_youtube != None or t.videos_vimeo != None:
videos = SubElement(child, "videos")
if t.videos_youtube != None :
for l in t.videos_youtube :
youtube = SubElement(videos, "youtube")
youtube.text = str(l)
if t.videos_vimeo != None :
for l in t.videos_vimeo :
vimeo = SubElement(videos, 'vimeo')
vimeo.text = str(l)
#.........这里部分代码省略.........