检查Centos / Redhat中安装的软件包列表的Python方式?
在bash脚本中,我将执行以下操作:
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('name','mysql')