mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-08-26 12:46:08 +00:00
setup: Run setup on apps instead of modules
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
f2af08d8a6
commit
a0a6e1d362
@ -31,9 +31,8 @@ def parse_arguments():
|
|||||||
'--develop', action='store_true', default=None,
|
'--develop', action='store_true', default=None,
|
||||||
help=('run Plinth *insecurely* from current folder; '
|
help=('run Plinth *insecurely* from current folder; '
|
||||||
'enable auto-reloading and debugging options'))
|
'enable auto-reloading and debugging options'))
|
||||||
parser.add_argument(
|
parser.add_argument('--setup', default=False, nargs='*',
|
||||||
'--setup', default=False, nargs='*',
|
help='run setup tasks on all essential apps and exit')
|
||||||
help='run setup tasks on all essential modules and exit')
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--setup-no-install', default=False, nargs='*',
|
'--setup-no-install', default=False, nargs='*',
|
||||||
help='run setup tasks without installing packages and exit')
|
help='run setup tasks without installing packages and exit')
|
||||||
@ -45,11 +44,11 @@ def parse_arguments():
|
|||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
def run_setup_and_exit(module_list, allow_install=True):
|
def run_setup_and_exit(app_ids, allow_install=True):
|
||||||
"""Run setup on all essential modules and exit."""
|
"""Run setup on all essential apps and exit."""
|
||||||
error_code = 0
|
error_code = 0
|
||||||
try:
|
try:
|
||||||
setup.run_setup_on_modules(module_list, allow_install)
|
setup.run_setup_on_apps(app_ids, allow_install)
|
||||||
except Exception:
|
except Exception:
|
||||||
error_code = 1
|
error_code = 1
|
||||||
|
|
||||||
|
|||||||
@ -173,14 +173,14 @@ def _install_apps_before_restore(components):
|
|||||||
data getting backed up into older version of the app.
|
data getting backed up into older version of the app.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
modules_to_setup = []
|
apps_to_setup = []
|
||||||
for component in components:
|
for component in components:
|
||||||
if component.app.get_setup_state() in (
|
if component.app.get_setup_state() in (
|
||||||
app_module.App.SetupState.NEEDS_SETUP,
|
app_module.App.SetupState.NEEDS_SETUP,
|
||||||
app_module.App.SetupState.NEEDS_UPDATE):
|
app_module.App.SetupState.NEEDS_UPDATE):
|
||||||
modules_to_setup.append(component.app.app_id)
|
apps_to_setup.append(component.app.app_id)
|
||||||
|
|
||||||
setup.run_setup_on_modules(modules_to_setup)
|
setup.run_setup_on_apps(apps_to_setup)
|
||||||
|
|
||||||
|
|
||||||
def _get_backup_restore_component(app):
|
def _get_backup_restore_component(app):
|
||||||
|
|||||||
@ -5,6 +5,7 @@ Utilities for performing application setup operations.
|
|||||||
|
|
||||||
import importlib
|
import importlib
|
||||||
import logging
|
import logging
|
||||||
|
import sys
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
@ -139,18 +140,19 @@ def stop():
|
|||||||
_force_upgrader.shutdown()
|
_force_upgrader.shutdown()
|
||||||
|
|
||||||
|
|
||||||
def setup_modules(module_list=None, essential=False, allow_install=True):
|
def setup_apps(app_ids=None, essential=False, allow_install=True):
|
||||||
"""Run setup on selected or essential modules."""
|
"""Run setup on selected or essential apps."""
|
||||||
logger.info(
|
logger.info(
|
||||||
'Running setup for modules, essential - %s, '
|
'Running setup for apps, essential - %s, '
|
||||||
'selected modules - %s', essential, module_list)
|
'selected apps - %s', essential, app_ids)
|
||||||
for module_name, module in plinth.module_loader.loaded_modules.items():
|
for app in app_module.App.list():
|
||||||
if essential and not module.app.info.is_essential:
|
if essential and not app.info.is_essential:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if module_list and module_name not in module_list:
|
if app_ids and app.app_id not in app_ids:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
module = sys.modules[app.__module__]
|
||||||
module.setup_helper.run(allow_install=allow_install)
|
module.setup_helper.run(allow_install=allow_install)
|
||||||
|
|
||||||
|
|
||||||
@ -201,43 +203,43 @@ def _run_setup():
|
|||||||
|
|
||||||
|
|
||||||
def _run_first_setup():
|
def _run_first_setup():
|
||||||
"""Run setup on essential modules on first setup."""
|
"""Run setup on essential apps on first setup."""
|
||||||
global is_first_setup_running
|
global is_first_setup_running
|
||||||
is_first_setup_running = True
|
is_first_setup_running = True
|
||||||
# TODO When it errors out, show error in the UI
|
# TODO When it errors out, show error in the UI
|
||||||
run_setup_on_modules(None, allow_install=False)
|
run_setup_on_apps(None, allow_install=False)
|
||||||
is_first_setup_running = False
|
is_first_setup_running = False
|
||||||
|
|
||||||
|
|
||||||
def _run_regular_setup():
|
def _run_regular_setup():
|
||||||
"""Run setup on all modules also installing required packages."""
|
"""Run setup on all apps also installing required packages."""
|
||||||
# TODO show notification that upgrades are running
|
# TODO show notification that upgrades are running
|
||||||
if package.is_package_manager_busy():
|
if package.is_package_manager_busy():
|
||||||
raise Exception('Package manager is busy.')
|
raise Exception('Package manager is busy.')
|
||||||
|
|
||||||
all_modules = _get_modules_for_regular_setup()
|
app_ids = _get_apps_for_regular_setup()
|
||||||
run_setup_on_modules(all_modules, allow_install=True)
|
run_setup_on_apps(app_ids, allow_install=True)
|
||||||
|
|
||||||
|
|
||||||
def _get_modules_for_regular_setup():
|
def _get_apps_for_regular_setup():
|
||||||
all_modules = plinth.module_loader.loaded_modules.items()
|
|
||||||
|
|
||||||
def is_setup_required(module):
|
def is_setup_required(app):
|
||||||
"""Setup is required for:
|
"""Setup is required for:
|
||||||
1. essential modules that are not up-to-date
|
1. essential apps that are not up-to-date
|
||||||
2. non-essential modules that are installed and need updates
|
2. non-essential app that are installed and need updates
|
||||||
"""
|
"""
|
||||||
if (module.app.info.is_essential and module.app.get_setup_state() !=
|
if (app.info.is_essential and
|
||||||
app_module.App.SetupState.UP_TO_DATE):
|
app.get_setup_state() != app_module.App.SetupState.UP_TO_DATE):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if (module.app.get_setup_state() ==
|
if app.get_setup_state() == app_module.App.SetupState.NEEDS_UPDATE:
|
||||||
app_module.App.SetupState.NEEDS_UPDATE):
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return [name for name, module in all_modules if is_setup_required(module)]
|
return [
|
||||||
|
app.app_id for app in app_module.App.list() if is_setup_required(app)
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def _set_is_first_setup():
|
def _set_is_first_setup():
|
||||||
@ -249,22 +251,22 @@ def _set_is_first_setup():
|
|||||||
if module.app.info.is_essential and module.app.needs_setup()))
|
if module.app.info.is_essential and module.app.needs_setup()))
|
||||||
|
|
||||||
|
|
||||||
def run_setup_on_modules(module_list, allow_install=True):
|
def run_setup_on_apps(app_ids, allow_install=True):
|
||||||
"""Run setup on the given list of modules.
|
"""Run setup on the given list of apps.
|
||||||
|
|
||||||
module_list is the list of modules to run setup on. If None is given, run
|
apps is the list of apps to run setup on. If None is given, run setup on
|
||||||
setup on all essential modules only.
|
all essential apps only.
|
||||||
|
|
||||||
allow_install with or without package installation. When setting up
|
allow_install with or without package installation. When setting up
|
||||||
essential modules, installing packages is not required as FreedomBox
|
essential apps, installing packages is not required as FreedomBox
|
||||||
(Plinth) itself has dependencies on all essential modules.
|
(Plinth) itself has dependencies on all essential apps.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
if not module_list:
|
if not app_ids:
|
||||||
setup_modules(essential=True, allow_install=allow_install)
|
setup_apps(essential=True, allow_install=allow_install)
|
||||||
else:
|
else:
|
||||||
setup_modules(module_list, allow_install=allow_install)
|
setup_apps(app_ids, allow_install=allow_install)
|
||||||
except Exception as exception:
|
except Exception as exception:
|
||||||
logger.error('Error running setup - %s', exception)
|
logger.error('Error running setup - %s', exception)
|
||||||
raise
|
raise
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user