Tuesday, May 31, 2011

python: rpm

http://docs.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html/RPM_Guide/ch16s06s02.html
http://fedora.linuxsir.org/fedoradocs/rpm-guide/en/ch16s06.html


#!/usr/bin/python
# Adds all package files on command line to a transaction
# and prints out the transaction elements.
# Usage:
# python te.py rpm_file1.rpm rpm_file2.rpm ...
#
import rpm, os, sys

def readRpmHeader(ts, filename):
""" Read an rpm header. """
fd = os.open(filename, os.O_RDONLY)
h = ts.hdrFromFdno(fd)
os.close(fd)
return h

ts = rpm.TransactionSet()
# Set to not verify DSA signatures.
ts.setVSFlags(rpm._RPMVSF_NOSIGNATURES)
for filename in sys.argv[1:]:
h = readRpmHeader(ts, filename)
print "Installing %s-%s-%s" % (h['name'], h['version'], h['release'])
ts.addInstall(h, filename, 'i')

print "This will install:"
for te in ts:
print "%s-%s-%s" % (te.N(), te.V(), te.R() )


ts.check()
ts.order()
print "\n"
print "This will install:"
for te in ts:
print "%s-%s-%s" % (te.N(), te.V(), te.R() )

No comments:

Related Posts Plugin for WordPress, Blogger...