Here's a rough Python script I slapped together to do the same thing.  Note that I'm 
testing on Windows, but I can't see why there'd be any problems when you run it under 
Gentoo.  Again, very rough, YMMV.

#! /usr/bin/env python
"""Remove outdated tarballs from portage's distfiles directory."""

import os
import string

DISTFILES_DIR = 'h:\distfiles\\'

all_files = os.listdir( DISTFILES_DIR )
by_name = [ string.split( filename, '-', 1 ) for filename in all_files ]
pkg_dict = {}
for pkg in by_name:
    if not pkg_dict.has_key( pkg[ 0 ] ):
        pkg_dict[ pkg[ 0 ] ] = []
    pkg_dict[ pkg[0] ].append( pkg[ 1 ] )
for pkg_name, version_list in pkg_dict.items():
    version_list.sort()
    version_list.pop()
    for version in version_list:
        full_filename = DISTFILES_DIR + pkg_name + "-" + version
        print "Removing", full_filename, "...",
        os.remove( full_filename )
        print "done."

Doug Gorley | [EMAIL PROTECTED]


----- Original Message -----
From: Andy Arbon <[EMAIL PROTECTED]>
Date: Monday, March 24, 2003 1:39 pm
Subject: [gentoo-user] Disk space && managing package binaries

> Hello,
> 
> Related to my recent question on gentoo-user regarding freeing up 
> disk 
> space, I've just written a short bash script that helps tidying up 
> the 
> binary packages that portage builds (see below).
> 
> All it does it take each file in the distfiles and packages 
> directories 
> and use qpkg to see if the package that built/came from it is 
> currently 
> installed. If it isn't then it's removed.
> 
> There are obviously shortcomings with this, but as a rough tool it 
> works. One problem is that if you have a package like rsync-1.2.3 
> and 
> rsync-1.2.3-r1 then rsync-1.2.3 won't get removed until the system 
> gets 
> upgraded to rsync-1.2.4, as (AFAIK) there's no way to specify 
> end-of-string in a query to qpkg (am I wrong about this?)
> 
> At the moment it moves packages into a subdirectory ready to be 
> removed 
> but doesn't actually remove them.
> 
> Any comments on this?
> 
> Cheers,
> 
> Andy
> 
> #!/bin/bash
> # Clean out of date packages and distfiles out
> 
> PPATH="/usr/portage/packages/All"
> DPATH="/usr/portage/distfiles"
> FILELIST=`find $PPATH| sed -e \
> 's/.*\/\(.*\)\.\(tar.bz2$\|zip\|tar.gz$\|tbz2\|bz2\|gz\)$/\1/g' -e 
> '1d'`
> if [[ -z "$PPATH/../old" ]];
>     then mkdir "$PPATH/../old"
> fi
> 
> for file in $FILELIST; do
>     echo -n "Testing $file    "
>     if [[ ! `qpkg -I $file` ]];
>       then mv $PPATH/$file* $PPATH/../old/
>       echo "... removing";
>     else echo
>     fi
> done
> 
> # Now we do the distfiles
> FILELIST=`find $DPATH| sed -e \
> 's/.*\/\(.*\)\.\(tar.bz2$\|zip\|tar.gz$\|tbz2\|bz2\|gz\|exe\|wsz\|tgz\|patch\|bin\|tar.Z\)$/\1/g'
>  
> -e '1d'`
> 
> if [[ -z "$DPATH/../old" ]];
>     then mkdir "$DPATH/../old"
> fi
> 
> for file in $FILELIST; do
>     echo -n "Testing $file    "
>     if [[ ! `qpkg -I $file` ]];
>       then mv $DPATH/$file* $DPATH/../old/
>       echo "... removing";
>     else echo
>     fi
> done
> 
> 
> --
> [EMAIL PROTECTED] mailing list
> 
> 


--
[EMAIL PROTECTED] mailing list

Reply via email to