Merge pull request #128 from robinro/patch_multiple_versions_rpm_zypper
Patch multiple versions rpm zypper
This commit is contained in:
commit
512c684b52
1 changed files with 28 additions and 20 deletions
|
@ -95,25 +95,31 @@ def zypper_version(module):
|
||||||
return rc, stderr
|
return rc, stderr
|
||||||
|
|
||||||
# Function used for getting versions of currently installed packages.
|
# 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 = ['/bin/rpm', '-q', '--qf', '%{NAME} %{VERSION}-%{RELEASE}\n']
|
||||||
cmd.extend(name)
|
cmd.extend(packages)
|
||||||
(rc, stdout, stderr) = m.run_command(cmd)
|
|
||||||
|
rc, stdout, stderr = m.run_command(cmd, check_rc=False)
|
||||||
|
|
||||||
current_version = {}
|
current_version = {}
|
||||||
rpmoutput_re = re.compile('^(\S+) (\S+)$')
|
rpmoutput_re = re.compile('^(\S+) (\S+)$')
|
||||||
for stdoutline, package in zip(stdout.splitlines(), name):
|
|
||||||
m = rpmoutput_re.match(stdoutline)
|
for stdoutline in stdout.splitlines():
|
||||||
if m == None:
|
match = rpmoutput_re.match(stdoutline)
|
||||||
|
if match == None:
|
||||||
return None
|
return None
|
||||||
rpmpackage = m.group(1)
|
package = match.group(1)
|
||||||
rpmversion = m.group(2)
|
version = match.group(2)
|
||||||
if package != rpmpackage:
|
current_version[package] = version
|
||||||
|
|
||||||
|
for package in packages:
|
||||||
|
if package not in current_version:
|
||||||
|
print package + ' was not returned by rpm \n'
|
||||||
return None
|
return None
|
||||||
current_version[package] = rpmversion
|
|
||||||
|
|
||||||
return current_version
|
return current_version
|
||||||
|
|
||||||
|
|
||||||
# Function used to find out if a package is currently installed.
|
# Function used to find out if a package is currently installed.
|
||||||
def get_package_state(m, packages):
|
def get_package_state(m, packages):
|
||||||
cmd = ['/bin/rpm', '--query', '--qf', 'package %{NAME} is installed\n']
|
cmd = ['/bin/rpm', '--query', '--qf', 'package %{NAME} is installed\n']
|
||||||
|
@ -123,19 +129,21 @@ def get_package_state(m, packages):
|
||||||
|
|
||||||
installed_state = {}
|
installed_state = {}
|
||||||
rpmoutput_re = re.compile('^package (\S+) (.*)$')
|
rpmoutput_re = re.compile('^package (\S+) (.*)$')
|
||||||
for stdoutline, name in zip(stdout.splitlines(), packages):
|
for stdoutline in stdout.splitlines():
|
||||||
m = rpmoutput_re.match(stdoutline)
|
match = rpmoutput_re.match(stdoutline)
|
||||||
if m == None:
|
if match == None:
|
||||||
return None
|
|
||||||
package = m.group(1)
|
|
||||||
result = m.group(2)
|
|
||||||
if not name.startswith(package):
|
|
||||||
print name + ':' + package + ':' + stdoutline + '\n'
|
|
||||||
return None
|
return None
|
||||||
|
package = match.group(1)
|
||||||
|
result = match.group(2)
|
||||||
if result == 'is installed':
|
if result == 'is installed':
|
||||||
installed_state[name] = True
|
installed_state[package] = True
|
||||||
else:
|
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
|
return installed_state
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue