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:
Sunil Mohan Adapa authored and James Valleroy committed 2022-08-15 10:36:10 -04:00
1 parent fee21cba0d
commit c6b69b2f41
2 files changed
+12 -25

No files matched your search

+9 -22
View File
@@ -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