From b747d9411ac346835c4a38dbe3997c72c0e78137 Mon Sep 17 00:00:00 2001 From: fabios Date: Sat, 27 Dec 2014 21:19:00 -0500 Subject: [PATCH] improve fail message and use itertools chain --- packaging/os/apt.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packaging/os/apt.py b/packaging/os/apt.py index d1101bc7b8b..77f1e431b2f 100644 --- a/packaging/os/apt.py +++ b/packaging/os/apt.py @@ -144,6 +144,7 @@ warnings.filterwarnings('ignore', "apt API not stable yet", FutureWarning) import os import datetime import fnmatch +import itertools # APT related constants APT_ENV_VARS = dict( @@ -180,9 +181,8 @@ def package_versions(pkgname, pkg, pkg_cache): # assume older version of python-apt is installed # 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_list_of_lists = (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 pkg_versions) + pkg_versions = (p.VersionList for p in pkg_cache_list) + versions = set(p.VerStr for p in itertools.chain(*pkg_versions)) return versions @@ -205,10 +205,10 @@ def package_status(m, pkgname, version, cache, state): try: if cache.get_providing_packages(pkgname): return False, True, False + m.fail_json(msg="No package matching '%s' is available" % pkgname) except AttributeError: - # older python-apt providing packages cannot be used - pass - m.fail_json(msg="No package matching '%s' is available" % pkgname) + # python-apt version too old to detect virtual packages + m.fail_json(msg="No package matching '%s' is available (python-apt version too old to detect virtual packages)" % pkgname) else: return False, False, False try: