Bjoern Olausson

Obsolete packages PDF Print E-mail
  
Friday, 09 November 2007 15:05
Portage magic: Identify obsolete packages

Gentoo developer Brian Harring designed a clever way to identify all merged versions of packages not available in Portage anymore -- both the official tree and packages from PORTDIR_OVERLAY. Here is the method he came up with, packing as much Python neatness as fits on a single command line

Code Listing 8.1: Python scriptlet #1

python -c 'import portage; print [x for x in portage.db["/"]["vartree"].getallcpv() \
if len(portage.portdb.xmatch("match-all","="+x))==0]'

If that just went a little over your head, let's look at what exactly it does. For example, if a package, say, foo-1.2.3 is merged, and that version 1.2.3 is no longer in the tree, the script will point it out. A simple check for packages that aren't available any longer regardless of versions, would look like this:

Code Listing 8.2: Python scriptlet #2

python -c 'import portage; print [x for x in portage.db["/"]["vartree"].getallcpv() \
if len(portage.portdb.xmatch("match-all",portage.pkgsplit(x)[0]))==0]'


Finally, if you want to ignore package foo-1.2.3 even if it isn't in the tree any longer, but a revision foo-1.2.3-r1 is, the following script will ignore the package, only triggering on installed applications that have completely vanished from Portage.

Code Listing 8.3: Python scriptlet #3

python -c 'import portage; print [x for x in portage.db["/"]["vartree"].getallcpv() \
if len(portage.portdb.xmatch("match-all","~"+"-".join(portage.pkgsplit(x)[:2])))==0]'

Lastly, none of the above take injected packages into consideration, only those that were installed from an available tree. Now, suppose you'd like to ignore those, too, here's what to do:

Code Listing 8.4: Python scriptlet #4

python -c 'import portage; print [x for x in portage.db["/"]["vartree"].getallcpv() \
if len(portage.portdb.xmatch("match-all",portage.pkgsplit(x)[0]))==0 \
and not portage.db["/"]["vartree"].dbapi.isInjected(x)]'

Yes, we knew you'd like this. All of the above do work for individual packages you keep in an overlay tree, for example at /usr/local/portage, those are being evaluated along with packages in the official Portage tree. Try it out, you can't break anything, it just notifies you about whatever it finds, leaving it up to the user to decide what to do with that information.

Snipped from Gentoo Weekly Newsletter: February 14th, 2005
 

Add comment


Security code
Refresh