mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-13 10:30:16 +00:00
setup: Prioritize FirstSetupMiddle over some others
- Minor PEP8 fixes. - Add doc strings. - Make a few methods private. - Remove unused global declarations. - Remove unused imports. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
parent
7ce56864e9
commit
1247f2ef93
@ -156,7 +156,7 @@ def setup_server():
|
|||||||
|
|
||||||
|
|
||||||
def on_server_stop():
|
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()
|
setup.stop()
|
||||||
|
|
||||||
|
|
||||||
@ -262,9 +262,9 @@ def configure_django():
|
|||||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||||
'stronghold.middleware.LoginRequiredMiddleware',
|
'stronghold.middleware.LoginRequiredMiddleware',
|
||||||
'plinth.middleware.AdminRequiredMiddleware',
|
'plinth.middleware.AdminRequiredMiddleware',
|
||||||
|
'plinth.middleware.FirstSetupMiddleware',
|
||||||
'plinth.modules.first_boot.middleware.FirstBootMiddleware',
|
'plinth.modules.first_boot.middleware.FirstBootMiddleware',
|
||||||
'plinth.middleware.SetupMiddleware',
|
'plinth.middleware.SetupMiddleware',
|
||||||
'plinth.middleware.FirstSetupMiddleware',
|
|
||||||
),
|
),
|
||||||
ROOT_URLCONF='plinth.urls',
|
ROOT_URLCONF='plinth.urls',
|
||||||
SECURE_PROXY_SSL_HEADER=secure_proxy_ssl_header,
|
SECURE_PROXY_SSL_HEADER=secure_proxy_ssl_header,
|
||||||
|
|||||||
@ -107,6 +107,7 @@ class AdminRequiredMiddleware(object):
|
|||||||
|
|
||||||
|
|
||||||
class FirstSetupMiddleware(object):
|
class FirstSetupMiddleware(object):
|
||||||
|
"""Django middleware to block all interactions before first setup."""
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def process_view(request, view_func, view_args, view_kwargs):
|
def process_view(request, view_func, view_args, view_kwargs):
|
||||||
|
|||||||
@ -140,4 +140,3 @@ def is_package_manager_busy():
|
|||||||
return True
|
return True
|
||||||
except actions.ActionError:
|
except actions.ActionError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|||||||
@ -26,8 +26,6 @@ import time
|
|||||||
from . import package
|
from . import package
|
||||||
from .errors import PackageNotInstalledError
|
from .errors import PackageNotInstalledError
|
||||||
import plinth
|
import plinth
|
||||||
from plinth import actions
|
|
||||||
from plinth import package
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
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, '
|
logger.info('Running setup for modules, essential - %s, '
|
||||||
'selected modules - %s', essential, module_list)
|
'selected modules - %s', essential, module_list)
|
||||||
for module_name, module in plinth.module_loader.loaded_modules.items():
|
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
|
continue
|
||||||
|
|
||||||
if module_list and module_name not in module_list:
|
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):
|
def list_dependencies(module_list=None, essential=False):
|
||||||
"""Print list of packages required by selected or essential modules."""
|
"""Print list of packages required by selected or essential modules."""
|
||||||
for module_name, module in plinth.module_loader.loaded_modules.items():
|
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
|
continue
|
||||||
|
|
||||||
if module_list and module_name not in module_list and \
|
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():
|
def run_setup_in_background():
|
||||||
"""Run setup in a background thread."""
|
"""Run setup in a background thread."""
|
||||||
global _is_first_setup
|
|
||||||
_set_is_first_setup()
|
_set_is_first_setup()
|
||||||
threading.Thread(target=_run_setup).start()
|
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
|
1. essential modules that are not up-to-date
|
||||||
2. non-essential modules that are installed and need updates
|
2. non-essential modules that are installed and need updates
|
||||||
"""
|
"""
|
||||||
if (is_module_essential(module) and
|
if _is_module_essential(module) and \
|
||||||
not module_state_matches(module, 'up-to-date')):
|
not _module_state_matches(module, 'up-to-date'):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if module_state_matches(module, 'needs-update'):
|
if _module_state_matches(module, 'needs-update'):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
@ -274,22 +271,25 @@ def _get_modules_for_regular_setup():
|
|||||||
if is_setup_required(module)]
|
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)
|
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
|
return module.setup_helper.get_state() == state
|
||||||
|
|
||||||
|
|
||||||
def _set_is_first_setup():
|
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
|
global _is_first_setup
|
||||||
modules = plinth.module_loader.loaded_modules.values()
|
modules = plinth.module_loader.loaded_modules.values()
|
||||||
_is_first_setup = any(
|
_is_first_setup = any(
|
||||||
(module
|
(module
|
||||||
for module in modules
|
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):
|
def run_setup_on_modules(module_list, allow_install=True):
|
||||||
|
|||||||
@ -42,4 +42,3 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|||||||
@ -30,7 +30,6 @@ import time
|
|||||||
|
|
||||||
from . import forms, frontpage
|
from . import forms, frontpage
|
||||||
import plinth
|
import plinth
|
||||||
from plinth import actions
|
|
||||||
from plinth import package
|
from plinth import package
|
||||||
from plinth.modules.storage import views as disk_views
|
from plinth.modules.storage import views as disk_views
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user