From 647139f17ee165dbd141fd11b59f97334dc4d2d9 Mon Sep 17 00:00:00 2001 From: Joseph Nuthalapati Date: Tue, 25 Sep 2018 19:01:35 +0530 Subject: [PATCH] Don't disable installation when apt lists are empty We are wrongly showing a warning message and disabling the install button on the setup page on newly spun up AWS cloud images. This is a false positive since the applications might be available in Debian but the apt caches are not updated. Taking care of this issue as well. The function returns None and not False to distinguish this as a case different from returning a result about whether the package is unavailable or not. Signed-off-by: Joseph Nuthalapati Reviewed-by: James Valleroy --- plinth/setup.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/plinth/setup.py b/plinth/setup.py index 69002066c..e633e2761 100644 --- a/plinth/setup.py +++ b/plinth/setup.py @@ -19,6 +19,7 @@ Utilities for performing application setup operations. """ import logging +import os import threading import time @@ -166,7 +167,19 @@ class Helper(object): pk=self.module_name, defaults={'setup_version': version}) def has_unavailable_packages(self): - """List the unavailable packages managed by the module (if any).""" + """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 + packages are available or not. + """ + APT_LISTS_DIR = '/var/lib/apt/lists/' + num_files = len([ + name for name in os.listdir(APT_LISTS_DIR) + if os.path.isfile(os.path.join(APT_LISTS_DIR, name)) + ]) + if num_files < 2: # not counting the lock file + return None cache = apt.Cache() managed_pkgs = getattr(self.module, 'managed_packages', []) unavailable_pkgs = (pkg_name for pkg_name in managed_pkgs @@ -188,8 +201,9 @@ def stop(): def setup_modules(module_list=None, essential=False, allow_install=True): """Run setup on selected or essential modules.""" - logger.info('Running setup for modules, essential - %s, ' - 'selected modules - %s', essential, module_list) + logger.info( + 'Running setup for modules, essential - %s, ' + 'selected modules - %s', essential, module_list) for module_name, module in plinth.module_loader.loaded_modules.items(): if essential and not _is_module_essential(module): continue