Merge pull request #35207 from eliasp/2016.3-modules.aptpkg-handle-exceptions

Handle exceptions in `_get_virtual()` and in `_get_virtual()` consumers
This commit is contained in:
Mike Place 2016-08-06 17:29:08 +09:00 committed by GitHub
commit 100645e557

View file

@ -171,7 +171,12 @@ def _get_virtual():
except KeyError:
__context__['pkg._get_virtual'] = {}
if HAS_APT:
apt_cache = apt.cache.Cache()
try:
apt_cache = apt.cache.Cache()
except SystemError as se:
msg = 'Failed to get virtual package information ({0})'.format(se)
log.error(msg)
raise CommandExecutionError(msg)
pkgs = getattr(apt_cache._cache, 'packages', [])
for pkg in pkgs:
for item in getattr(pkg, 'provides_list', []):
@ -249,7 +254,10 @@ def latest_version(*names, **kwargs):
if refresh:
refresh_db()
virtpkgs = _get_virtual()
try:
virtpkgs = _get_virtual()
except CommandExecutionError as cee:
raise CommandExecutionError(cee)
all_virt = set()
for provides in six.itervalues(virtpkgs):
all_virt.update(provides)
@ -1179,7 +1187,10 @@ def list_pkgs(versions_as_list=False,
# Check for virtual packages. We need dctrl-tools for this.
if not removed:
virtpkgs_all = _get_virtual()
try:
virtpkgs_all = _get_virtual()
except CommandExecutionError as cee:
raise CommandExecutionError(cee)
virtpkgs = set()
for realpkg, provides in six.iteritems(virtpkgs_all):
# grep-available returns info on all virtual packages. Ignore any