diff --git a/pym/gentoolkit/eclean/clean.py b/pym/gentoolkit/eclean/clean.py index 87d7aaca..b6f96cf2 100644 --- a/pym/gentoolkit/eclean/clean.py +++ b/pym/gentoolkit/eclean/clean.py @@ -5,6 +5,7 @@ import os +import shutil import sys import gentoolkit.pprinter as pp @@ -23,7 +24,7 @@ def __init__(self, controller, quiet): self.controller = controller self.quiet = quiet - def clean_dist(self, clean_dict): + def clean_dist(self, clean_dict, git): """Calculate size of each entry for display, prompt user if needed, delete files if approved and return the total size of files that have been deleted. @@ -39,6 +40,7 @@ def clean_dist(self, clean_dict): for key in sorted(clean_dict): clean_size += self._clean_files(clean_dict[key], key, file_type) # return total size of deleted or to delete files + clean_size += self._clean_git_src(git) return clean_size def clean_pkgs(self, clean_dict, pkgdir): @@ -148,3 +150,22 @@ def _clean_files(self, files, key, file_type): print(pp.error("Could not delete " + file_), file=sys.stderr) print(pp.error("Error: %s" % str(er)), file=sys.stderr) return clean_size + + def _clean_git_src(self, deprecated_git): + clean_size = 0 + for checkout in deprecated_git: + try: + statinfo = os.stat(checkout) + except OSError as er: + print( + pp.error("Could not get stat info for:" + checkout), + file=sys.stderr, + ) + print(pp.error("Error: %s" % str(er)), file=sys.stderr) + try: + shutil.rmtree(checkout) + clean_size += statinfo.st_size + except OSError as er: + print(pp.error("Could not delete " + checkout), file=sys.stderr) + print(pp.error("Error: %s" % str(er)), file=sys.stderr) + return clean_size diff --git a/pym/gentoolkit/eclean/cli.py b/pym/gentoolkit/eclean/cli.py index b180641b..eecaa00a 100644 --- a/pym/gentoolkit/eclean/cli.py +++ b/pym/gentoolkit/eclean/cli.py @@ -13,25 +13,25 @@ __productname__ = "eclean" __description__ = "A cleaning tool for Gentoo distfiles and binaries." +import getopt import os -import sys import re +import sys import time -import getopt import portage -from portage.output import white, yellow, turquoise, green, red +from portage.output import green, red, turquoise, white, yellow import gentoolkit.pprinter as pp +from gentoolkit.eclean.clean import CleanUp +from gentoolkit.eclean.exclude import ParseExcludeFileException, parseExcludeFile +from gentoolkit.eclean.output import OutputControl from gentoolkit.eclean.search import ( DistfilesSearch, findPackages, - port_settings, pkgdir, + port_settings, ) -from gentoolkit.eclean.exclude import parseExcludeFile, ParseExcludeFileException -from gentoolkit.eclean.clean import CleanUp -from gentoolkit.eclean.output import OutputControl # from gentoolkit.eclean.dbapi import Dbapi from gentoolkit.eprefix import EPREFIX @@ -567,7 +567,7 @@ def doAction(action, options, exclude={}, output=None): # portdb=Dbapi(portage.db[portage.root]["porttree"].dbapi), # var_dbapi=Dbapi(portage.db[portage.root]["vartree"].dbapi), ) - clean_me, saved, deprecated = engine.findDistfiles( + clean_me, saved, deprecated, git = engine.findDistfiles( exclude=exclude, destructive=options["destructive"], fetch_restricted=options["fetch-restricted"], @@ -581,7 +581,7 @@ def doAction(action, options, exclude={}, output=None): cleaner = CleanUp(output.progress_controller, options["quiet"]) # actually clean files if something was found - if clean_me: + if clean_me or git: # verbose pretend message if options["pretend"] and not options["quiet"]: output.einfo("Here are the " + files_type + " that would be deleted:") @@ -592,7 +592,7 @@ def doAction(action, options, exclude={}, output=None): if options["pretend"]: clean_size = cleaner.pretend_clean(clean_me) elif action in ["distfiles"]: - clean_size = cleaner.clean_dist(clean_me) + clean_size = cleaner.clean_dist(clean_me, git) elif action in ["packages"]: clean_size = cleaner.clean_pkgs(clean_me, pkgdir) # vocabulary for final message diff --git a/pym/gentoolkit/eclean/search.py b/pym/gentoolkit/eclean/search.py index a2ac0ce4..ac983e8e 100644 --- a/pym/gentoolkit/eclean/search.py +++ b/pym/gentoolkit/eclean/search.py @@ -16,13 +16,12 @@ import gentoolkit.pprinter as pp from gentoolkit.eclean.exclude import ( - exclDictMatchCP, exclDictExpand, exclDictExpandPkgname, + exclDictMatchCP, exclMatchFilename, ) - # Misc. shortcuts to some portage stuff: port_settings = portage.settings pkgdir = port_settings["PKGDIR"] @@ -148,7 +147,8 @@ def findDistfiles( + "%s remaining candidates to clean" % len(clean_me) ) clean_me, saved = self._check_excludes(exclude, clean_me) - return clean_me, saved, deprecated + git = self.git_check(_distdir) + return clean_me, saved, deprecated, git # begin _check_limits code block @@ -332,6 +332,17 @@ def _non_destructive( deprecated.update(_deprecated) return pkgs, deprecated + def git_check(self, distdir): + cpvs = [ + i.split("/")[1][:-5] for i in set(self.vardb.cpv_all()) if i[-5:] == "-9999" + ] + git_src = os.path.join(distdir, "git3-src") + gitdir = dict(map(lambda i: (i.split("_")[1][:-4], i), os.listdir(git_src))) + deprecated_git = [ + os.path.join(git_src, gitdir[i]) for i in gitdir.keys() if i not in cpvs + ] + return deprecated_git + def _fetch_restricted(self, pkgs_, cpvs): """perform fetch restricted non-destructive source filename lookups