Just make things a little more readable

pull/18777/head
Toshio Kuratomi 10 years ago committed by Matt Clay
parent f2c1d49de7
commit 6b776da7bc

@ -167,7 +167,7 @@ except ImportError:
HAS_PYTHON_APT = False HAS_PYTHON_APT = False
def package_split(pkgspec): def package_split(pkgspec):
parts = pkgspec.split('=') parts = pkgspec.split('=', 1)
if len(parts) > 1: if len(parts) > 1:
return parts[0], parts[1] return parts[0], parts[1]
else: else:
@ -229,28 +229,28 @@ def expand_dpkg_options(dpkg_options_compressed):
def expand_pkgspec_from_fnmatches(m, pkgspec, cache): def expand_pkgspec_from_fnmatches(m, pkgspec, cache):
new_pkgspec = [] new_pkgspec = []
for name_or_fnmatch_or_version in pkgspec: for pkgspec_pattern in pkgspec:
pkgname_or_fnmatch_pattern, version = package_split(name_or_fnmatch_or_version) pkgname_pattern, version = package_split(pkgspec_pattern)
# note that any of these chars is not allowed in a (debian) pkgname # note that any of these chars is not allowed in a (debian) pkgname
if [c for c in pkgname_or_fnmatch_pattern if c in "*?[]!"]: if frozenset('*?[]!').intersection(pkgname_pattern):
if version: if version:
m.fail_json(msg="pkgname wildcard and version can not be mixed") m.fail_json(msg="pkgname wildcard and version can not be mixed")
# handle multiarch pkgnames, the idea is that "apt*" should # handle multiarch pkgnames, the idea is that "apt*" should
# only select native packages. But "apt*:i386" should still work # only select native packages. But "apt*:i386" should still work
if not ":" in pkgname_or_fnmatch_pattern: if not ":" in pkgname_pattern:
matches = fnmatch.filter( matches = fnmatch.filter(
[pkg.name for pkg in cache [pkg.name for pkg in cache
if not ":" in pkg.name], pkgname_or_fnmatch_pattern) if not ":" in pkg.name], pkgname_pattern)
else: else:
matches = fnmatch.filter( matches = fnmatch.filter(
[pkg.name for pkg in cache], pkgname_or_fnmatch_pattern) [pkg.name for pkg in cache], pkgname_pattern)
if len(matches) == 0: if len(matches) == 0:
m.fail_json(msg="No package(s) matching '%s' available" % str(pkgname_or_fnmatch_pattern)) m.fail_json(msg="No package(s) matching '%s' available" % str(pkgname_pattern))
else: else:
new_pkgspec.extend(matches) new_pkgspec.extend(matches)
else: else:
new_pkgspec.append(name_or_fnmatch_or_version) new_pkgspec.append(pkgspec_pattern)
return new_pkgspec return new_pkgspec
def install(m, pkgspec, cache, upgrade=False, default_release=None, def install(m, pkgspec, cache, upgrade=False, default_release=None,

Loading…
Cancel
Save