mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-09-19 04:59:01 +00:00
Load modules using explict paths instead of config file name
This commit is contained in:
parent
22def21d6b
commit
cc549fff61
@ -0,0 +1 @@
|
|||||||
|
plinth.modules.apps
|
||||||
@ -0,0 +1 @@
|
|||||||
|
plinth.modules.config
|
||||||
@ -0,0 +1 @@
|
|||||||
|
plinth.modules.diagnostics
|
||||||
@ -0,0 +1 @@
|
|||||||
|
plinth.modules.expert_mode
|
||||||
@ -0,0 +1 @@
|
|||||||
|
plinth.modules.firewall
|
||||||
@ -0,0 +1 @@
|
|||||||
|
plinth.modules.first_boot
|
||||||
@ -0,0 +1 @@
|
|||||||
|
plinth.modules.help
|
||||||
@ -0,0 +1 @@
|
|||||||
|
plinth.modules.lib
|
||||||
@ -0,0 +1 @@
|
|||||||
|
plinth.modules.owncloud
|
||||||
@ -0,0 +1 @@
|
|||||||
|
plinth.modules.packages
|
||||||
@ -0,0 +1 @@
|
|||||||
|
plinth.modules.pagekite
|
||||||
@ -0,0 +1 @@
|
|||||||
|
plinth.modules.system
|
||||||
@ -0,0 +1 @@
|
|||||||
|
plinth.modules.tor
|
||||||
@ -0,0 +1 @@
|
|||||||
|
plinth.modules.users
|
||||||
@ -0,0 +1 @@
|
|||||||
|
plinth.modules.xmpp
|
||||||
@ -4,6 +4,7 @@ import argparse
|
|||||||
import django.conf
|
import django.conf
|
||||||
import django.core.management
|
import django.core.management
|
||||||
import django.core.wsgi
|
import django.core.wsgi
|
||||||
|
import importlib
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import stat
|
import stat
|
||||||
@ -98,9 +99,10 @@ def setup_server():
|
|||||||
# TODO: our modules are mimicking django apps. It'd be better to convert
|
# TODO: our modules are mimicking django apps. It'd be better to convert
|
||||||
# our modules to Django apps instead of reinventing the wheel.
|
# our modules to Django apps instead of reinventing the wheel.
|
||||||
# (we'll still have to serve the static files with cherrypy though)
|
# (we'll still have to serve the static files with cherrypy though)
|
||||||
for module in module_loader.LOADED_MODULES:
|
for module_name in module_loader.loaded_modules:
|
||||||
static_dir = os.path.join(cfg.file_root, 'plinth', 'modules', module,
|
module = importlib.import_module(module_name)
|
||||||
'static')
|
module_path = os.path.dirname(module.__file__)
|
||||||
|
static_dir = os.path.join(module_path, 'static')
|
||||||
if not os.path.isdir(static_dir):
|
if not os.path.isdir(static_dir):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|||||||
@ -23,6 +23,7 @@ import django
|
|||||||
import importlib
|
import importlib
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
|
|
||||||
from plinth import cfg
|
from plinth import cfg
|
||||||
from plinth import urls
|
from plinth import urls
|
||||||
@ -30,7 +31,7 @@ from plinth.signals import pre_module_loading, post_module_loading
|
|||||||
|
|
||||||
LOGGER = logging.getLogger(__name__)
|
LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
LOADED_MODULES = []
|
loaded_modules = []
|
||||||
|
|
||||||
|
|
||||||
def load_modules():
|
def load_modules():
|
||||||
@ -39,27 +40,30 @@ def load_modules():
|
|||||||
import them from modules directory.
|
import them from modules directory.
|
||||||
"""
|
"""
|
||||||
pre_module_loading.send_robust(sender="module_loader")
|
pre_module_loading.send_robust(sender="module_loader")
|
||||||
module_names = []
|
|
||||||
modules = {}
|
modules = {}
|
||||||
module_directory = os.path.join(cfg.config_dir, 'modules-enabled')
|
module_directory = os.path.join(cfg.config_dir, 'modules-enabled')
|
||||||
for name in os.listdir(module_directory):
|
for file_name in os.listdir(module_directory):
|
||||||
full_name = 'plinth.modules.{module}'.format(module=name)
|
full_file_name = os.path.join(module_directory, file_name)
|
||||||
|
with open(full_file_name, 'r') as file:
|
||||||
|
for line in file:
|
||||||
|
line = re.sub('#.*', '', line)
|
||||||
|
line = line.strip()
|
||||||
|
if line:
|
||||||
|
modules[line] = None
|
||||||
|
|
||||||
LOGGER.info('Importing %s', full_name)
|
for module_name in modules:
|
||||||
|
LOGGER.info('Importing %s', module_name)
|
||||||
try:
|
try:
|
||||||
module = importlib.import_module(full_name)
|
modules[module_name] = importlib.import_module(module_name)
|
||||||
modules[name] = module
|
|
||||||
module_names.append(name)
|
|
||||||
except Exception as exception:
|
except Exception as exception:
|
||||||
LOGGER.exception('Could not import modules/%s: %s',
|
LOGGER.exception('Could not import %s: %s', module_name, exception)
|
||||||
name, exception)
|
|
||||||
if cfg.debug:
|
if cfg.debug:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
_include_module_urls(full_name, name)
|
_include_module_urls(module_name)
|
||||||
|
|
||||||
ordered_modules = []
|
ordered_modules = []
|
||||||
remaining_modules = dict(modules)
|
remaining_modules = dict(modules) # Make a copy
|
||||||
for module_name in modules:
|
for module_name in modules:
|
||||||
if module_name not in remaining_modules:
|
if module_name not in remaining_modules:
|
||||||
continue
|
continue
|
||||||
@ -76,9 +80,9 @@ def load_modules():
|
|||||||
|
|
||||||
for module_name in ordered_modules:
|
for module_name in ordered_modules:
|
||||||
_initialize_module(modules[module_name])
|
_initialize_module(modules[module_name])
|
||||||
LOADED_MODULES.append(module_name)
|
loaded_modules.append(module_name)
|
||||||
post_module_loading.send_robust(sender="module_loader")
|
|
||||||
|
|
||||||
|
post_module_loading.send_robust(sender="module_loader")
|
||||||
|
|
||||||
|
|
||||||
def _insert_modules(module_name, module, remaining_modules, ordered_modules):
|
def _insert_modules(module_name, module, remaining_modules, ordered_modules):
|
||||||
@ -88,7 +92,7 @@ def _insert_modules(module_name, module, remaining_modules, ordered_modules):
|
|||||||
|
|
||||||
dependencies = []
|
dependencies = []
|
||||||
try:
|
try:
|
||||||
dependencies = module.DEPENDS
|
dependencies = module.depends
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -108,8 +112,9 @@ def _insert_modules(module_name, module, remaining_modules, ordered_modules):
|
|||||||
ordered_modules.append(module_name)
|
ordered_modules.append(module_name)
|
||||||
|
|
||||||
|
|
||||||
def _include_module_urls(module_name, namespace):
|
def _include_module_urls(module_name):
|
||||||
"""Include the module's URLs in global project URLs list"""
|
"""Include the module's URLs in global project URLs list"""
|
||||||
|
namespace = module_name.split('.')[-1]
|
||||||
url_module = module_name + '.urls'
|
url_module = module_name + '.urls'
|
||||||
try:
|
try:
|
||||||
urls.urlpatterns += django.conf.urls.patterns(
|
urls.urlpatterns += django.conf.urls.patterns(
|
||||||
|
|||||||
@ -24,4 +24,4 @@ from .config import init
|
|||||||
|
|
||||||
__all__ = ['config', 'init']
|
__all__ = ['config', 'init']
|
||||||
|
|
||||||
DEPENDS = ['system']
|
depends = ['plinth.modules.system']
|
||||||
|
|||||||
@ -24,4 +24,4 @@ from .diagnostics import init
|
|||||||
|
|
||||||
__all__ = ['diagnostics', 'init']
|
__all__ = ['diagnostics', 'init']
|
||||||
|
|
||||||
DEPENDS = ['system']
|
depends = ['plinth.modules.system']
|
||||||
|
|||||||
@ -24,4 +24,4 @@ from .expert_mode import init
|
|||||||
|
|
||||||
__all__ = ['expert_mode', 'init']
|
__all__ = ['expert_mode', 'init']
|
||||||
|
|
||||||
DEPENDS = ['system']
|
depends = ['plinth.modules.system']
|
||||||
|
|||||||
@ -24,4 +24,4 @@ from .firewall import init
|
|||||||
|
|
||||||
__all__ = ['firewall', 'init']
|
__all__ = ['firewall', 'init']
|
||||||
|
|
||||||
DEPENDS = ['system']
|
depends = ['plinth.modules.system']
|
||||||
|
|||||||
@ -24,4 +24,4 @@ from .owncloud import init
|
|||||||
|
|
||||||
__all__ = ['owncloud', 'init']
|
__all__ = ['owncloud', 'init']
|
||||||
|
|
||||||
DEPENDS = ['apps']
|
depends = ['plinth.modules.apps']
|
||||||
|
|||||||
@ -24,4 +24,4 @@ from .packages import init
|
|||||||
|
|
||||||
__all__ = ['packages', 'init']
|
__all__ = ['packages', 'init']
|
||||||
|
|
||||||
DEPENDS = ['system']
|
depends = ['plinth.modules.system']
|
||||||
|
|||||||
@ -24,4 +24,4 @@ from .pagekite import init
|
|||||||
|
|
||||||
__all__ = ['pagekite', 'init']
|
__all__ = ['pagekite', 'init']
|
||||||
|
|
||||||
DEPENDS = ['apps']
|
depends = ['plinth.modules.apps']
|
||||||
|
|||||||
@ -24,4 +24,4 @@ from .tor import init
|
|||||||
|
|
||||||
__all__ = ['tor', 'init']
|
__all__ = ['tor', 'init']
|
||||||
|
|
||||||
DEPENDS = ['apps']
|
depends = ['plinth.modules.apps']
|
||||||
|
|||||||
@ -24,4 +24,4 @@ from .users import init
|
|||||||
|
|
||||||
__all__ = ['users', 'init']
|
__all__ = ['users', 'init']
|
||||||
|
|
||||||
DEPENDS = ['system']
|
depends = ['plinth.modules.system']
|
||||||
|
|||||||
@ -24,4 +24,4 @@ from .xmpp import init
|
|||||||
|
|
||||||
__all__ = ['xmpp', 'init']
|
__all__ = ['xmpp', 'init']
|
||||||
|
|
||||||
DEPENDS = ['apps']
|
depends = ['plinth.modules.apps']
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user