Looking for more info

"Adam T. Gautier" <adam_gautier-/[email protected]> Sat, 20 Mar 2004 11:13:39 -0500
Newsgroups gmane.linux.redhat.rpm.python
Message-ID <[email protected]>
> It's not a lot of code to do that, though. What else do you want to do
> besides rpm -e?

I want to have a python script that I can run to remove all packages that do not have dependencies(with some human interaction).  I am trying to get rid of packages that are not needed for an install on old laptop.  It has a very small harddrive and I am looking to eliminate the packages that are not needed and have the machine be a dedicated DVD burner using an external DVD burner and the internal DVD drive.  To do this I need as much HD space as possible.  I have the minimum Fedora install that I could install from CDROM but there are still a ton of packages that I just don't need. I know that this could get done faster using the rpm app on the commandline but I am also just trying to learn the basics of rpm-python to write some administrative scripts.

So, what I want to do is iterate the list of installed packages and then propt the user for removal, giving the user the header information and dependency information.  If the user chooses to remove the package then a cascading removal of all packages in the dependency chain is executed.  So using the example below I want to delete foo and have it in turn delete all dependant packages.

EXAMPLE DEPENDECY:

~> sudo rpm -e foo
error: Failed dependencies:
        grep is needed by (installed) ash-0.3.8-15
        grep is needed by (installed) logwatch-4.3.2-2.1
        grep is needed by (installed) irda-utils-0.9.15-1.1
        grep is needed by (installed) bc-1.06-15.1
        grep is needed by (installed) tcsh-6.12-5
        grep is needed by (installed) docbook-dtds-1.0-22.1
        grep is needed by (installed) gphoto2-2.1.3-1
        grep is needed by (installed) XFree86-libs-4.3.0-55
        /bin/grep is needed by (installed) sane-backends-1.0.12-4


> import rpm
> ts = rpm.TransactionSet()
> ts.addErase('pkgname')
> ts.run(callback=my_install_callback_instance)

> you need the callback but you can steal that from all over. 

Great, it took about an hour for me to hack out an RPM class that erased the tuxracer rpm on my development box, still trying to figure out how to iterate and cascade down the dependecy tree.  Thanks!  I also grabbed the callback class from YUM (Thanks again). I am not sure what the variables "(self, what, bytes, total, h, user)" in the callback function are for (I have a general idea based on the code), I am going to search the net for more info.  If anyone knows where the complete listing of say the "what" variable is/does as well as all the constants like "rpm.RPMCALLBACK_TRANS_START" means I will compile it into some documentation and post it on the web in one place.  Any help with this would be great.

Ok.  so now for the next step of my project how to I iterate all of the installed packages and get their dependencies?