mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-02 17:29:22 +01:00
httpserver: Use new algorithm to load default templates.
This commit is contained in:
parent
83dd3a2fe8
commit
c4b9c80198
@ -52,7 +52,7 @@ configGroup = conf.supybot.servers.http
|
|||||||
class RequestNotHandled(Exception):
|
class RequestNotHandled(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
TEMPLATE_DEFAULTS = {
|
DEFAULT_TEMPLATES = {
|
||||||
'index.html': """\
|
'index.html': """\
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
@ -68,15 +68,22 @@ TEMPLATE_DEFAULTS = {
|
|||||||
'robots.txt': """""",
|
'robots.txt': """""",
|
||||||
}
|
}
|
||||||
|
|
||||||
for filename, content in TEMPLATE_DEFAULTS.items():
|
def set_default_templates(defaults):
|
||||||
path = conf.supybot.directories.data.web.dirize(filename)
|
for filename, content in defaults.items():
|
||||||
if not os.path.isfile(path):
|
path = conf.supybot.directories.data.web.dirize(filename)
|
||||||
with open(path, 'a') as fd:
|
if os.path.isfile(path + '.example'):
|
||||||
|
os.unlink(path + '.example')
|
||||||
|
with open(path + '.example', 'a') as fd:
|
||||||
fd.write(content)
|
fd.write(content)
|
||||||
|
set_default_templates(DEFAULT_TEMPLATES)
|
||||||
|
|
||||||
def get_template(filename):
|
def get_template(filename):
|
||||||
path = conf.supybot.directories.data.web.dirize(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):
|
class RealSupyHTTPServer(HTTPServer):
|
||||||
# TODO: make this configurable
|
# TODO: make this configurable
|
||||||
|
Loading…
Reference in New Issue
Block a user