[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: Any SMALL examples of rpm-python code?



On Thu, Jan 09, 2003 at 05:07:58PM -0500, Kevin Cole wrote:
> Hi,
> 
> Does anyone have a real basic python-based "query the RPM database and
> return the fields I ask for in a list"?
> 

For simple strings, using rpm-4.1, this is trivial

    import rpm
    ts = rpm.TransactionSet()
    for h in ts.dbMatch():
        print h['name'], h['version'], h['release']

Arrays are returned as tuples of elements, i.e. try

    for h in ts.dbMatch():
	print h['basenames']

Slightly fancier is to add headers to the transaction, then
access transaction element objects:

    for h in ts.dbMatch():
	ts.addInstall(h, h, 'i')

    for te in ts:
        print te.FI('basenames')

to list every file in every installed package. There are other
methods associated with transaction elements, see te.DS('providename')
for all the provides, te.DS('requirename') for all the requires, etc

> I'm familiar enough with Python and Postgresql to get the two of them
> talking, but don't know squat about whatever RPM's database is. (db?
> db2? db3? Doesn't matter since I don't know any of them.)  Several
> years ago, I was able to get something simple going in C, but I've
> misplaced that code.
> 

Berkeley DB, not that it matters a bit, because retrieval is based
on transactions, not the database.

> I've been looking through the doxygen documentation (from rpm-devel)
> and am completely lost.  (Was there better documentation when I did it
> in C or did I just get lucky?)

Yeah, there's no street signs yet, but all the houses are numbered.

73 de Jeff

-- 
Jeff Johnson	ARS N3NPQ
jbj@redhat.com (jbj@jbj.org)
Chapel Hill, NC





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index] []