diff --git a/yaltik_dsl/xml_base.py b/yaltik_dsl/xml_base.py index 9bbaa2b..9d34a80 100644 --- a/yaltik_dsl/xml_base.py +++ b/yaltik_dsl/xml_base.py @@ -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)