From 6e68614e213aa34f84ce7070925e54bc234b46c6 Mon Sep 17 00:00:00 2001 From: Joseph Nuthalapati Date: Fri, 29 Oct 2021 16:12:50 +0530 Subject: [PATCH] setup: Use packages from Packages component Signed-off-by: Joseph Nuthalapati [sunil: Minor refactor in listing unavailable packages, add code comment] [sunil: Fix listing dependencies by initializing modules before call] Signed-off-by: Sunil Mohan Adapa Reviewed-by: Sunil Mohan Adapa --- plinth/__main__.py | 3 +++ plinth/package.py | 8 +++++++- plinth/setup.py | 30 +++++++++++++++++------------- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/plinth/__main__.py b/plinth/__main__.py index 171bcd36c..bdb7041bc 100644 --- a/plinth/__main__.py +++ b/plinth/__main__.py @@ -109,6 +109,9 @@ def main(): if arguments.list_dependencies is not False: log.default_level = 'ERROR' web_framework.init(read_only=True) + module_loader.include_urls() + menu.init() + module_loader.load_modules() list_dependencies(arguments.list_dependencies) log.init() diff --git a/plinth/package.py b/plinth/package.py index 496e52d2d..c24f2ac1a 100644 --- a/plinth/package.py +++ b/plinth/package.py @@ -24,8 +24,14 @@ class Packages(app.FollowerComponent): """Component to manage the packages of an app.""" def __init__(self, component_id, packages): + super(Packages, self).__init__(component_id) + self.component_id = component_id - self.packages = packages + self._packages = packages + + @property + def packages(self): + return self._packages class PackageException(Exception): diff --git a/plinth/setup.py b/plinth/setup.py index 8189f6199..9e3d23dd1 100644 --- a/plinth/setup.py +++ b/plinth/setup.py @@ -13,7 +13,7 @@ from collections import defaultdict import apt import plinth -from plinth.package import packages_installed +from plinth.package import Packages, packages_installed from plinth.signals import post_setup from . import package @@ -161,6 +161,7 @@ class Helper(object): def has_unavailable_packages(self): """Find if any of the packages managed by the module are not available. + Returns True if one or more of the packages is not available in the user's Debian distribution or False otherwise. Returns None if it cannot be reliably determined whether the @@ -173,8 +174,15 @@ class Helper(object): ]) if num_files < 2: # not counting the lock file return None + + pkg_components = list(self.module.app.get_components_of_type(Packages)) + if not pkg_components: # This app has no packages to install + return False + + # List of all packages from all Package components + managed_pkgs = (package for component in pkg_components + for package in component.packages) cache = apt.Cache() - managed_pkgs = _get_module_managed_packages(self.module) unavailable_pkgs = (pkg_name for pkg_name in managed_pkgs if pkg_name not in cache) return any(unavailable_pkgs) @@ -231,8 +239,9 @@ def list_dependencies(module_list=None, essential=False): '*' not in module_list: continue - for package_name in _get_module_managed_packages(module): - print(package_name) + for component in module.app.get_components_of_type(Packages): + for package_name in component.packages: + print(package_name) def run_setup_in_background(): @@ -314,11 +323,6 @@ def _get_module_package_conflicts(module): None), getattr(module, 'package_conflicts_action', None)) -def _get_module_managed_packages(module): - """Return list of packages managed by a module.""" - return getattr(module, 'managed_packages', []) - - 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 @@ -582,11 +586,11 @@ class ForceUpgrader(): # Or needs an update, let it update first. continue - managed_packages = _get_module_managed_packages(module) - upgradable_packages.update(managed_packages) + for component in module.app.get_components_of_type(Packages): + upgradable_packages.update(component.packages) - for managed_package in managed_packages: - package_apps_map[managed_package].add(module) + for managed_package in component.packages: + package_apps_map[managed_package].add(module) return upgradable_packages.intersection( set(packages)), package_apps_map