From 83dd3a2fe8d34851fe31c8a3a0bb6cca5a8abdd0 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Sat, 9 Mar 2013 20:52:35 +0100 Subject: [PATCH] Create config variable supybot.directories.data.web, and move robots.txt to this directory. --- src/conf.py | 6 +++--- src/httpserver.py | 44 +++++++++++++++++++++++++++++--------------- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/src/conf.py b/src/conf.py index d5b484d87..527f4fe7f 100644 --- a/src/conf.py +++ b/src/conf.py @@ -789,6 +789,9 @@ registerGlobalValue(supybot.directories, 'backup', registerGlobalValue(supybot.directories.data, 'tmp', DataFilenameDirectory('tmp', _("""Determines what directory temporary files are put into."""))) +registerGlobalValue(supybot.directories.data, 'web', + DataFilenameDirectory('web', _("""Determines what directory files of the + web server (templates, custom images, ...) are put into."""))) utils.file.AtomicFile.default.tmpDir = supybot.directories.data.tmp utils.file.AtomicFile.default.backupDir = supybot.directories.backup @@ -1113,9 +1116,6 @@ registerGlobalValue(supybot.servers.http, 'keepAlive', registry.Boolean(False, _("""Determines whether the server will stay alive if no plugin is using it. This also means that the server will start even if it is not used."""))) -registerGlobalValue(supybot.servers.http, 'robots', - registry.String('', _("""Determines the content of the robots.txt file, - served on the server to search engine."""))) registerGlobalValue(supybot.servers.http, 'favicon', registry.String('', _("""Determines the path of the file served as favicon to browsers."""))) diff --git a/src/httpserver.py b/src/httpserver.py index 04373c711..5b3620232 100644 --- a/src/httpserver.py +++ b/src/httpserver.py @@ -52,6 +52,32 @@ configGroup = conf.supybot.servers.http class RequestNotHandled(Exception): pass +TEMPLATE_DEFAULTS = { + 'index.html': """\ + + + """ + _('Supybot Web server index') + """ + + +

""" + _('Here is a list of the plugins that have a Web interface:') +\ + """ +

+ %(list)s + +""", + '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: + fd.write(content) + +def get_template(filename): + path = conf.supybot.directories.data.web.dirize(filename) + return open(path, 'r').read() + class RealSupyHTTPServer(HTTPServer): # TODO: make this configurable timeout = 0.5 @@ -184,26 +210,14 @@ class SupyIndex(SupyHTTPServerCallback): """Displays the index of available plugins.""" name = "index" defaultResponse = _("Request not handled.") - template = """ - - - """ + _('Supybot Web server index') + """ - - -

""" + _('Here is a list of the plugins that have a Web interface:') +\ - """ -

- %s - - """ def doGet(self, handler, path): plugins = [x for x in handler.server.callbacks.items()] if plugins == []: plugins = _('No plugins available.') else: - plugins = '' % '
  • '.join( + plugins = '' % '
  • '.join( ['%s' % (x,y.name) for x,y in plugins]) - response = self.template % plugins + response = get_template('index.html') % {'list': plugins} handler.send_response(200) self.send_header('Content_type', 'text/html') self.send_header('Content-Length', len(response)) @@ -215,7 +229,7 @@ class RobotsTxt(SupyHTTPServerCallback): name = 'robotstxt' defaultResponse = _('Request not handled') def doGet(self, handler, path): - response = conf.supybot.servers.http.robots().replace('\\n', '\n') + response = get_template('robots.txt') handler.send_response(200) self.send_header('Content-type', 'text/plain') self.send_header('Content-Length', len(response))