summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToshio Kuratomi <toshio@fedoraproject.org>2014-11-13 11:20:37 -0800
committerToshio Kuratomi <toshio@fedoraproject.org>2014-11-14 07:45:56 -0800
commitbc18c9dc782969fecd0d1d5bf71eeadddd4da1b2 (patch)
tree67218a056c2a3c4ae8895614263872e6a382a106
parent10fd0f7073959d7fc166a1b3ae58f9c634ecf936 (diff)
downloadansible-modules-core-bc18c9dc782969fecd0d1d5bf71eeadddd4da1b2.tar.gz
Cache pkg name list so we don't recreate the list for every package
-rw-r--r--packaging/os/apt.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/packaging/os/apt.py b/packaging/os/apt.py
index 5e02016e..7940317e 100644
--- a/packaging/os/apt.py
+++ b/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