libreschool-startpage/root/etc/e-smith/events/actions/startpage-refresh

31 lines
851 B
Python

#!/usr/bin/env python
import subprocess
from jinja2 import Template
import json
import os
templatedir = '/usr/share/startpage/templates/'
_data = json.loads(subprocess.Popen(['/sbin/e-smith/db', 'startpage', 'showjson'],stdout=subprocess.PIPE).communicate()[0])
_config = [x for x in _data if x['type']=='configuration'][0]
_status = _config['props']['status'] == 'enabled'
_outfile = _config['props']['outfile']
_template = _config['props']['template']
try:
os.remove(_outfile)
except OSError:
pass
if _status:
_links = [x for x in _data if x['type']=='link']
_links = [x for x in _links if x['props']['enable']=='yes']
tplfile = templatedir + _template + '.jinja2'
with open(tplfile) as file_:
template = Template(file_.read())
out = template.render(links=_links)
with open(_outfile, "wb") as f:
f.write(out)