Merge pull request #846 from cfuhrman/devel

pkgin: Support multiple matching packages
reviewable/pr18780/r1
Brian Coca 9 years ago
commit b20f2b6abc

@ -68,6 +68,7 @@ import shlex
import os import os
import sys import sys
import pipes import pipes
import re
def query_package(module, pkgin_path, name): def query_package(module, pkgin_path, name):
"""Search for the package by name. """Search for the package by name.
@ -95,8 +96,11 @@ def query_package(module, pkgin_path, name):
# rc will not be 0 unless the search was a success # rc will not be 0 unless the search was a success
if rc == 0: if rc == 0:
# Get first line # Search results may contain more than one line (e.g., 'emacs'), so iterate
line = out.split('\n')[0] # through each line to see if we have a match.
packages = out.split('\n')
for package in packages:
# Break up line at spaces. The first part will be the package with its # Break up line at spaces. The first part will be the package with its
# version (e.g. 'gcc47-libs-4.7.2nb4'), and the second will be the state # version (e.g. 'gcc47-libs-4.7.2nb4'), and the second will be the state
@ -105,15 +109,21 @@ def query_package(module, pkgin_path, name):
# '<' - installed but out of date # '<' - installed but out of date
# '=' - installed and up to date # '=' - installed and up to date
# '>' - installed but newer than the repository version # '>' - installed but newer than the repository version
pkgname_with_version, raw_state = out.split(splitchar)[0:2] pkgname_with_version, raw_state = package.split(splitchar)[0:2]
# Search for package, stripping version
# (results in sth like 'gcc47-libs' or 'emacs24-nox11')
pkg_search_obj = re.search(r'^([a-zA-Z]+[0-9]*[\-]*\w*)-[0-9]', pkgname_with_version, re.M)
# Strip version # Do not proceed unless we have a match
# (results in sth like 'gcc47-libs') if not pkg_search_obj:
pkgname_without_version = '-'.join(pkgname_with_version.split('-')[:-1]) continue
# Grab matched string
pkgname_without_version = pkg_search_obj.group(1)
if name != pkgname_without_version: if name != pkgname_without_version:
return False continue
# no fall-through
# The package was found; now return its state # The package was found; now return its state
if raw_state == '<': if raw_state == '<':
@ -122,6 +132,10 @@ def query_package(module, pkgin_path, name):
return 'present' return 'present'
else: else:
return False return False
# no fall-through
# No packages were matched, so return False
return False
def format_action_message(module, action, count): def format_action_message(module, action, count):

Loading…
Cancel
Save