wiki:Packages/rpm/rpm-python/rpminfo

Version 1 (modified by yasumichi, 11 years ago) (diff)

--

パッケージの詳細情報を表示する

 Printing information on packagesの例は、そのままでは期待通りに動作しない。rpm.ds オブジェクトの仕様が、当時と違うと思われる。

rpminfo.py

#!/usr/bin/python
# Lists information on installed package listed on command line.
# Usage:
# python rpminfo.py package_name

import rpm, sys

def printEntry(header, label, format, extra):
	value = header.sprintf(format).strip()
	print "%-20s: %s %s" % (label, value, extra)

def printHeader(h):
	if h[rpm.RPMTAG_SOURCEPACKAGE]:
		extra = " source package"
	else:
		extra = " binary package"

	printEntry(h, 'Package', "%{NAME}-%{VERSION}-%{RELEASE}", extra)
	printEntry(h, 'Group', "%{GROUP}", '')
	printEntry(h, 'Summary', "%{Summary}", '')
	printEntry(h, 'Arch-OS-Platform', "%{ARCH}-%{OS}-%{PLATFORM}", '')
	printEntry(h, 'Vendor', "%{Vendor}", '')
	printEntry(h, 'URL', "%{URL}", '')
	printEntry(h, 'Size', "%{Size}", '')
	printEntry(h, 'Installed on', "%{INSTALLTID:date}", '')

	print h['description']
	print "Files:"
	for fi in h.fiFromHeader():
		print fi[0]

	# Dependencies
	print "Provides:"
	for ds in h.dsFromHeader('providename'):
		print ds.DNEVR()
	print "Requires:"
	for ds in h.dsFromHeader('requirename'):
		print ds.DNEVR()
	print "Obsoletes:"
	for ds in h.dsFromHeader('obsoletename'):
		print ds.DNEVR()
	print "Conflicts:"
	for ds in h.dsFromHeader('conflictname'):
		print ds.DNEVR()

ts = rpm.TransactionSet()
for name in sys.argv:
	mi = ts.dbMatch( 'name', name )
	for h in mi:
		printHeader(h)

実行例