From 57ba43cfc91ccaacdb60c145d4610929fd82cbcd Mon Sep 17 00:00:00 2001 From: fonfon Date: Wed, 30 Jul 2014 15:03:52 +0300 Subject: [PATCH] allow modules to have custom static directories --- module_loader.py | 3 +++ plinth.py | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/module_loader.py b/module_loader.py index b31f0e7c4..e06f2bc50 100644 --- a/module_loader.py +++ b/module_loader.py @@ -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): diff --git a/plinth.py b/plinth.py index f84d4b85a..bfe2ea520 100755 --- a/plinth.py +++ b/plinth.py @@ -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()