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

16.6.4 ������ ����������

����� ������������� ���� ����������, ������ �������� �������������� ������� run. ��������� ��� ���������:

ts.run(callback, client_data)

�������� callback ������ ���� �������� Python. �������� client_data - ����� ������, ������� �� ������ ��������� � �������� �����. ��������� � ���� ���������� ����� ���� ����� �������, ��� �� ������ ���� ������, ����������� � ������������� ������. � �������� client_data �� ����� ���� �������� �������� None.

16.6.4.1 �������� ������ ������ run
Callback, ������� ��� ������� � run, ���������. �������� ����� ������ ��������� ���������, ����� ���������� ���������� � �������. �� ������ ������������ callback.

��������� callback ����� ���������� �� ���� ���, ��� �������� ������ �������� �������� ����� ��� ����������� ������� ���������� ���������� (�������� � ���������� ����������� ���������� ��� ��������-�����).

������� ��������� ��������� ������ ��� ���� ����������:

def runCallback(reason, amount, total, key, client_data):

# Do your stuff...

key - ��� ������, ��������������� ���� ��� ������ addInstall. client_data - ������, ������� ����� ������������ � run.

������ ���, ����� ���������� �������� �����, ��� ���������� ����� �������� ���� reason. ��������� �������� ����� �������� � �������.

��������

�� ��� ���������

rpm.RPMCALLBACK_UNKNOWN

����������� ������

rpm.RPMCALLBACK_INST_PROGRESS

�������� ���������

rpm.RPMCALLBACK_INST_START

����� ���������

rpm.RPMCALLBACK_INST_OPEN_FILE

Callback ������ ������� ���� ������

rpm.RPMCALLBACK_INST_CLOSE_FILE

Callback ������ ������� ���� ������

rpm.RPMCALLBACK_TRANS_PROGRESS

�������� ����������

rpm.RPMCALLBACK_TRANS_START

����� ����������

rpm.RPMCALLBACK_TRANS_STOP

���� ����������

rpm.RPMCALLBACK_UNINST_PROGRESS

�������� ��������

rpm.RPMCALLBACK_UNINST_START

����� ��������

rpm.RPMCALLBACK_UNINST_STOP

���� ��������

rpm.RPMCALLBACK_REPACKAGE_PROGRESS

�������� ����������

rpm.RPMCALLBACK_REPACKAGE_START

����� ����������

rpm.RPMCALLBACK_REPACKAGE_STOP

���� ����������

rpm.RPMCALLBACK_UNPACK_ERROR

������ ����������

rpm.RPMCALLBACK_CPIO_ERROR

������ cpio ��� ������� ��������������� ��������

��� callback ������ ������������ �� ������� ���� ��� ������: rpm.RPMCALLBACK_INST_OPEN_FILE � rpm.RPMCALLBACK_INST_CLOSE_FILE.

� reason, ������ rpm.RPMCALLBACK_INST_OPEN_FILE, ���������� ������� ���� rpm-������ � ������� ����������. ���� ���������� ���������� ������� � ���������-��������� ����������, ��� �� ������� ���� � ���� ���������, ��� ��� ����������� ���� �������, ����� reason ����� rpm.RPMCALLBACK_INST_CLOSE_FILE.

16.6.4.2 �������� ������ callback-�������
��� ���� ���������� ���������� ������ callback ��� ��������� ��� ���������� �������.

# Global file descriptor for the callback.

rpmtsCallback_fd = None

def runCallback(reason, amount, total, key, client_data):

global rpmtsCallback_fd

if reason == rpm.RPMCALLBACK_INST_OPEN_FILE:

print "Opening file. ", reason, amount, total, key, client_data

rpmtsCallback_fd = os.open(client_data, os.O_RDONLY)

return rpmtsCallback_fd

elif reason == rpm.RPMCALLBACK_INST_START:

print "Closing file. ", reason, amount, total, key, client_data

os.close(rpmtsCallback_fd)

���� callback �������������, ��� � ����� addInstall ���������� � �������� ���������������� ������ ��� ����� rpm-������. client_data � ����� run ������������, �� ��� ������� ����� ��� �������� �������. �����, ��������, ������������ ��� ����������� ��� ����, ����� �������� �������� ����������� ����� � ���������� ����������.

16.6.4.3 ���������� ������
������ ���� �������� ������ (rpmupgrade.py) ��� ���������� ��� ��������� ������.

#!/usr/bin/python

# Upgrades packages passed on the command line.

# Usage:

# python rpmupgrade.py rpm_file1.rpm rpm_file2.rpm ...

#

import rpm, os, sys

# Global file descriptor for the callback.

rpmtsCallback_fd = None

def runCallback(reason, amount, total, key, client_data):

global rpmtsCallback_fd

if reason == rpm.RPMCALLBACK_INST_OPEN_FILE:

print "Opening file. ", reason, amount, total, key, client_data

rpmtsCallback_fd = os.open(key, os.O_RDONLY)

return rpmtsCallback_fd

elif reason == rpm.RPMCALLBACK_INST_START:

print "Closing file. ", reason, amount, total, key, client_data

os.close(rpmtsCallback_fd)

def checkCallback(ts, TagN, N, EVR, Flags):

if TagN == rpm.RPMTAG_REQUIRENAME:

prev = ""

Nh = None

if N[0] == '/':

dbitag = 'basenames'

else:

dbitag = 'providename'

# What do you need to do.

if EVR:

print "Must find package [", N, "-", EVR, "]"

else:

print "Must find file [", N, "]"

if resolved:

# ts.addIntall(h, h, 'i')

return -1

return 1

def readRpmHeader(ts, filename):

""" Read an rpm header. """

fd = os.open(filename, os.O_RDONLY)

h = ts.hdrFromFdno(fd)

os.close(fd)

return h

ts = rpm.TransactionSet()

# Set to not verify DSA signatures.

ts.setVSFlags(-1)

for filename in sys.argv[1:]:

h = readRpmHeader(ts, filename)

print "Upgrading %s-%s-%s" % (h['name'], h['version'], h['release'])

ts.addInstall(h, filename, 'u')

unresolved_dependencies = ts.check(checkCallback)

if not unresolved_dependencies:

ts.order()

print "This upgrade will install:"

for te in ts:

print "%s-%s-%s" % (te.N(), te.V(), te.R())

print "Running transaction (final step)..."

ts.run(runCallback, 1)

else:

print "Error: Unresolved dependencies, transaction failed."

print unresolved_dependencies

���� ������ �������, ��� ��� ����� rpm-������ ����� �������� � ��������� ��������� ������, ������� ��� �� ��������� ���������� ������ (� ���� ��� ����� ����� - �� ���������).

��� ������� ������� ������ ���������:

# rpm -q jikes

jikes-1.17-1

# python rpmupgrade.py jikes-1.18-1.i386.rpm

Upgrading jikes-1.18-1

This upgrade will install:

jikes-1.18-1

jikes-1.17-1

Running transaction (final step)...

Opening file. 4 0 0 jikes-1.18-1.i386.rpm 1

Closing file. 2 0 2854204 jikes-1.18-1.i386.rpm 1

# rpm -q jikes

jikes-1.18-1

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

$ python rpmupgrade.py jikes-1.18-1.i386.rpm

Upgrading jikes-1.18-1

This upgrade will install:

jikes-1.18-1

jikes-1.17-1

Running transaction (final step)...

error: cannot get exclusive lock on /var/lib/rpm/Packages

error: cannot open Packages index using db3 - Operation not permitted (1)

error: cannot open Packages database in /var/lib/rpm

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

# python rpmupgrade.py jikes-1.17-glibc2.2-1.i386.rpm jpilot-0_97-1_i386.rpm
Upgrading jikes-1.17-1

Upgrading jpilot-0.97-1

Must find file [ libpisock.so.3 ]

Error: Unresolved dependencies, transaction failed.

(('jpilot', '0.97', '1'), ('libpisock.so.3', None), 0, None, 0)

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

# python rpmupgrade.py eruby-devel-0.9.8-2.i386.rpm

Upgrading eruby-devel-0.9.8-2

Must find package [ eruby-libs - 0.9.8 ]

Error: Unresolved dependencies, transaction failed.

(('eruby-devel', '0.9.8', '2'), ('eruby-libs', '0.9.8'), 8, None, 0)

����� - ������ 17. ���������������� RPM �� Perl
����� - �������� � ��������������� ������� ��������� ����������
����������


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