Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Clean out this old unsloted packages
View unanswered posts
View posts from last 24 hours

Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message

Joined: 02 Jun 2002
Posts: 1978
Location: Rennes, France

PostPosted: Mon Jul 21, 2003 2:01 pm    Post subject: Clean out this old unsloted packages Reply with quote

My gentoo instalation is ~18 months old, and at this time there were no SLOT in portage. The consequence is that I have still a lot of old package version that are not cleaned by "emerge clean", because it would be unsafe to clean a package without knowing to which slot it belongs to.

But I've found a (I think safe) solution: I've written a small script to guess what the slot of this packages should be, and fill their empty /var/db/pkg/category/package-ver/SLOT file. This way, after running this script, most of them (which have installed updates in the same slot) will be cleaned.

Here is the piece of python code I've used to guess the right slot for a package:
#!/usr/bin/env python2.2

import sys,os,portage,string

def get_slot(pkg):
   #<cat/pkg-ver> expected
      return portage.db["/"]["porttree"].dbapi.aux_get(pkg,["SLOT"])
   except KeyError:

def get_closest_slot(pkg):
   #<cat/pkg-ver> expected
   #list the available (visibles) pkgs
   #in case the pkg has been (re)moved
   if not len(fulllist):
      #then zero is not worst than something else
      return 0
   #keep only pkgs >= to pkg:
   okaylist=filter((lambda p: portage.pkgcmp(portage.catpkgsplit(pkg)[1:],portage.catpkgsplit(p)[1:]) <= 0),fulllist)
   #sort by version
   okaylist.sort(lambda p1,p2: portage.pkgcmp(portage.catpkgsplit(p1)[1:],portage.catpkgsplit(p2)[1:]))
   # return a reasonable slot
   if len(okaylist):
      #the slot we want is the one of the first element
      return get_slot(okaylist[0])[0]
      #for safety, we return nothing.
      #return get_slot([0]
      return ""

def main():
   if not (len(sys.argv) == 2):
   print get_closest_slot(sys.argv[1])


Save it somewhere (for instance /root/bin/, and try:
> /root/bin/ media-gfx/gimp-1.2.0
> /root/bin/ media-gfx/gimp-1.3.0
> /root/bin/ media-gfx/gimp-1.5.0

> /root/bin/ media-gfx/gump-1.2.0

Most of time, it will return, for cat/pkg-ver1, the slot of the first cat/pkg-ver2 package available in portage such that ver1<=ver2. If the package is in portage but there is no such version (gimp-1.5), then it returns nothing. If the package is not in portage (gump-1.2), it returns 0, but we don't really care.

Now, we can give slots to packages which don't have one. First, let's see if there is any:
> find /var/db/pkg -type f -name SLOT -exec grep -H --label={} "^\ *$" {} \; | awk -F/ '{ print $5"/"$6 }'

(We've looked for packages with an empty SLOT file in the installed packages db.)
Any results? Then save (for instance to /root/bin/ the following script:
for p in $( find /var/db/pkg \
      -type f \
      -name SLOT \
      -exec grep -H --label={} "^\ *$" {} \; \
         | awk -F/ '{ print $5"/"$6 }' )
   echo -n "${p}: "
   pslot="`$SLOT_SCRIPT $p`"
   echo "${pslot}"
   echo ${pslot} > /var/db/pkg/${p}/SLOT
Run it (with no argument), and it should fill the empty SLOT files.

That's it. An "emerge -p clean" will show you which old packages can now be cleaned.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum