allow modules to have custom static directories

This commit is contained in:
fonfon 2014-07-30 15:03:52 +03:00
parent 27287097c5
commit 57ba43cfc9
2 changed files with 16 additions and 0 deletions

View File

@ -29,6 +29,8 @@ import cfg
LOGGER = logging.getLogger(__name__)
loaded_modules = []
def load_modules():
"""
@ -71,6 +73,7 @@ def load_modules():
for module_name in ordered_modules:
_initialize_module(modules[module_name])
loaded_modules.append(module_name)
def _insert_modules(module_name, module, remaining_modules, ordered_modules):

View File

@ -104,6 +104,19 @@ def setup_server():
'tools.staticdir.dir': '.'}}
cherrypy.tree.mount(None, django.conf.settings.STATIC_URL, config)
# TODO: our modules are mimicking django apps. It'd be better to convert
# our modules to django apps instead of reinventing the wheel.
# (we'll still have to serve the static files with cherrypy though)
for module in module_loader.loaded_modules:
staticdir = os.path.join(cfg.file_root, 'modules', module, 'static')
if os.path.isdir(staticdir):
config = {
'/': {'tools.staticdir.root': staticdir,
'tools.staticdir.on': True,
'tools.staticdir.dir': '.'}}
urlprefix = "%s%s" % (django.conf.settings.STATIC_URL, module)
cherrypy.tree.mount(None, urlprefix, config)
if not cfg.no_daemon:
Daemonizer(cherrypy.engine).subscribe()