summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToshio Kuratomi <a.badger@gmail.com>2015-01-29 18:00:04 -0800
committerToshio Kuratomi <a.badger@gmail.com>2015-01-29 18:00:04 -0800
commit753a3ba3828e6e5c1b03c01e8ec8b4a16621a505 (patch)
tree82f6deaae2abe533b78367f666bbbee4737f3aeb
parent802c235894a93e408f512164d94254ce8a69669e (diff)
parent0b2d190f7243d702b471d46d0aa1151fd5384869 (diff)
downloadansible-modules-core-753a3ba3828e6e5c1b03c01e8ec8b4a16621a505.tar.gz
Merge pull request #624 from mscherer/use_rpm_module
Use the rpm python module rather than execing rpm
-rw-r--r--packaging/os/yum.py24
1 files changed, 15 insertions, 9 deletions
diff --git a/packaging/os/yum.py b/packaging/os/yum.py
index 744fc117..6d5f964b 100644
--- a/packaging/os/yum.py
+++ b/packaging/os/yum.py
@@ -25,6 +25,7 @@
import traceback
import os
import yum
+import rpm
try:
from yum.misc import find_unfinished_transactions, find_ts_remaining
@@ -108,7 +109,7 @@ options:
notes: []
# informational: requirements for nodes
-requirements: [ yum, rpm ]
+requirements: [ yum ]
author: Seth Vidal
'''
@@ -400,14 +401,19 @@ def transaction_exists(pkglist):
def local_nvra(module, path):
"""return nvra of a local rpm passed in"""
-
- cmd = ['/bin/rpm', '-qp' ,'--qf',
- '%{name}-%{version}-%{release}.%{arch}\n', path ]
- rc, out, err = module.run_command(cmd)
- if rc != 0:
- return None
- nvra = out.split('\n')[0]
- return nvra
+
+ ts = rpm.TransactionSet()
+ ts.setVSFlags(rpm._RPMVSF_NOSIGNATURES)
+ fd = os.open(path, os.O_RDONLY)
+ try:
+ header = ts.hdrFromFdno(fd)
+ finally:
+ os.close(fd)
+
+ return '%s-%s-%s.%s' % (header[rpm.RPMTAG_NAME],
+ header[rpm.RPMTAG_VERSION],
+ header[rpm.RPMTAG_RELEASE],
+ header[rpm.RPMTAG_ARCH])
def pkg_to_dict(pkgstr):