本文整理汇总了Python中elementtree.SimpleXMLWriter.XMLWriter.end方法的典型用法代码示例。如果您正苦于以下问题:Python XMLWriter.end方法的具体用法?Python XMLWriter.end怎么用?Python XMLWriter.end使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类elementtree.SimpleXMLWriter.XMLWriter
的用法示例。
在下文中一共展示了XMLWriter.end方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: installerLog
# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import end [as 别名]
def installerLog(package_details):
'''
This module writes the required fields of a package to a temporary
XML file which is then appended to the list of installedLog.xml.
Right now - only name and version written to the installedLog.xml.
'''
#package_details contain all the info about the package
w = XMLWriter('tempholder.xml')
xml = w.start("xml")
w.start("Package")
w.element("name", package_details[0])
w.element("version", package_details[1])
#w.element("architecture", package_details[2])
#w.element("short-description",package_details[3])
#w.element("installed",package_details[4])
#w.element("long-description",package_details[4])
#-----^basic logging data above^------
#w.element("section",package_details[5])
#w.element("installed-size",package_details[6])
#w.element("maintainer",package_details[7])
#w.element("original-maintainer",package_details[8])
#w.element("replaces",package_details[9])
#w.element("provides",package_details[10])
#w.element("pre-depends",package_details[11])
#w.element("depends",package_details[5])
#w.element("recomends",package_details[13])
#w.element("suggests",package_details[14])
#w.element("conflicts",package_details[15])
#w.element("filename",package_details[16])
#w.element("size",package_details[17])
#w.element("md5sum",package_details[18])
#w.element("homepage",package_details[19])
w.end()
w.close(xml)
示例2: project_save1
# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import end [as 别名]
def project_save1(tree):
f = open('resar.xml', 'w')
w = XMLWriter(f)
html = w.start("data")
w.element("empresa", '"' + tree.GetItemText(tree.GetRootItem(), 0) + '"')
w.start('items')
def printChildren(tree, treeItem):
subItem = tree.GetFirstChild(treeItem)[0]
name = tree.GetItemText(treeItem, 1)
index = tree.GetItemText(treeItem, 0)
try:
parent = tree.GetItemText(tree.GetItemParent(treeItem), 1)
except Exception:
parent = 'root'
if not subItem.IsOk():
w.element("item", nombre=name, indice=index, parent=parent)
else:
w.element("item", nombre=name, indice=index, parent='root')
while subItem.IsOk():
printChildren(tree, subItem)
subItem = tree.GetNextSibling(subItem)
printChildren(tree, tree.GetRootItem())
w.end('items')
w.close(html)
f.close()
示例3: createMetadata
# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import end [as 别名]
def createMetadata(item_ID):
# get number of files
images = os.listdir("/processing/"+item_ID+"/images")
leaf_count = len(images) - 1 #accounts for /thumbs directory in there
# get dimensions of cover and create cover image
cover_path = Template('/processing/$item_ID/images/$item_ID').substitute(item_ID=item_ID) + "00001.jpg"
im = Image.open(cover_path)
width, height = im.size #returns tuple
# generate cover thumbnail
max_cover_width = 200
max_cover_height = 200
im.thumbnail((max_cover_width, max_cover_height), Image.ANTIALIAS)
im.save(Template('/processing/$item_ID/$item_ID').substitute(item_ID=item_ID) + "_cover.jpg")
print "Cover created for",item_ID
# write to xml
fhand = Template("/processing/$item_ID/$item_ID$suffix.xml").substitute(item_ID=item_ID, suffix="_metadata")
w = XMLWriter(fhand, "utf-8")
metadata = w.start("add")
w.start("doc")
w.element("field", Template("meta:$item_ID").substitute(item_ID=item_ID), name="id")
w.element("field", Template("$item_ID").substitute(item_ID=item_ID), name="ItemID") #no underscore for solr index in "ItemID"
#creats overall ratio - height / width
w.element("field", str(height), name="pheight")
w.element("field", str(width), name="pwidth")
w.element("field", str(leaf_count), name="leafs")
w.element("field", Template("$item_ID").substitute(item_ID=item_ID), name="item_title") #how will we generate this? ItemID for now...
w.end() #closes <doc>
w.close(metadata)
示例4: main
# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import end [as 别名]
def main():
dimension = sys.argv[1]
min_count = int(sys.argv[2])
engine_response = _json_post('%s/ws/query' % (ENGINE_URL), ENGINE_QUERY % {'dimension':dimension, 'min_count': min_count})
facets = engine_response['facets'][dimension]['childIds']
w = XMLWriter(sys.stdout)
w.start("dimension", {'id': dimension, 'type': 'tree'})
for facet in facets:
w.start('element', {'id': facet, '_count':str(engine_response['facets'][dimension]['data'][facet]['count'])})
w.end('element')
w.end('dimension')
示例5: create_project
# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import end [as 别名]
def create_project(name, path, template=None):
os.mkdir(path)
os.mkdir(os.path.join(path, 'bin'))
os.mkdir(os.path.join(path, 'contabilidad'))
os.mkdir(os.path.join(path, 'documentos'))
f = open(os.path.join(path, 'bin','empresa.xml'), 'w')
w = XMLWriter(f)
html = w.start("data")
w.element("empresa", '"' + name + '"')
w.start('items')
w.element('item', nombre=name, indice='', parent='root')
w.end('items')
w.close(html)
f.close()
示例6: to_xml
# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import end [as 别名]
def to_xml(self):
from StringIO import StringIO
myxml = StringIO()
w = XMLWriter(myxml)
w.start(self._kind.lower(), name=self._label )
if self._m_title: w.element("title", self._m_title )
if self._m_subtitle: w.element("subtitle", self._m_subtitle )
if self._m_num: w.element("num", self._m_num )
if self._m_source: w.element("source", self._m_source )
self.to_xml_body(w)
w.end(self._kind.lower())
ret = myxml.getvalue()
myxml.close()
return ret
示例7: run1
# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import end [as 别名]
def run1():
x = XMLWriter("test.xml")
musicLibrary = x.start("musciLibrary")
x.start("song")
x.element("id", "2")
x.element("title", "Jigga What/Faint")
x.element("artist", "Linkin Park/Jay Z")
x.element("year", "2004")
x.element("trackNumber", "3")
x.element("totalTracks", "6")
x.element("genre", "Rap/Nu Metal")
x.end("song")
x.close(musicLibrary)
示例8: tagcloudxml
# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import end [as 别名]
def tagcloudxml(request):
xml = cStringIO.StringIO()
w = XMLWriter(xml)
tags = w.start("tags")
for tag in tagcloud():
w.element("a",
text=tag['tag'],
attrs={'href': "http://www.bhamtechevents.org/browse_events/%s".format(tag['tag']),
'title': "%s topics".format(tag["count"]), 'rel': "tag",
'style': "font-size: %s".format(tag["size"])}
)
w.end()
w.close(tags)
w.flush()
return HttpResponse(xml.read())
示例9: write_keymap
# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import end [as 别名]
def write_keymap(keymap, filename):
contexts = list(set([ c for c,a,k in keymap ]))
actions = list(set([ a for c,a,k in keymap ]))
w = XMLWriter(filename, "utf-8")
doc = w.start("keymap")
for context in contexts:
w.start(context)
w.start("keyboard")
for c,a,k in keymap:
if c==context:
w.element("key", a, id=k)
w.end()
w.end()
w.end()
w.close(doc)
示例10: process
# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import end [as 别名]
def process(self, args):
# Perform any base class processing.
if not super(NfoProcess, self).process(args):
return
# If we don't have an output parameter, we figure it out from
# the input filename.
output = args.output
if not output:
output = os.path.splitext(args.tmdb)[0] + ".nfo"
# Check to see if the file exists.
if os.path.isfile(output) and not args.force:
print "Cannot overwrite file: " + output
return False
# Open up the output file.
xml = open(output, 'w')
xml.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
w = XMLWriter(xml, 'utf-8')
tag = w.start("movie", ThumbGen="1")
w.element("hasrighttoleftdirection", "false")
w.element("title", self.movie['title'])
w.element("originaltitle", self.movie['original_title'])
w.element("filename", os.path.splitext(args.tmdb)[0] + ".mp4")
w.element("tagline", self.movie['tagline'])
w.element("releasedate", self.movie['release_date'])
w.element("id", self.movie['imdb_id'])
w.element("runtime", format(self.movie['runtime']))
w.element("plot", self.movie['overview'])
# Write out the genres.
w.start("genre")
for genre in self.movie['genres']:
w.element("name", genre['name'])
w.end()
# Media information
w.start("mediainfo")
w.start("Resolution")
w.element("Flag", "Resolution_480p")
w.end()
w.element("resolution", "480P")
w.end()
# Finish up the document.
w.end()
w.close(tag)
xml.close()
# Report that we created the file.
self.log.info("Created " + output)
示例11: main
# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import end [as 别名]
def main():
genre_objects = json.load(sys.stdin)
registry = {}
for obj in genre_objects:
registry[obj['id']] = obj
_validate_parent_child_relationships(registry)
top_level = [obj for obj in genre_objects if len(obj['_parent_ids']) == 0]
touched = set()
paths = set()
w = XMLWriter(sys.stdout)
w.start("dimension", {'id':'genre', 'type':'tree'})
for obj in top_level:
process_genre(w, obj, '', registry, touched, paths)
w.end('dimension')
_assert_all_visited(registry, touched)
示例12: __call__
# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import end [as 别名]
def __call__(self,options):
"""Make .tex file for JOB"""
ret,jlist,base,jobspecfile,order,jjspec = e4t.cli.select_jobs_from_jobfile(options.jobfile)
def xmloutjobs(w,name,*args,**kw):
(datareqs,processors,outputs) = e4t.cli.get_elem_configs(*args,**kw)
cfg = e4t.cli._read_cfgfile(kw,'OUTPUT',name)
_cfgs = (kw, cfg)
if cfg:
# pprint(cfg)
cfg = udict(cfg)
cfg.remove('^__.*')
cfg = ldict([ (k.replace(' ','_'),v) for k,v in cfg.items()])
w.start("job",name=name,**ldict(cfg))
w.end("job")
formats = options.options.xget('FORMAT','XML')
from elementtree.SimpleXMLWriter import XMLWriter
from StringIO import StringIO
myxml = StringIO()
w = XMLWriter(myxml)
for part,jobs in jlist.items():
w.start('index', name=part )
for j,k in jobs:
if k['kind'] in ('table','figure'):
xmloutjobs(w,j,**k)
w.end('index')
ret = myxml.getvalue()
xmls = dom.parseString(ret) # or xml.dom.minidom.parseString(xml_string)
pp = Postprocessor(options=options)
pp.output(False,xmls.toprettyxml(),'%s.xml'% part)
示例13: writeXML
# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import end [as 别名]
def writeXML(frames, path, args):
out_xml = XMLWriter(path)
out_xml.declaration()
doc = out_xml.start("AnnotationEvaluation")
# source information
out_xml.element("video", mark_in=str(args[4]), mark_out=str(args[5]))
out_xml.element("mapper", os.path.basename(args[1]))
out_xml.element("annotation", os.path.basename(args[2]))
out_xml.element("comparison", mean_err=str(calMean(frames)))
# compared points
out_xml.start("frames", total=str((args[5]-1) - (args[4]+1)+1), compared=str(len(frames)))
for f in frames.keys():
out_xml.start("frame", num=str(f))
for key in frames[f]:
out_xml.start("object", lens=Theta.name(frames[f][key]["lens"]), name=key, err=str(frames[f][key]["err"]))
out_xml.element("annotatedCentroid", x=str(frames[f][key]["ann_x"]), y=str(frames[f][key]["ann_y"]))
out_xml.element("mappedCentroid", x=str(frames[f][key]["map_x"]), y=str(frames[f][key]["map_y"]))
out_xml.end() # object
out_xml.end() # frames
# clean up
out_xml.close(doc)
示例14: post
# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import end [as 别名]
def post():
try:
d = request.form['thedata']
ds = json.loads(d)['activity']
stime = ds['startTimeUtc']
stime = dateutil.parser.parse(stime)
points = ds['geo']['waypoints']
name = ds['name']
f = StringIO.StringIO()
w = XMLWriter(f)
gpx_attribs = {"version":"1.1",
"creator":"unrealduck.com",
"xmlns:xsi":"http://www.w3.org/2001/XMLSchema-instance",
"xmlns:gpxtpx":"http://www.garmin.com/xmlschemas/TrackPointExtension/v1",
"xmlns":"http://www.topografix.com/GPX/1/1",
"xsi:schemaLocation":"http://www.topografix.com/GPX/1/1 http://www.topografix.com/gpx/1/1/gpx.xsd http://www.garmin.com/xmlschemas/TrackPointExtension/v1 http://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd"}
gpx = w.start("gpx", gpx_attribs)
w.start("metadata")
w.element("name", name)
w.element("time", str(stime).replace(" ", "T"))
w.element("desc", "Import from nikeplus.com")
w.end()
w.start("trk")
w.element("name", name)
w.start("trkseg")
for i,pt in zip(range(len(points)), points):
time = stime + datetime.timedelta(seconds=i)
w.start("trkpt", lon=str(pt['lon']), lat=str(pt['lat']))
w.element("ele", str(pt['ele']))
w.element("time", str(time).replace(" ", "T"))
w.end()
w.end()
w.end()
w.close(gpx)
filename = '_'.join([ds['activityType'], ds['deviceType'], str(stime.date()), str(stime.time())])
response = make_response("<?xml version=\"1.0\" ?>"+f.getvalue())
response.headers['Content-Type'] = 'application/gpx+xml'
response.headers['Content-Disposition'] = 'attachment; filename='+filename+'.gpx'
return response
except KeyError:
print "KeyError"
return make_response("KeyError")
except:
print "UnexpectedError"
print sys.exc_info()[0]
return make_response("Unexpected error")
示例15: _test_to_html
# 需要导入模块: from elementtree.SimpleXMLWriter import XMLWriter [as 别名]
# 或者: from elementtree.SimpleXMLWriter.XMLWriter import end [as 别名]
def _test_to_html(test):
iodevice = StringIO()
w = XMLWriter(iodevice, "utf-8")
w.start(u"html")
w.start(u"body")
w.start(u"div")
w.start(u"table", border=u"1")
w.start(u"tr")
w.element(u"th", u"Base verbale")
w.element(u"th", u"Preterit")
w.element(u"th", u"Participe passé")
w.element(u"th", u"Traduction")
#w.element(u"th", u"Points")
w.end(u"tr")
for entry in test.array:
_add_row(entry, w)
w.end(u"table")
w.end(u"div")
solution_lines = []
current_line_nb_solution = 0
for solution in test.solutions:
if len(solution_lines) == 0 or current_line_nb_solution >= 10:
solution_lines.append(solution)
current_line_nb_solution = 0
else:
solution_lines[-1] += " / "+solution
current_line_nb_solution += 1
w.element(u"br", u"")
w.element(u"div", u"Solutions:")
for line in solution_lines:
w.element(u"div", line)
w.end(u"body")
w.end(u"html")
html_str = unicode(iodevice.getvalue(), encoding='utf-8')
iodevice.close()
return html_str