Files
WPIQ/wo/core/template.py

44 lines
1.6 KiB
Python
Raw Permalink Normal View History

import os
2019-09-04 20:36:15 +02:00
from wo.core.logging import Log
"""
Render Templates
"""
2019-10-12 11:07:25 +02:00
class WOTemplate:
2019-10-02 13:13:32 +02:00
"""WordOps template utilities"""
2019-09-23 16:35:20 +02:00
def deploy(self, fileconf, template, data, overwrite=True):
"""Deploy template with render()"""
2019-08-19 18:23:29 +02:00
data = dict(data)
2019-08-25 23:30:05 +02:00
if (not os.path.isfile('{0}.custom'
.format(fileconf))):
if (not overwrite):
if not os.path.isfile('{0}'.format(fileconf)):
Log.debug(self, 'Writting the configuration to '
'file {0}'.format(fileconf))
wo_template = open('{0}'.format(fileconf),
encoding='utf-8', mode='w')
self.app.render((data), '{0}'.format(template),
out=wo_template)
wo_template.close()
else:
2019-08-19 18:21:51 +02:00
Log.debug(self, 'Writting the configuration to '
'file {0}'.format(fileconf))
wo_template = open('{0}'.format(fileconf),
encoding='utf-8', mode='w')
self.app.render((data), '{0}'.format(template),
out=wo_template)
wo_template.close()
else:
2019-08-25 23:30:05 +02:00
Log.debug(self, 'Writting the configuration to '
'file {0}.orig'.format(fileconf))
wo_template = open('{0}.orig'.format(fileconf),
encoding='utf-8', mode='w')
self.app.render((data), '{0}'.format(template),
out=wo_template)
wo_template.close()