Handle template syntax errors

parent 8b03916a
......@@ -15,6 +15,7 @@ from settingsd.tools.process import execProcess
import settingsd.tools.editors
from os import path
from jinja2 import Template
from jinja2.exceptions import TemplateSyntaxError
##### Private constants #####
SERVICE_NAME = "maild"
......@@ -22,16 +23,21 @@ MAILD_METHODS_NAMESPACE = "maild"
MAILD_DRWEB_INI = "/etc/opt/drweb.com/drweb.ini"
MAILD_MILTER_HOOK = "/etc/opt/drweb.com/milterhook.lua"
##### Private classes #####
class MailD(service.FunctionObject) :
### DBus methods ###
@service.functionMethod(MAILD_METHODS_NAMESPACE, in_signature="sss")
@service.functionMethod(MAILD_METHODS_NAMESPACE, in_signature="sss", out_signature="s")
def regenerateDrwebIni(self, config_filename, drweb_ini_templates_dir, lua_templates_dir):
with open(config_filename, 'r') as maild_config:
config = safe_load(maild_config.read())
try:
self.renderTemplate(config['template'], drweb_ini_templates_dir, config['settings'], MAILD_DRWEB_INI)
self.renderTemplate(config['template'], lua_templates_dir, config['settings'], MAILD_MILTER_HOOK)
return ''
except TemplateSyntaxError as exc:
return str(exc)
def renderTemplate(self, template, templates_dir, settings, output_filename):
template_filename = path.join(templates_dir, template + '.tpl')
......
......@@ -15,6 +15,7 @@ from settingsd.tools.process import execProcess
import settingsd.tools.editors
from os import path
from jinja2 import Template
from jinja2.exceptions import TemplateSyntaxError
##### Private constants #####
SERVICE_NAME = "postfix"
......@@ -24,10 +25,12 @@ POSTFIX_MAIN_CF = "/etc/postfix/main.cf"
##### Private classes #####
class Postfix(service.FunctionObject) :
### DBus methods ###
@service.functionMethod(POSTFIX_METHODS_NAMESPACE, in_signature="ss")
@service.functionMethod(POSTFIX_METHODS_NAMESPACE, in_signature="ss", out_signature="s")
def regenerateMainCf(self, config_filename, templates_dir):
with open(config_filename, 'r') as postfix_config:
config = safe_load(postfix_config.read())
try:
template_filename = path.join(templates_dir, config['template'] + '.tpl')
with open(template_filename, 'r') as template_text:
template = Template(template_text.read())
......@@ -36,6 +39,10 @@ class Postfix(service.FunctionObject) :
with open(POSTFIX_MAIN_CF, 'w+') as main_cf:
main_cf.write(config_text)
return ''
except TemplateSyntaxError as exc:
return str(exc)
##### Public classes #####
class Service(service.Service) :
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment