使用Python RPM模块进行通配符匹配?

3 投票
1 回答
1666 浏览
提问于 2025-04-16 01:42

下面的代码使用了 rpm 模块来查询已安装软件包的版本。我想做的是查询一组通过通配符指定的软件包,比如说搜索 "python*" 而不是 "python"。请问使用 rpm 模块可以做到这一点吗?

  1 #!/usr/bin/python
  2 
  3 import rpm
  4 
  5 ts = rpm.TransactionSet()
  6 mi = ts.dbMatch("name", "python")
  7 for i in mi:
  8     print i['name'], i['version']

`

1 个回答

5
import rpm
ts = rpm.TransactionSet()
mi = ts.dbMatch()
mi.pattern('name', rpm.RPMMIRE_GLOB, 'py*' )
for h in mi:
   # Do something with the header... 

当然可以!请把你想要翻译的内容发给我,我会帮你用简单易懂的语言解释清楚。

撰写回答