diff --git a/plinth/__main__.py b/plinth/__main__.py index 36a998b79..684444729 100644 --- a/plinth/__main__.py +++ b/plinth/__main__.py @@ -156,7 +156,7 @@ def setup_server(): def on_server_stop(): - """Stop all other threads since web server is trying to exit""" + """Stop all other threads since web server is trying to exit.""" setup.stop() @@ -262,9 +262,9 @@ def configure_django(): 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'stronghold.middleware.LoginRequiredMiddleware', 'plinth.middleware.AdminRequiredMiddleware', + 'plinth.middleware.FirstSetupMiddleware', 'plinth.modules.first_boot.middleware.FirstBootMiddleware', 'plinth.middleware.SetupMiddleware', - 'plinth.middleware.FirstSetupMiddleware', ), ROOT_URLCONF='plinth.urls', SECURE_PROXY_SSL_HEADER=secure_proxy_ssl_header, diff --git a/plinth/middleware.py b/plinth/middleware.py index 4d4575da8..b35bb432e 100644 --- a/plinth/middleware.py +++ b/plinth/middleware.py @@ -107,6 +107,7 @@ class AdminRequiredMiddleware(object): class FirstSetupMiddleware(object): + """Django middleware to block all interactions before first setup.""" @staticmethod def process_view(request, view_func, view_args, view_kwargs): diff --git a/plinth/package.py b/plinth/package.py index 7419106ef..c195117b2 100644 --- a/plinth/package.py +++ b/plinth/package.py @@ -140,4 +140,3 @@ def is_package_manager_busy(): return True except actions.ActionError: return False - diff --git a/plinth/setup.py b/plinth/setup.py index 484b9a435..fa8862d41 100644 --- a/plinth/setup.py +++ b/plinth/setup.py @@ -26,8 +26,6 @@ import time from . import package from .errors import PackageNotInstalledError import plinth -from plinth import actions -from plinth import package logger = logging.getLogger(__name__) @@ -180,7 +178,7 @@ def setup_modules(module_list=None, essential=False, allow_install=True): logger.info('Running setup for modules, essential - %s, ' 'selected modules - %s', essential, module_list) for module_name, module in plinth.module_loader.loaded_modules.items(): - if essential and not is_module_essential(module): + if essential and not _is_module_essential(module): continue if module_list and module_name not in module_list: @@ -192,7 +190,7 @@ def setup_modules(module_list=None, essential=False, allow_install=True): def list_dependencies(module_list=None, essential=False): """Print list of packages required by selected or essential modules.""" for module_name, module in plinth.module_loader.loaded_modules.items(): - if essential and not is_module_essential(module): + if essential and not _is_module_essential(module): continue if module_list and module_name not in module_list and \ @@ -205,7 +203,6 @@ def list_dependencies(module_list=None, essential=False): def run_setup_in_background(): """Run setup in a background thread.""" - global _is_first_setup _set_is_first_setup() threading.Thread(target=_run_setup).start() @@ -260,11 +257,11 @@ def _get_modules_for_regular_setup(): 1. essential modules that are not up-to-date 2. non-essential modules that are installed and need updates """ - if (is_module_essential(module) and - not module_state_matches(module, 'up-to-date')): + if _is_module_essential(module) and \ + not _module_state_matches(module, 'up-to-date'): return True - if module_state_matches(module, 'needs-update'): + if _module_state_matches(module, 'needs-update'): return True return False @@ -274,22 +271,25 @@ def _get_modules_for_regular_setup(): if is_setup_required(module)] -def is_module_essential(module): +def _is_module_essential(module): + """Return if a module is an essential module.""" return getattr(module, 'is_essential', False) -def module_state_matches(module, state): +def _module_state_matches(module, state): + """Return if the current setup state of a module matches given state.""" return module.setup_helper.get_state() == state def _set_is_first_setup(): - """Return whether all essential modules have been setup at least once.""" + """Set whether all essential modules have been setup at least once.""" global _is_first_setup modules = plinth.module_loader.loaded_modules.values() _is_first_setup = any( (module for module in modules - if is_module_essential(module) and module_state_matches(module, 'needs-setup'))) + if _is_module_essential(module) and + _module_state_matches(module, 'needs-setup'))) def run_setup_on_modules(module_list, allow_install=True): diff --git a/plinth/templates/first_setup.html b/plinth/templates/first_setup.html index df63e0417..74e94c760 100644 --- a/plinth/templates/first_setup.html +++ b/plinth/templates/first_setup.html @@ -42,4 +42,3 @@ {% endif %} {% endblock %} - diff --git a/plinth/views.py b/plinth/views.py index 66f5c64f4..8dcc1d6a3 100644 --- a/plinth/views.py +++ b/plinth/views.py @@ -30,7 +30,6 @@ import time from . import forms, frontpage import plinth -from plinth import actions from plinth import package from plinth.modules.storage import views as disk_views