TGL Bodhisattva
Joined: 02 Jun 2002 Posts: 1978 Location: Rennes, France
|
Posted: Wed Jul 23, 2003 1:08 am Post subject: Update slotted packages |
|
|
If you have some slotted packages in multiple versions installed (for instance, I had gimp-1.2.3-r2 in slot 1.2 and gimp-1.3.16 in slot 1.4), then "emerge -u world" only updates the one of the greater version (gimp-1.3.16), and ignores the one in the old slot. I've written a small script which helps updating this forgot versions.
First, you to save need this python script somewhere (/root/bin/best-in-same-slot.py for me): 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 best_in_same_slot(pkg):
#<cat/pkg-ver> expected
#list the available pkgs
psplit=portage.catpkgsplit(pkg)
fulllist=portage.db["/"]["porttree"].dbapi.match(psplit[0]+"/"+psplit[1])
pkgslot=[]
#we first try to get the slot of the package as installed
if os.access("/var/db/pkg/"+pkg+"/SLOT",os.R_OK):
pkgslotf=open("/var/db/pkg/"+pkg+"/SLOT","r")
pkgslot=string.split(pkgslotf.readline())
pkgslotf.close()
#if we've failed, we try in the portage tree
if not len(pkgslot):
#keep only pkgs >= to pkg
okaylist=filter((lambda p: portage.pkgcmp(psplit[1:],portage.catpkgsplit(p)[1:]) <= 0),fulllist)
#if no match, we quit
if not len(okaylist):
return ""
#if there are some matching package,
#we keep the slot of the first one
okaylist.sort(lambda p1,p2: portage.pkgcmp(portage.catpkgsplit(p1)[1:],portage.catpkgsplit(p2)[1:]))
pkgslot=get_slot(okaylist[0])
#no we have a slot, lets keep only matching pkgs
okaylist=filter((lambda p: get_slot(p) == pkgslot),fulllist)
#if no match, we quit
if not len(okaylist):
return ""
#return the best matching pkg
return portage.best(okaylist)
def main():
if not (len(sys.argv) == 2):
#print "ERROR: exactly 1 arg is needed"
sys.exit(1)
bestversion=best_in_same_slot(sys.argv[1])
if len(bestversion):
print bestversion
sys.exit(0)
main() |
You can test it like this: Code: | # cd /root/bin
# ./best-in-same-slot.py media-gfx/gimp-1.3.16
media-gfx/gimp-1.3.16
# ./best-in-same-slot.py media-gfx/gimp-1.2.3-r2
media-gfx/gimp-1.2.5-r1 |
Then, you can use the following bash script to find packages in multiple slots which have availables updates (it's called /root/bin/updates-in-slots.sh for me): Code: | #!/bin/bash
BESTPKG_SCRIPT="/root/bin/best-in-same-slot.py"
for dbp in $( find /var/db/pkg/ -mindepth 2 -maxdepth 2 -type d \
| sed s:"-[0-9].*":: | uniq -d )
do
for dbpv in ${dbp}-*
do
pv="`echo ${dbpv} | sed s:/var/db/pkg/::`"
bestpv="`${BESTPKG_SCRIPT} ${pv}`"
[ -z ${bestpv} ] || [ ${bestpv} == ${pv} ] || echo "=${bestpv}"
done
done | sort -u |
It will output a list of multiple-versions-installed packages which have updates in their slots: Code: | #./updates-in-slots.sh
=dev-util/glade-0.6.4
=media-gfx/gimp-1.2.5
=net-www/links-0.96-r2 |
You can now easily feed emerge with this output to update what portage has missed: Code: | # emerge -pv $( ./updates-in-slots.sh ) |
And that's it. |
|