TGL Bodhisattva
Joined: 02 Jun 2002 Posts: 1978 Location: Rennes, France
|
Posted: Mon Jul 21, 2003 2:01 pm Post subject: Clean out this old unsloted packages |
|
|
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: Code: | #!/usr/bin/env python2.2
import sys,os,portage,string
def get_slot(pkg):
#<cat/pkg-ver> expected
try:
return portage.db["/"]["porttree"].dbapi.aux_get(pkg,["SLOT"])
except KeyError:
sys.exit(1)
def get_closest_slot(pkg):
#<cat/pkg-ver> expected
#list the available (visibles) pkgs
psplit=portage.catpkgsplit(pkg)
fulllist=portage.db["/"]["porttree"].dbapi.match(psplit[0]+"/"+psplit[1])
#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]
else:
#for safety, we return nothing.
#return get_slot(portage.best(fulllist))[0]
return ""
def main():
if not (len(sys.argv) == 2):
sys.exit(1)
print get_closest_slot(sys.argv[1])
sys.exit(0)
main() |
Save it somewhere (for instance /root/bin/closest-slot.py), and try: Code: | > /root/bin/closest-slot.py media-gfx/gimp-1.2.0
1.2
> /root/bin/closest-slot.py media-gfx/gimp-1.3.0
1.4
> /root/bin/closest-slot.py media-gfx/gimp-1.5.0
> /root/bin/closest-slot.py media-gfx/gump-1.2.0
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: Code: | > 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/slot-them-all.sh) the following script: Code: | #!/bin/bash
SLOT_SCRIPT=/root/bin/closest-slot.py
for p in $( find /var/db/pkg \
-type f \
-name SLOT \
-exec grep -H --label={} "^\ *$" {} \; \
| awk -F/ '{ print $5"/"$6 }' )
do
echo -n "${p}: "
pslot="`$SLOT_SCRIPT $p`"
echo "${pslot}"
echo ${pslot} > /var/db/pkg/${p}/SLOT
done | 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. |
|