����� ������������ OpenNet.ru / ������ "������������ ��� Linux" / ������

16.3.2 ������� � �� RPM

��� �������� ���������� ��������� ������������ ����� dbMatch ���������� ���� ����������. ������� C API ��������� �������� ��������� ��������� ���������� ������, ������� ������������� ������� �� ��������� ��������.

����� dbMatch ��� ���������� ��������, ��� ����� ������������ ��� ������������� ������. ������� ���������:

import rpm

ts = rpm.TransactionSet()

mi = ts.dbMatch()

for h in mi:

# Do something with header object...

� ���� ������� ����� dbMatch ���������� ��������� ��������. ���� for ������� ���� ��������, ��������� ���� ������ ������ �� ���.

����� ������� ���������� ����� �������� ����� next ��� ��������� ���������� ������� ������. ��������:

import rpm

ts = rpm.TransactionSet()

mi = ts.dbMatch()

while mi:

h = mi.next()

# Do something with the header object

������ ����� ������ next � ������� ������� Python API �������������� �� �����.

��������� ������� ���������� ������ ������� �� Python (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'])

��� ������ ������� �� ������ �������� ��������� ����� (����� ������ ������ ���� �������� �����):

$ 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

���� �� ������ ����������� ����� ����������, ����� �������� ������ �������������� ������ � ������ �������:

$ ./rpmqa.py

����� - ������ � �������
����� - ������ � �� RPM
����������


����� ������������ �� OpenNet.ru