RPM Community Forums

Mailing List Message of <rpm-users>

Re: rpm dependency checking via python

From: Jeff Johnson <n3npq@mac.com>
Date: Sat 08 May 2010 - 16:26:05 CEST
Message-id: <87DFA186-A8E8-40AC-8376-ABA49305CA57@mac.com>

On May 8, 2010, at 9:15 AM, юрка олейников wrote:

> how do i check in python if rpmA has satisfied dependecies from rpmB if i do not want to use rpmdb?
> 

If you don't want to use an rpmdb, then you cannot check "added"
dependency assertions against "installed" packages. An rpmdb
is in fact where the "installed" package metadata lives.

> i thought that i can check 'provides' vs 'requires' fields of rpm header read from rpm-file.
> but looking on bash.rpm from CentOS 5 i've been a little bit confused:
> 
> >>> import rpm
> >>> file = open("rpms/bash.rpm")
> >>> header = ts.hdrFromFdno(file.fileno())
> >>> header['requires']
> ['/bin/bash', '/bin/sh', '/bin/sh', '/bin/sh', 'config(bash)', 'libc.so.6', 'libc.so.6(GLIBC_2.0)', 'libc.so.6(GLIBC_2.1)', 'libc.so.6(GLIBC_2.2)', 'libc.so.6(GLIBC_2.3)', 'libc.so.6(GLIBC_2.3.4)', 'libc.so.6(GLIBC_2.4)', 'libdl.so.2', 'libdl.so.2(GLIBC_2.0)', 'libdl.so.2(GLIBC_2.1)', 'libtermcap.so.2', 'mktemp', 'rpmlib(CompressedFileNames)', 'rpmlib(PayloadFilesHavePrefix)', 'rtld(GNU_HASH)']
> >>> header['provides']
> ['config(bash)', 'bash']
> 

FWIW, you really should _NOT_ be using 'requires' and 'provides'
because they aren't tag names, and because you will be confused
by WYSIWYG.

Dependencies are stored as a {N,EVR,F} triple, and (for 'requires')
the actual tags used in *.rpm metadata headers are
	RPMTAG_REQUIRENAME
	RPMTAG_REQUIREVERSION
	RPMTAG_REQUIREFLAGS
Other 'provides', 'conflicts', 'obsoletes' (and there's also 'triggers' dependencies)
follow similar naming.

The point here is that dependency assertions are a triple of {N,EVR,F}
and you are retrieving (through a 'requires' alias for RPMTAG_REQUIRENAME)
only the "N" in the triple of {N,EVR,F}

> >>> header.dsOfHeader()
> P bash = 3.2-21.el5
> 
> >>> header.dsFromHeader()
> R /bin/bash
> R /bin/sh
> R /bin/sh
> R /bin/sh
> R config(bash) = 3.2-21.el5
> R libc.so.6
> R libc.so.6(GLIBC_2.0)
> R libc.so.6(GLIBC_2.1)
> R libc.so.6(GLIBC_2.2)
> R libc.so.6(GLIBC_2.3)
> R libc.so.6(GLIBC_2.3.4)
> R libc.so.6(GLIBC_2.4)
> R libdl.so.2
> R libdl.so.2(GLIBC_2.0)
> R libdl.so.2(GLIBC_2.1)
> R libtermcap.so.2
> R mktemp
> R rpmlib(CompressedFileNames) <= 3.0.4-1
> R rpmlib(PayloadFilesHavePrefix) <= 4.0-1
> R rtld(GNU_HASH)
> 

A dependency set is one way to look at the triple of {N,EVR,F}.
The other way is to use header.sprintf[] which is both more flexible than header'requires']
and with a few more twists called "header tag extensions" and "header format extensions",
kind of like SQL "VIEW" meta-markup for complex queries.

> e.g. bash depends on itself :
> R /bin/bash
> R /bin/sh
> R /bin/sh
> R /bin/sh
> R config(bash) = 3.2-21.el5
> 

No. Technically, there's a dependency assertion that _GENERALLY_ tries
to enforce
	Every scriptlet in *.rpm packaging depends on the inetrpreter to run the script.

So its merely ccidental that "bash depends on itself". The reality is
that only bash %preun/%postun scriptlets depend on /bin/sh.

What you are missing is that dependencies have a context buried in the F portion
of a dependency {N,EVR,F} triple. There are essentially 3 contexts
	1) needed while installing
	2) needed to use
	3) needed while erasing
but in actual usage by rpm  there are only two contexts, the union of 1+2 and the
union of 2+3.

> moreover, who provides the flowing? :
> R rpmlib(CompressedFileNames) <= 3.0.4-1
> R rpmlib(PayloadFilesHavePrefix) <= 4.0-1
> 

These are called "tracking dependencies" that are used to ensure that
possibly incompatible *.rpm packaging is associated with an rpm installer
that has a prayer of Doing The Right Thing.

Think of "rpmlib(...)" as a name space that is provided by the rpm installer itself.

> so my question is: what is the proper way to verify rpm dependencies without rpmdb (using only rpm files)?
> sure i've missed something...

There is no proper way to verify dependency assertions without
supplying some representation of "installed" packages, that's what
is in an rpmdb.

hth

73 de Jeff
Received on Sat May 8 17:26:48 2010
Driven by Jeff Johnson and the RPM project team.
Hosted by OpenPKG and Ralf S. Engelschall.
Powered by FreeBSD and OpenPKG.