web_server: Drop use of loaded_modules and use App.list

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2021-11-21 12:50:08 -08:00 committed by James Valleroy
parent 528fd08245
commit 57422d562e
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808

View File

@ -5,11 +5,13 @@ Setup CherryPy web server.
import logging import logging
import os import os
import sys
import warnings import warnings
import cherrypy import cherrypy
from . import app, cfg, log, module_loader, web_framework from . import app as app_module
from . import cfg, log, web_framework
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -57,13 +59,14 @@ def init():
_mount_static_directory('/usr/share/javascript', '/javascript') _mount_static_directory('/usr/share/javascript', '/javascript')
for module_name, module in module_loader.loaded_modules.items(): for app in app_module.App.list():
module = sys.modules[app.__module__]
module_path = os.path.dirname(module.__file__) module_path = os.path.dirname(module.__file__)
static_dir = os.path.join(module_path, 'static') static_dir = os.path.join(module_path, 'static')
if not os.path.isdir(static_dir): if not os.path.isdir(static_dir):
continue continue
urlprefix = "%s%s" % (web_framework.get_static_url(), module_name) urlprefix = "%s%s" % (web_framework.get_static_url(), app.app_id)
_mount_static_directory(static_dir, urlprefix) _mount_static_directory(static_dir, urlprefix)
for component in StaticFiles.list(): for component in StaticFiles.list():
@ -88,7 +91,7 @@ def run(on_web_server_stop):
cherrypy.engine.block() cherrypy.engine.block()
class StaticFiles(app.FollowerComponent): class StaticFiles(app_module.FollowerComponent):
"""Component to serve static files shipped with an app. """Component to serve static files shipped with an app.
Any files in <app>/static directory will be automatically served on Any files in <app>/static directory will be automatically served on