-#!/usr/bin/env python
+#!/usr/bin/python
# Copyright 2003-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $
+from __future__ import with_statement
###############################################################################
# Meta:
###############################################################################
# Python imports:
+
import sys
import os, stat
import re
distdir = port_settings["DISTDIR"]
pkgdir = port_settings["PKGDIR"]
-
###############################################################################
# printVersion:
def printVersion():
# findDistfiles: find all obsolete distfiles.
# XXX: what about cvs ebuilds? i should install some to see where it goes...
def findDistfiles( \
+ myoptions, \
exclude_dict={}, \
destructive=False,\
fetch_restricted=False, \
package_names=False, \
time_limit=0, \
- size_limit=0):
+ size_limit=0,):
# this regexp extracts files names from SRC_URI. It is not very precise,
# but we don't care (may return empty strings, etc.), since it is fast.
file_regexp = re.compile('([a-zA-Z0-9_,\.\-\+\~]*)[\s\)]')
except KeyError: continue
del pkg_list
- # create a dictionary of files which should be deleted
+ # create a dictionary of files which should be deleted
+ if not (os.path.isdir(distdir)):
+ eerror("%s does not appear to be a directory." % distdir, myoptions['nocolor'])
+ eerror("Please set DISTDIR to a sane value.", myoptions['nocolor'])
+ eerror("(Check your /etc/make.conf and environment).", myoptions['nocolor'])
+ exit(1)
for file in os.listdir(distdir):
filepath = os.path.join(distdir, file)
try: file_stat = os.stat(filepath)
# XXX: packages are found only by symlinks. Maybe i should also return .tbz2
# files from All/ that have no corresponding symlinks.
def findPackages( \
+ myoptions, \
exclude_dict={}, \
destructive=False, \
time_limit=0, \
package_names=False):
clean_dict = {}
- # create a full package dictionnary
+ # create a full package dictionary
+
+ if not (os.path.isdir(pkgdir)):
+ eerror("%s does not appear to be a directory." % pkgdir, myoptions['nocolor'])
+ eerror("Please set PKGDIR to a sane value.", myoptions['nocolor'])
+ eerror("(Check your /etc/make.conf and environment).", myoptions['nocolor'])
+ exit(1)
for root, dirs, files in os.walk(pkgdir):
if root[-3:] == 'All': continue
for file in files:
del clean_dict[mycpv]
continue
if portage.cpv_getkey(mycpv) in cp_all:
- # exlusion because of --package-names
+ # exlusion because of --package-names
del clean_dict[mycpv]
return clean_dict
"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
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
einfo("Building file list for "+action+" cleaning...", \
myoptions['nocolor'])
if action == 'packages':
- clean_dict = findPackages( \
+ clean_dict = findPackages(
+ myoptions, \
exclude_dict=exclude_dict, \
destructive=myoptions['destructive'], \
package_names=myoptions['package-names'], \
time_limit=myoptions['time-limit'])
else:
clean_dict = findDistfiles( \
+ myoptions, \
exclude_dict=exclude_dict, \
destructive=myoptions['destructive'], \
fetch_restricted=myoptions['fetch-restricted'], \