--- eclean (revision 576) +++ eclean (working copy) @@ -1,9 +1,8 @@ -#!/usr/bin/env python +#!/usr/bin/python # Copyright 2003-2005 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Header: $ - ############################################################################### # Meta: __author__ = "Thomas de Grenier de Latour (tgl)" @@ -22,6 +21,7 @@ import getopt import fpformat import signal +from __future__ import with_statement try: import portage except ImportError: @@ -678,7 +678,12 @@ "Do you want to delete this " \ + file_type+"?"): # non-interactive mode or positive answer. - # For each file,... + # For each file, try to delete the file and clean it out + # of Packages metadata file + if action == 'packages': + metadata = portage.getbinpkg.PackageIndex() + with open(os.path.join(pkgdir, 'Packages')) as metadata_file: + metadata.read(metadata_file) for file in clean_dict[mykey]: # ...get its size... filesize = 0 @@ -688,11 +693,21 @@ except: eerror("Could not read size of "\ +file, myoptions['nocolor']) # ...and try to delete it. - try: os.unlink(file) - except: eerror("Could not delete "+file, \ - myoptions['nocolor']) + try: + os.unlink(file) + except: + eerror("Could not delete "+file, \ + myoptions['nocolor']) # only count size if successfully deleted - else: clean_size += filesize + else: + clean_size += filesize + if action == 'packages': + metadata.packages[:] = [p for p in metadata.packages if 'CPV' in p and p['CPV'] != file] + + if action == 'packages': + with open(os.path.join(pkgdir, 'Packages'), 'w') as metadata_file: + metadata.write(metadata_file) + # return total size of deleted or to delete files return clean_size