mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-03-18 09:10:49 +00:00
package: Run installation operation using app_id instead of module
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
fee21cba0d
commit
c6b69b2f41
@ -5,21 +5,19 @@ Wrapper to handle package installation with apt-get.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import inspect
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
from collections import defaultdict
|
||||
from importlib import import_module
|
||||
|
||||
import apt.cache
|
||||
import apt_inst
|
||||
import apt_pkg
|
||||
|
||||
from plinth import app as app_module
|
||||
from plinth import cfg
|
||||
from plinth import module_loader
|
||||
from plinth.action_utils import (apt_hold_freedombox, is_package_manager_busy,
|
||||
run_apt_command)
|
||||
from plinth.package import Packages
|
||||
@ -48,7 +46,7 @@ def parse_arguments():
|
||||
'--force-missing-configuration', action='store_true',
|
||||
help='force installation of missing configuration files')
|
||||
subparser.add_argument(
|
||||
'module', help='name of module for which package is being installed')
|
||||
'app_id', help='ID of app for which package is being installed')
|
||||
subparser.add_argument('packages', nargs='+',
|
||||
help='list of packages to install')
|
||||
|
||||
@ -76,7 +74,7 @@ def subcommand_update(arguments):
|
||||
def subcommand_install(arguments):
|
||||
"""Install packages using apt-get."""
|
||||
try:
|
||||
_assert_managed_packages(arguments.module, arguments.packages)
|
||||
_assert_managed_packages(arguments.app_id, arguments.packages)
|
||||
except Exception as exception:
|
||||
print('Access check failed:', exception, file=sys.stderr)
|
||||
sys.exit(99)
|
||||
@ -113,25 +111,14 @@ def subcommand_remove(arguments):
|
||||
sys.exit(run_apt_command(['remove'] + arguments.packages))
|
||||
|
||||
|
||||
def _assert_managed_packages(module, packages):
|
||||
def _assert_managed_packages(app_id, packages):
|
||||
"""Check that list of packages are in fact managed by module."""
|
||||
cfg.read()
|
||||
module_file = os.path.join(cfg.config_dir, 'modules-enabled', module)
|
||||
|
||||
with open(module_file, 'r', encoding='utf-8') as file_handle:
|
||||
module_path = file_handle.read().strip()
|
||||
|
||||
module = import_module(module_path)
|
||||
module_classes = inspect.getmembers(module, inspect.isclass)
|
||||
app_classes = [
|
||||
cls[1] for cls in module_classes if issubclass(cls[1], app_module.App)
|
||||
]
|
||||
module_loader.load_modules()
|
||||
app_module.apps_init()
|
||||
app = app_module.App.get(app_id)
|
||||
managed_packages = []
|
||||
for cls in app_classes:
|
||||
app = cls()
|
||||
components = app.get_components_of_type(Packages)
|
||||
for component in components:
|
||||
managed_packages += component.possible_packages
|
||||
for component in app.get_components_of_type(Packages):
|
||||
managed_packages += component.possible_packages
|
||||
|
||||
for package in packages:
|
||||
assert package in managed_packages
|
||||
|
||||
@ -255,12 +255,12 @@ class PackageException(Exception):
|
||||
class Transaction:
|
||||
"""Information about an ongoing transaction."""
|
||||
|
||||
def __init__(self, module_name, package_names):
|
||||
def __init__(self, app_id, package_names):
|
||||
"""Initialize transaction object.
|
||||
|
||||
Set most values to None until they are sent as progress update.
|
||||
"""
|
||||
self.module_name = module_name
|
||||
self.app_id = app_id
|
||||
self.package_names = package_names
|
||||
|
||||
self._reset_status()
|
||||
@ -320,7 +320,7 @@ class Transaction:
|
||||
extra_arguments.append('--force-missing-configuration')
|
||||
|
||||
self._run_apt_command(['install'] + extra_arguments +
|
||||
[self.module_name] + self.package_names)
|
||||
[self.app_id] + self.package_names)
|
||||
except subprocess.CalledProcessError as exception:
|
||||
logger.exception('Error installing package: %s', exception)
|
||||
raise
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user