diff options
author | Brian Coca <bcoca@ansible.com> | 2015-03-31 23:56:28 -0400 |
---|---|---|
committer | Brian Coca <bcoca@ansible.com> | 2015-03-31 23:56:28 -0400 |
commit | 512c684b52e4848eaac2c4a8551426ae14bc1cea (patch) | |
tree | c3ea7e0917845db36179f375a41cb0ce03c1336f | |
parent | 3832be803320649144f83fd3b751400208c820f3 (diff) | |
parent | 23495a16f4f16982ef30f2994c9e405c9276bc78 (diff) | |
download | ansible-modules-extras-512c684b52e4848eaac2c4a8551426ae14bc1cea.tar.gz |
Merge pull request #128 from robinro/patch_multiple_versions_rpm_zypper
Patch multiple versions rpm zypper
-rw-r--r-- | packaging/os/zypper.py | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/packaging/os/zypper.py b/packaging/os/zypper.py index 196a7e27..a6fdc5e7 100644 --- a/packaging/os/zypper.py +++ b/packaging/os/zypper.py @@ -95,25 +95,31 @@ def zypper_version(module): return rc, stderr # Function used for getting versions of currently installed packages. -def get_current_version(m, name): +def get_current_version(m, packages): cmd = ['/bin/rpm', '-q', '--qf', '%{NAME} %{VERSION}-%{RELEASE}\n'] - cmd.extend(name) - (rc, stdout, stderr) = m.run_command(cmd) + cmd.extend(packages) + + rc, stdout, stderr = m.run_command(cmd, check_rc=False) current_version = {} rpmoutput_re = re.compile('^(\S+) (\S+)$') - for stdoutline, package in zip(stdout.splitlines(), name): - m = rpmoutput_re.match(stdoutline) - if m == None: + + for stdoutline in stdout.splitlines(): + match = rpmoutput_re.match(stdoutline) + if match == None: return None - rpmpackage = m.group(1) - rpmversion = m.group(2) - if package != rpmpackage: + package = match.group(1) + version = match.group(2) + current_version[package] = version + + for package in packages: + if package not in current_version: + print package + ' was not returned by rpm \n' return None - current_version[package] = rpmversion return current_version + # Function used to find out if a package is currently installed. def get_package_state(m, packages): cmd = ['/bin/rpm', '--query', '--qf', 'package %{NAME} is installed\n'] @@ -123,19 +129,21 @@ def get_package_state(m, packages): installed_state = {} rpmoutput_re = re.compile('^package (\S+) (.*)$') - for stdoutline, name in zip(stdout.splitlines(), packages): - m = rpmoutput_re.match(stdoutline) - if m == None: - return None - package = m.group(1) - result = m.group(2) - if not name.startswith(package): - print name + ':' + package + ':' + stdoutline + '\n' + for stdoutline in stdout.splitlines(): + match = rpmoutput_re.match(stdoutline) + if match == None: return None + package = match.group(1) + result = match.group(2) if result == 'is installed': - installed_state[name] = True + installed_state[package] = True else: - installed_state[name] = False + installed_state[package] = False + + for package in packages: + if package not in installed_state: + print package + ' was not returned by rpm \n' + return None return installed_state |