httpserver: Use new algorithm to load default templates.

This commit is contained in:
Valentin Lorentz 2013-03-11 16:38:21 +01:00
parent 83dd3a2fe8
commit c4b9c80198
1 changed files with 13 additions and 6 deletions

View File

@ -52,7 +52,7 @@ configGroup = conf.supybot.servers.http
class RequestNotHandled(Exception):
pass
TEMPLATE_DEFAULTS = {
DEFAULT_TEMPLATES = {
'index.html': """\
<html>
<head>
@ -68,15 +68,22 @@ TEMPLATE_DEFAULTS = {
'robots.txt': """""",
}
for filename, content in TEMPLATE_DEFAULTS.items():
path = conf.supybot.directories.data.web.dirize(filename)
if not os.path.isfile(path):
with open(path, 'a') as fd:
def set_default_templates(defaults):
for filename, content in defaults.items():
path = conf.supybot.directories.data.web.dirize(filename)
if os.path.isfile(path + '.example'):
os.unlink(path + '.example')
with open(path + '.example', 'a') as fd:
fd.write(content)
set_default_templates(DEFAULT_TEMPLATES)
def get_template(filename):
path = conf.supybot.directories.data.web.dirize(filename)
return open(path, 'r').read()
if os.path.isfile(path):
return open(path, 'r').read()
else:
assert os.path.isfile(path + '.example'), path + '.example'
return open(path + '.example', 'r').read()
class RealSupyHTTPServer(HTTPServer):
# TODO: make this configurable