If you ever get to use this library, it’s design is horrible and it’s documentation is worse. If you want to retrieve the basic RPM data, I have a code snippet you can use:

As long as at the top of your file you had import rpm that should work file. That gives a few basic fields. To get a full list of fields, I actually used a reference from a perl module: http://cpansearch.perl.org/src/RJRAY/Perl-RPM-1.51/RPM/Constants.pm.
If you expect more information, it really isn’t out there. Every mailing list post tells you to visit slides at people.redhat.com, on a webpage which no longer exists from 2004. I was able to find it again, so this may help you also: http://www.ukuug.org/events/linux2004/programme/paper-PNasrat-1/rpm-python-slides/toc.html. ActiveState’s website also has a snippet showing a bit of what is contained in that hdr class, which really helped trying to decipher this: http://code.activestate.com/recipes/576767/.
And for all future python programmers out there, THERE IS NO NEED TO ABBREVIATE VARIABLE NAMES. We have big computers, lots of memory, and naming things ‘hdr’ and ‘ts’ help nobody, and make your code horrible for others to use. Seriously, expand them out.
Related posts:
#1 by Stefano F. (tacone) on May 21, 2009 - 5:32 pm
Quote
not tested, by the way:
def getRPMInformation (rpmPath):
long_variable_name = rpm.ts();
try:
file_descriptor_number = os.open(rpmPath, os.O_RDONLY)
rpmInfo = long_variable_name.hdrFromFdno(file_descriptor_number);
os.close(file_descriptor_number)
except:
return False
return rpmInfo
I don’t get the point of your post. I don’t also get the name of returning a var with one name or another, since the name itself doesn’t get returned.
#2 by sharms on May 21, 2009 - 8:14 pm
Quote
The point is someone has to read that code and use it, so you might as well name it so it can be picked up more intuitively. The name matters as this was showing how to actually use the python-rpm. I am trying to phrase this in a decent way, maybe in summary it was for illustrative purposes of what the dictionary was actually containing.
The fdno was cut and pasted straight from the powerpoint that I linked to, and in no way reflects a finished or released library function, just shows usage.
#3 by nixternal on May 22, 2009 - 2:06 am
Quote
I had a bunch of really great RPM tools I created in Python for my last job. They are all GPLv3, but that company has refused to release them in their open source releases. I am going to push them and grab our common lawyer to force them. The good thing is, I put all of the code copyrighted to me and not them, so if there is stuff that is missing or they deleted I will shit a brick. If I can get them, I will publish them. I used a lot of them for a custom distro (CentOS) that we used and created all of the tools and features that ubuntuwire.com has for the custom distro. Python RPM is a pita. I wrote docs for it as well and I will try to get all of that too. Thanks for reminding me
#4 by Dennis on May 23, 2009 - 11:47 am
Quote
The ‘createrepo’ application also deals with rpms. Especially the older versions in debian/ubuntu are good sources for learning to use this horrible thing
#5 by sharms on May 23, 2009 - 12:06 pm
Quote
Dennis – yeah the problem is createrepo doesn’t deal with SUSE patch / delta rpms, there is a separate tool needed to generate that data, so thats when I went to grab python-rpm and try and solve it.
#6 by Rahul Sundaram on May 23, 2009 - 6:11 pm
Quote
Shams,
The createrepo in Fedora 11 actually can generate deltarpms. Feel free to take a look. The developer who wrote the originally bindings is no longer with Red Hat and yes, there is a lack of good documentation in there but yum source code is a valuable starting point. There is a effort to rewrite the python bindings for RPM as well
Direct your questions to
http://lists.rpm.org/pipermail/rpm-python/
#7 by puzzled on December 3, 2009 - 3:24 pm
Quote
If you’re going to publish helpful code for people to use, it might be worth doing so in a way that people can readily extract it. You posted a screenshot FFS!