From c2ad72a3a61c986fad36ea6cd7342fe959219da2 Mon Sep 17 00:00:00 2001 From: Fabien BOURGEOIS Date: Wed, 2 Nov 2022 10:25:01 +0100 Subject: [PATCH] [IMP]Yaltik DSL : allow other suffix for XML --- yaltik_dsl/__manifest__.py | 2 +- yaltik_dsl/src/xml_base.py | 9 +++++---- yaltik_dsl/tests/test_xml_base.py | 9 +++++++++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/yaltik_dsl/__manifest__.py b/yaltik_dsl/__manifest__.py index 282cdc8..e71b048 100644 --- a/yaltik_dsl/__manifest__.py +++ b/yaltik_dsl/__manifest__.py @@ -19,7 +19,7 @@ 'name': 'Yaltik Odoo DSL base module and fns', 'summary': 'Yaltik Odoo Domain Specific Language base module and functions', 'description': """ Yaltik Odoo Domain Specific Language base module and functions """, - 'version': '16.0.0.4.1', + 'version': '16.0.0.4.3', 'category': 'Yaltik', 'author': 'Fabien Bourgeois', 'license': 'AGPL-3', diff --git a/yaltik_dsl/src/xml_base.py b/yaltik_dsl/src/xml_base.py index 426c927..f7289f7 100644 --- a/yaltik_dsl/src/xml_base.py +++ b/yaltik_dsl/src/xml_base.py @@ -62,14 +62,15 @@ def xmln(tag='', attrs={}, children=[]): raise TypeError('Invalid arguments for xmln') -def xml_write(filepath, tree, pretty=True): +def xml_write(filepath, tree, pretty=True, xml_type='view'): """ Write XML file according to filename and given tree """ if filepath.endswith('.py'): # if .pyc, no need to generate XML 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) + suffix = '_views.xml' if xml_type == 'view' else '_data.xml' + output_path = path.abspath(filepath).split('/') + output_path[-1] = output_path[-1].replace('.py', suffix) + output_path = '/'.join(output_path) with open(output_path, 'w') as output_file: output_file.write(output_xml) diff --git a/yaltik_dsl/tests/test_xml_base.py b/yaltik_dsl/tests/test_xml_base.py index 66a5ad6..00a69d6 100644 --- a/yaltik_dsl/tests/test_xml_base.py +++ b/yaltik_dsl/tests/test_xml_base.py @@ -115,6 +115,15 @@ class TestXMLBase(unittest.TestCase): self.assertIn('', output_xml) self.assertIn('Some text', output_xml) unlink(filepath) + xml_write(__file__, tree, xml_type='data') + filepath = __file__.replace('.py', '_data.xml') + with open(filepath, 'r') as output_file: + output_xml = output_file.read() + self.assertIn('', output_xml) + self.assertIn('', output_xml) + self.assertIn('Some text', output_xml) + unlink(filepath) if __name__ == '__main__': unittest.main()