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 <njoseph@thoughtworks.com>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Joseph Nuthalapati 2018-09-25 19:01:35 +05:30 committed by James Valleroy
parent df7774a24b
commit 647139f17e
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808

View File

@ -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