From 37fa22eb93a32388a3e9582c26ecfa9fee3e88a1 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Thu, 13 Nov 2014 11:20:37 -0800 Subject: [PATCH] Cache pkg name list so we don't recreate the list for every package --- lib/ansible/modules/packaging/os/apt.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/ansible/modules/packaging/os/apt.py b/lib/ansible/modules/packaging/os/apt.py index 5e02016ecac..7940317eb78 100644 --- a/lib/ansible/modules/packaging/os/apt.py +++ b/lib/ansible/modules/packaging/os/apt.py @@ -235,21 +235,27 @@ def expand_pkgspec_from_fnmatches(m, pkgspec, cache): if frozenset('*?[]!').intersection(pkgname_pattern): if version: m.fail_json(msg="pkgname wildcard and version can not be mixed") + # handle multiarch pkgnames, the idea is that "apt*" should # only select native packages. But "apt*:i386" should still work if not ":" in pkgname_pattern: - matches = fnmatch.filter( - [pkg.name for pkg in cache - if not ":" in pkg.name], pkgname_pattern) + try: + pkg_name_cache = _non_multiarch + except NameError: + pkg_name_cache = _non_multiarch = [pkg.name for pkg in cache if not ':' in pkg.name] else: - matches = fnmatch.filter( - [pkg.name for pkg in cache], pkgname_pattern) + try: + pkg_name_cache = _all_pkg_names + except NameError: + pkg_name_cache = _all_pkg_names = [pkg.name for pkg in cache] + matches = fnmatch.filter(pkg_name_cache, pkgname_pattern) if len(matches) == 0: m.fail_json(msg="No package(s) matching '%s' available" % str(pkgname_pattern)) else: new_pkgspec.extend(matches) else: + # No wildcards in name new_pkgspec.append(pkgspec_pattern) return new_pkgspec