setup: Abstraction for getting managing packages of a 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 2019-02-22 16:10:53 -08:00 committed by James Valleroy
parent 2df02b059c
commit d042026314
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808

View File

@ -184,7 +184,7 @@ class Helper(object):
if num_files < 2: # not counting the lock file
return None
cache = apt.Cache()
managed_pkgs = getattr(self.module, 'managed_packages', [])
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)
@ -227,7 +227,7 @@ def list_dependencies(module_list=None, essential=False):
'*' not in module_list:
continue
for package_name in getattr(module, 'managed_packages', []):
for package_name in _get_module_managed_packages(module):
print(package_name)
@ -304,6 +304,11 @@ def _is_module_essential(module):
return getattr(module, 'is_essential', False)
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