[WIP][IMP]XML Base : pretty option of xml write
This commit is contained in:
parent
315f4a82ae
commit
143492e58b
@ -62,11 +62,14 @@ def xmln(tag='', attrs={}, children=[]):
|
||||
raise TypeError('Invalid arguments for xmln')
|
||||
|
||||
|
||||
def xml_write(filepath, tree):
|
||||
def xml_write(filepath, tree, pretty=True):
|
||||
""" Write XML file according to filename and given tree """
|
||||
if filepath.endswith('.py'): # if .pyc, no need to generate XML
|
||||
output_xml = minidom.parseString(ET.tostring(tree)).toprettyxml(indent=' ')
|
||||
output_path = path.dirname(path.abspath(filepath))
|
||||
fpath = u'/'.join([output_path, path.basename(filepath)]).replace('.py', '_views.xml')
|
||||
with open(fpath, 'w') as output_file:
|
||||
output_xml = ET.tostring(tree)
|
||||
if pretty:
|
||||
output_xml = minidom.parseString(output_xml).toprettyxml(indent=' ')
|
||||
output_path = path.abspath(filepath).split(u'/')
|
||||
output_path[-1] = output_path[-1].replace(u'.py', u'_views.xml')
|
||||
output_path = u'/'.join(output_path)
|
||||
with open(output_path, 'w') as output_file:
|
||||
output_file.write(output_xml)
|
||||
|
Loading…
x
Reference in New Issue
Block a user