mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
improve fail message and use itertools chain
This commit is contained in:
parent
21bfa80203
commit
043242df2c
1 changed files with 6 additions and 6 deletions
|
@ -144,6 +144,7 @@ warnings.filterwarnings('ignore', "apt API not stable yet", FutureWarning)
|
||||||
import os
|
import os
|
||||||
import datetime
|
import datetime
|
||||||
import fnmatch
|
import fnmatch
|
||||||
|
import itertools
|
||||||
|
|
||||||
# APT related constants
|
# APT related constants
|
||||||
APT_ENV_VARS = dict(
|
APT_ENV_VARS = dict(
|
||||||
|
@ -180,9 +181,8 @@ def package_versions(pkgname, pkg, pkg_cache):
|
||||||
# assume older version of python-apt is installed
|
# assume older version of python-apt is installed
|
||||||
# apt.package.Package#versions require python-apt >= 0.7.9.
|
# apt.package.Package#versions require python-apt >= 0.7.9.
|
||||||
pkg_cache_list = (p for p in pkg_cache.Packages if p.Name == pkgname)
|
pkg_cache_list = (p for p in pkg_cache.Packages if p.Name == pkgname)
|
||||||
pkg_list_of_lists = (p.VersionList for p in pkg_cache_list)
|
pkg_versions = (p.VersionList for p in pkg_cache_list)
|
||||||
pkg_versions = (p for l in pkg_list_of_lists for p in l)
|
versions = set(p.VerStr for p in itertools.chain(*pkg_versions))
|
||||||
versions = set(p.VerStr for p in pkg_versions)
|
|
||||||
|
|
||||||
return versions
|
return versions
|
||||||
|
|
||||||
|
@ -205,10 +205,10 @@ def package_status(m, pkgname, version, cache, state):
|
||||||
try:
|
try:
|
||||||
if cache.get_providing_packages(pkgname):
|
if cache.get_providing_packages(pkgname):
|
||||||
return False, True, False
|
return False, True, False
|
||||||
|
m.fail_json(msg="No package matching '%s' is available" % pkgname)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
# older python-apt providing packages cannot be used
|
# python-apt version too old to detect virtual packages
|
||||||
pass
|
m.fail_json(msg="No package matching '%s' is available (python-apt version too old to detect virtual packages)" % pkgname)
|
||||||
m.fail_json(msg="No package matching '%s' is available" % pkgname)
|
|
||||||
else:
|
else:
|
||||||
return False, False, False
|
return False, False, False
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in a new issue