Fedora Linux Support Community & Resources Center
  #1  
Old 8th June 2007, 05:39 PM
7ofClubs Offline
Registered User
 
Join Date: Jun 2007
Posts: 2
Querying with the RPM Python API

This might be the wrong forum, but here goes.

I'm trying to use the rpm python api to get information out of the rpm database, specifically the type of information given with rpm -q --whatprovides. I've got a solution halfway working. The problem is figuring out the provider of files. The python query call:
Code:
import rpm
ts = rpm.TransactionSet()
headers = ts.dbMatch('providename', whatevercapabilityIwant)
gives me the header of the providing package when the capability is a package. But when the capability is a file path, headers is empty. I've tried doing:
Code:
baseheaders = ts.dbMatch('basenames', whateverthenameofthefileis)
dirheaders = ts.dbMatch('dirnames', whateverthenameofthedirectoryis)
Then matching the headers in both lists. Problem is, baseheaders and dirheaders are empty, regardless of the file I'm querying.

So, in conclusion, any ideas on how to mimic the rpm -q --whatprovides call? Or where else to ask this question?
Reply With Quote
  #2  
Old 11th June 2007, 03:57 PM
7ofClubs Offline
Registered User
 
Join Date: Jun 2007
Posts: 2
Ok, I figured it out. For some reason, to query using 'basenames' (or the equivalent rpm.RPMTAG_BASENAMES), you need to use the full file path, not the base name. e.g. '/bin/sh' instead of 'sh'. As for searching using 'dirnames', I was getting a populated list, I just tested it wrong (oops).

BTW this is on:
FC6
RPM version 4.4.2
Python 2.4.4

To sum up. To find the rpm package(s) that provide a file, use:

Code:
import rpm
ts = rpm.TransactionSet()
headers = ts.dbMatch('basenames', '/bin/sh') #or whatever filepath you want

# to print it
for h in headers:
    print h['name']
Hope this helps someone.
7

Last edited by 7ofClubs; 11th June 2007 at 04:09 PM.
Reply With Quote
Reply

Tags
api, python, querying, rpm

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Python, IDLE, Python-tools Gnome. Deonis Using Fedora 2 12th March 2009 03:44 AM
Processing Conflict: python-devel conflicts python< 2.3.4-13.1 guarriman Using Fedora 0 15th September 2005 05:53 PM


Current GMT-time: 00:32 (Tuesday, 21-10-2014)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat
Qalat al Andalus Instagram Photos - Santo Domingo Oeste Travel Photos - Wiehl