Pythonic way to check list of packages installed in Centos/Redhat?
In a bash script, I'd do:
rpm -qa | grep -w packagename
import sys import rpm ts = rpm.TransactionSet() mi = ts.dbMatch( 'name', sys.argv[1] ) try : h = mi.next() print "%s-%s-%s" % (h['name'], h['version'], h['release']) except StopIteration: print "Package not found"
dbMatch can also be used to query specific packages, you need to pass the name of a tag, as well as the value for that tag that you are looking for:
dbMatch('name','mysql')
2.1m questions
2.1m answers
60 comments
57.0k users