Call dbMatch on a transaction set to create a match iterator. As with the C API, a match iterator allows your code to iterate over the packages that match a given criteria.
A call to dbMatch with no parameters means to set up a match iterator to go over the entire set of installed packages. The basic format follows:
import rpm
 
ts = rpm.TransactionSet()
 
mi = ts.dbMatch()
for h in mi:
# Do something with header object...
In this example, the call to dbMatch returns a match iterator. The for loop iterates over the match iterator, returning one header each time.
In addition to this syntax, you can call next on the match iterator to get the next entry, a header object that represents one package. For example:
import rpm
 
ts = rpm.TransactionSet()
 
mi = ts.dbMatch()
while mi:
h = mi.next()
# Do something with the header object
The explicit call to next on the match iterator will likely no longer be supported in a future version of the RPM Python API, since the PEP-234 (Python Enhancement Proposal) calls for one means or the other for iterating, but not both.
For example, Listing 17-1 shows a Python script to print out the name, version, and release information for all installed packages.
Listing 17-1: rpmqa.py
#!/usr/bin/python
 
# Acts like rpm -qa and lists the names of all the installed packages.
# Usage:
# python rpmqa.py
 
import rpm
 
ts = rpm.TransactionSet()
 
mi = ts.dbMatch()
for h in mi:
 
print "%s-%s-%s" % (h['name'], h['version'], h['release'])
When you call this script, you should see output like the following, truncated for space:
$ python rpmqa.py
libbonoboui-2.0.1-2
attr-2.0.8-3
dhclient-3.0pl1-9
file-3.37-8
hdparm-5.2-1
ksymoops-2.4.5-1
imlib-1.9.13-9
logwatch-2.6-8
mtr-0.49-7
openssh-clients-3.4p1-2
pax-3.0-4
python-optik-1.3-2
dump-0.4b28-4
sendmail-8.12.5-7
sudo-1.6.6-1
mkbootdisk-1.4.8-1
telnet-0.17-23
usbutils-0.9-7
wvdial-1.53-7
docbook-dtds-1.0-14
urw-fonts-2.0-26
db4-utils-4.0.14-14
libogg-devel-1.0-1
Note
If you set the execute permission on this script, you can skip the explicit call to the python command. For example:
$ ./rpmqa.pyr

querying rpm database的更多相关文章

  1. RPM Database 实战详解

    RPM 是 RPM Package Manager 的简写,是发源于 Red-hat 系统的软件管理工具,所以最初的名字叫做 Red-hat Packager Manager.目前,RPM 已发展成为 ...

  2. RPM Database

    RPM Database RPM 不仅在安装.升级.卸载方面工作出色,而且在查询和验证方面也表现非凡.你很久前安装了一个数据库软件,但现在忘记了它的版本号,也不知道它的说明文档的位置,可以通过 RPM ...

  3. How to rebuild RPM database on a Red Hat Enterprise Linux system?

    本文是笔者最近遇到的一个故障的处理过程,解决方案是Rebuild RPM 的DB,后面内容其实是REDHAT官方的solutions,不过我遇到的现象和解决方案都与官方有点出入,故一直帖出来: 我遇到 ...

  4. Fedora 22中的RPM软件包管理工具

    Introduction The RPM Package Manager (RPM) is an open packaging system that runs on Fedora as well a ...

  5. MAN RPM

    RPM(8)   Red Hat Linux   RPM(8) NAME/名称       rpm - RPM Package Manager/RPM-RPM包管理器SYNOPSIS/简介  QUER ...

  6. linux环境,通过rpm删除mysql包,报错:error reading information on service mysqld: Invalid argument

    问题描述: 今天在做saltstack的练习,想要通过sls的方式,在远程进行mysql数据库的安装,发现无法通过service的方式启动数据库,然后就想给删除了重新进行安装,在通过rpm -e进行删 ...

  7. FluentData -Micro ORM with a fluent API that makes it simple to query a database 【MYSQL】

    官方地址:http://fluentdata.codeplex.com/documentation MYSQL: MySQL through the MySQL Connector .NET driv ...

  8. Fedora 22中的DNF软件包管理工具

    Introduction DNF is the The Fedora Project package manager that is able to query for information abo ...

  9. Code First :使用Entity. Framework编程(7) ----转发 收藏

    第7章 高级概念 The Code First modeling functionality that you have seen so far should be enough to get you ...

随机推荐

  1. 数组dome

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  2. BZOJ 2820 YY的GCD ——莫比乌斯反演

    我们可以枚举每一个质数,那么答案就是 $\sum_{p}\sum_{d<=n}\mu(d)*\lfloor n / pd \rfloor *\lfloor m / pd \rfloor$ 直接做 ...

  3. 洛谷 [P2964] 硬币的游戏

    博弈论+dp 依旧是博弈论的壳子,但问的是最大值,所以要dp 设 dp[i][j] 表示该取 i 号硬币,上一次取了 j 个的先手能取的最大值, 因为每次从小到大枚举复杂度太高,所以我们要从 dp[i ...

  4. PHP实现当前文件夹下所有文件和文件夹的遍历

    <?php function myScandir($dir){ static $flag=''; //设置缩进显示格式 $files = scandir($dir);//读取当前文件夹的文件 $ ...

  5. 【HDOJ5979】Convex(三角函数)

    题意:n个点在一个半径为R的圆上,给出这n个点顺时针的夹角差值,求这n个点的凸包面积 n<=10,R<=10 思路:S=1/2*sinθ*a*b 角度转弧度再用sin C++有点小毛病,叫 ...

  6. MySQL 中 key, primary key ,unique key,index的区别

    一.key与primary key区别 CREATE TABLE wh_logrecord ( logrecord_id int(11) NOT NULL auto_increment, user_n ...

  7. 什么是Hadoop?什么是HDFS?

    [学习笔记] 什么是Hadoop?什么是HDFS?马 克-to-win @ 马克java社区:Hadoop是Apache基金会开发的一个分布式系统基础架构.比如前面我们接触的Spring就是一个开发应 ...

  8. File类 文件过滤器

    创建过滤器 package cn.zmh.File; import java.io.File; import java.io.FileFilter; // 实现FileFilter类的功能 publi ...

  9. Maven用项目模板生成项目

    Archetype插件是Maven生成项目的项目模板,项目模板就是一个框,把文件夹这些定好,然后就可以在上开写具体逻辑等等. 最常用的命令: mvn archetype:generate 这个是生成一 ...

  10. go语言学习之路 一:开发环境配置

    1. 安装go 1)下载地址:http://www.golangtc.com/download,下载后直接双击msi文件安装,默认安装在c:\go 2)安装完成后默认会在环境变量 Path 后添加 G ...