检查安装在 Centos/Redhat 中的软件包列表的 Pythonic 方法?
Pythonic way to check list of packages installed in Centos/Redhat?
在 bash 脚本中,我会这样做:
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 也可用于查询特定的包,您需要传递一个标签的名称,以及您要查找的该标签的值:
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')
这篇关于检查是否安装了包的 Pythonic 方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!