From cea023f7b2cc5b44e2ef8f76d07912d20f6576f0 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Tue, 16 Nov 2021 08:14:33 -0800 Subject: [PATCH] actions: Get list of packages from Packages components Instead of getting it from managed_packages module level variable. This is made possible by the ability to instantiate an app without being able to instantiate all apps at once and without even initializing Django. Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- actions/packages | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/actions/packages b/actions/packages index 24517a3cd..996450141 100755 --- a/actions/packages +++ b/actions/packages @@ -5,6 +5,7 @@ Wrapper to handle package installation with apt-get. """ import argparse +import inspect import json import logging import os @@ -17,9 +18,11 @@ import apt.cache import apt_inst import apt_pkg +from plinth import app as app_module from plinth import cfg from plinth.action_utils import (apt_hold_freedombox, is_package_manager_busy, run_apt_command) +from plinth.package import Packages logger = logging.getLogger(__name__) @@ -119,8 +122,19 @@ def _assert_managed_packages(module, packages): 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) + ] + managed_packages = [] + for cls in app_classes: + app = cls() + components = app.get_components_of_type(Packages) + for component in components: + managed_packages += component.packages + for package in packages: - assert package in module.managed_packages + assert package in managed_packages def subcommand_is_package_manager_busy(_):