Skip to content

Commit

Permalink
Package: rpm (centos / rhel) support
Browse files Browse the repository at this point in the history
  • Loading branch information
philpep committed May 14, 2015
1 parent 81a4469 commit 00fec1f
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions testinfra/modules/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ def f(Command, SystemInfo):
return OpenBSDPackage
elif Command.run_test("which apt-get").rc == 0:
return DebianPackage
elif Command.run_test("which rpm").rc == 0:
return RpmPackage
else:
raise NotImplementedError
f.__doc__ = cls.__doc__
Expand Down Expand Up @@ -94,3 +96,22 @@ def version(self):
# OpenBSD: inst:zsh-5.0.5p0
# NetBSD: zsh-5.0.7nb1
return out.split(self.name + "-", 1)[1]


class RpmPackage(Package):

@property
def is_installed(self):
return self.run_test("rpm -q %s", self.name)

@property
def version(self):
out = self.check_output("rpm -qi %s", self.name)

# Name : bash
# Version : 4.2.46
# ...
for line in out.splitlines():
if line.startswith("Version"):
return line.split(":", 1)[1].strip()
raise RuntimeError("Cannot parse output '%s'" % (out,))

0 comments on commit 00fec1f

Please sign in to comment.