Skip to content

Commit

Permalink
Enhancement: eclean-dist should additionally handle git checkouts in …
Browse files Browse the repository at this point in the history
…/git3-src

Bug: https://bugs.gentoo.org/622938

Signed-off-by: Siddhanth Rathod <[email protected]>
  • Loading branch information
hyprsyd committed Sep 21, 2023
1 parent 5146d35 commit 8a637ef
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 14 deletions.
23 changes: 22 additions & 1 deletion pym/gentoolkit/eclean/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@


import os
import shutil
import sys

import gentoolkit.pprinter as pp
Expand All @@ -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.
Expand All @@ -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):
Expand Down Expand Up @@ -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
20 changes: 10 additions & 10 deletions pym/gentoolkit/eclean/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"],
Expand All @@ -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:")
Expand All @@ -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
Expand Down
19 changes: 16 additions & 3 deletions pym/gentoolkit/eclean/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -332,6 +332,19 @@ 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 "live" in self.vardb.aux_get(i, ["PROPERTIES"])
]
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
Expand Down

0 comments on commit 8a637ef

Please sign in to comment.