bundlewrap/libs/systemd.py
mwiegand 9db53faf23 wip
2021-07-13 16:23:47 +02:00

27 lines
661 B
Python

from mako.template import Template
template = '''
% for segment, options in sorted(data.items()):
% if '#' in segment:
# ${segment.split('#', 2)[1]}
% endif
[${segment.split('#')[0]}]
% for option, value in options.items():
% if isinstance(value, dict):
% for k, v in value.items():
${option}=${k}=${v}
% endfor
% elif isinstance(value, (list, set, tuple)):
% for item in sorted(value):
${option}=${item}
% endfor
% else:
${option}=${str(value)}
% endif
% endfor
% endfor
'''
def generate_unitfile(data):
return Template(template).render(data=data).lstrip()