Re: Looking for more info
seth vidal <skvidal-c/MNwgJ9CEH2fBVCVOL8/[email protected]> Sat, 20 Mar 2004 12:33:10 -0500
| Newsgroups | gmane.linux.redhat.rpm.python |
|---|---|
| Message-ID | <1079803989.12516.1.camel@binkley> |
On Sat, 2004-03-20 at 11:13 -0500, Adam T. Gautier wrote: > > 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. > This script was posted to [email protected] by Panu Matilainen: #!/usr/bin/python import rpm ts = rpm.TransactionSet() req = {} orphan = [] for h in ts.dbMatch(): name = h['name'] if not h[rpm.RPMTAG_REQUIRENAME]: continue for r in h[rpm.RPMTAG_REQUIRENAME]: req[r] = name for h in ts.dbMatch(): name = h['name'] preq = 0 for p in h[rpm.RPMTAG_PROVIDES] + h[rpm.RPMTAG_FILENAMES]: if req.has_key(p): preq = preq + 1 if preq == 0: orphan.append(name) orphan.sort() for name in orphan: print orphan it returns a simple list of packages that nothing requires. -sv