[IMP]Yaltik DSL : allow other suffix for XML
This commit is contained in:
parent
0cc980b7a9
commit
c2ad72a3a6
@ -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.1',
|
'version': '16.0.0.4.3',
|
||||||
'category': 'Yaltik',
|
'category': 'Yaltik',
|
||||||
'author': 'Fabien Bourgeois',
|
'author': 'Fabien Bourgeois',
|
||||||
'license': 'AGPL-3',
|
'license': 'AGPL-3',
|
||||||
|
@ -62,14 +62,15 @@ def xmln(tag='', attrs={}, children=[]):
|
|||||||
raise TypeError('Invalid arguments for xmln')
|
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 """
|
""" 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=' ')
|
||||||
output_path = path.abspath(filepath).split(u'/')
|
suffix = '_views.xml' if xml_type == 'view' else '_data.xml'
|
||||||
output_path[-1] = output_path[-1].replace(u'.py', u'_views.xml')
|
output_path = path.abspath(filepath).split('/')
|
||||||
output_path = u'/'.join(output_path)
|
output_path[-1] = output_path[-1].replace('.py', suffix)
|
||||||
|
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)
|
||||||
|
@ -115,6 +115,15 @@ 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')
|
||||||
|
filepath = __file__.replace('.py', '_data.xml')
|
||||||
|
with open(filepath, 'r') as output_file:
|
||||||
|
output_xml = output_file.read()
|
||||||
|
self.assertIn('<?xml version', output_xml)
|
||||||
|
self.assertIn('<root>', output_xml)
|
||||||
|
self.assertIn('<child1 attr="value"/>', output_xml)
|
||||||
|
self.assertIn('<child2>Some text</child2>', output_xml)
|
||||||
|
unlink(filepath)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user