Pythonic way to check list of packages installed in Centos/Redhat?
In a bash script, I\'d do:
rpm -qa | grep -w packagename
I could not get this answer: https://stackoverflow.com/a/51258124/498657 to work on Python 3.6.8, what did work for me was:
import sys
import rpm
ts = rpm.TransactionSet()
mi = ts.dbMatch( 'name', 'lsof' )
rpmhit=0
for h in mi:
if h['name'] == 'lsof':
rpmhit=1
break
if rpmhit == 0:
print('Error: Package lsof not installed. Install using: dnf install lsof')
sys.exit(3)