[IMP]Yaltik DSL : suffix better than xml type

This commit is contained in:
Fabien BOURGEOIS 2022-11-02 10:39:12 +01:00
parent cc40759909
commit 6b49ee69f4
3 changed files with 4 additions and 5 deletions

View File

@ -19,7 +19,7 @@
'name': 'Yaltik Odoo DSL base module and fns', 'name': 'Yaltik Odoo DSL base module and fns',
'summary': 'Yaltik Odoo Domain Specific Language base module and functions', 'summary': 'Yaltik Odoo Domain Specific Language base module and functions',
'description': """ Yaltik Odoo Domain Specific Language base module and functions """, 'description': """ Yaltik Odoo Domain Specific Language base module and functions """,
'version': '16.0.0.4.4', 'version': '16.0.0.4.5',
'category': 'Yaltik', 'category': 'Yaltik',
'author': 'Fabien Bourgeois', 'author': 'Fabien Bourgeois',
'license': 'AGPL-3', 'license': 'AGPL-3',

View File

@ -62,15 +62,14 @@ def xmln(tag='', attrs={}, children=[]):
raise TypeError('Invalid arguments for xmln') raise TypeError('Invalid arguments for xmln')
def xml_write(filepath, tree, pretty=True, xml_type='view'): def xml_write(filepath, tree, pretty=True, suffix='_views'):
""" Write XML file according to filename and given tree """ """ Write XML file according to filename and given tree """
if filepath.endswith('.py'): # if .pyc, no need to generate XML if filepath.endswith('.py'): # if .pyc, no need to generate XML
output_xml = ET.tostring(tree) output_xml = ET.tostring(tree)
if pretty: if pretty:
output_xml = minidom.parseString(output_xml).toprettyxml(indent=' ') output_xml = minidom.parseString(output_xml).toprettyxml(indent=' ')
suffix = '_views.xml' if xml_type == 'view' else '_data.xml'
output_path = path.abspath(filepath).split('/') output_path = path.abspath(filepath).split('/')
output_path[-1] = output_path[-1].replace('.py', suffix) output_path[-1] = output_path[-1].replace('.py', '%s.xml' % suffix)
output_path = '/'.join(output_path) output_path = '/'.join(output_path)
with open(output_path, 'w') as output_file: with open(output_path, 'w') as output_file:
output_file.write(output_xml) output_file.write(output_xml)

View File

@ -115,7 +115,7 @@ class TestXMLBase(unittest.TestCase):
self.assertIn('<child1 attr="value"/>', output_xml) self.assertIn('<child1 attr="value"/>', output_xml)
self.assertIn('<child2>Some text</child2>', output_xml) self.assertIn('<child2>Some text</child2>', output_xml)
unlink(filepath) unlink(filepath)
xml_write(__file__, tree, xml_type='data') xml_write(__file__, tree, suffix='_data')
filepath = __file__.replace('.py', '_data.xml') filepath = __file__.replace('.py', '_data.xml')
with open(filepath, 'r') as output_file: with open(filepath, 'r') as output_file:
output_xml = output_file.read() output_xml = output_file.read()