Skip to content

Instantly share code, notes, and snippets.

@maurorappa
Last active July 14, 2017 08:50
Show Gist options
  • Save maurorappa/25892d26cfd3f3782c76565f75dc7afb to your computer and use it in GitHub Desktop.
Save maurorappa/25892d26cfd3f3782c76565f75dc7afb to your computer and use it in GitHub Desktop.
Query RPM database in Python
#!/usr/bin/python
# Acts like rpm -qa and lists the names of all the installed packages.
# Usage:
# python rpmqa.py
# This toool was used to debug RedHat Bugzilla BZ#1253608 for RHEL6 (not public)
# the relative errata is: https://rhn.redhat.com/errata/RHBA-2015-1809.html
import rpm
import datetime
ts = rpm.TransactionSet()
mi = ts.dbMatch()
mi.pattern('name', rpm.RPMMIRE_GLOB, 'kernel*' )
for h in mi:
install_time = h['INSTALLTID']
date = datetime.datetime.fromtimestamp(install_time)
print "%s-%s-%s installed %s" % (h['name'], h['version'], h['release'],date.strftime('%Y-%m-%d %H:%M:%S'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment