Gentoo Archives: gentoo-commits

From: Yixun Lan <dlan@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/gentoolkit:master commit in: pym/gentoolkit/eclean/
Date: Sat, 28 May 2022 15:28:06
Message-Id: 1653751472.2fffbd450df2443bbd671f7ec760051ce3c930e9.dlan@gentoo
1 commit: 2fffbd450df2443bbd671f7ec760051ce3c930e9
2 Author: Yixun Lan <dlan <AT> gentoo <DOT> org>
3 AuthorDate: Wed May 25 08:08:09 2022 +0000
4 Commit: Yixun Lan <dlan <AT> gentoo <DOT> org>
5 CommitDate: Sat May 28 15:24:32 2022 +0000
6 URL: https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=2fffbd45
7
8 implement --unique-use option for eclean-pkg
9
10 this will help to clean duplicated binpkg which has exact same USEs flags enabled,
11 and it will choose the more recent version according to BUILD_TIME by default
12
13 Closes: https://bugs.gentoo.org/727576
14 Closes: https://github.com/gentoo/gentoolkit/pull/20
15 Signed-off-by: Yixun Lan <dlan <AT> gentoo.org>
16
17 pym/gentoolkit/eclean/cli.py | 14 +++++++++++++-
18 pym/gentoolkit/eclean/search.py | 26 ++++++++++++++++++++++++++
19 2 files changed, 39 insertions(+), 1 deletion(-)
20
21 diff --git a/pym/gentoolkit/eclean/cli.py b/pym/gentoolkit/eclean/cli.py
22 index 2ad2ae9..c129d5e 100644
23 --- a/pym/gentoolkit/eclean/cli.py
24 +++ b/pym/gentoolkit/eclean/cli.py
25 @@ -252,6 +252,11 @@ def printUsage(_error=None, help=None):
26 + " - ignore failure to locate PKGDIR",
27 file=out,
28 )
29 + print(
30 + yellow(" -u, --unique-use")
31 + + " - keep unique packages which have no duplicated USE",
32 + file=out,
33 + )
34 print(file=out)
35 if _error in ("distfiles-options", "merged-distfiles-options") or help in (
36 "all",
37 @@ -392,6 +397,8 @@ def parseArgs(options={}):
38 options["changed-deps"] = True
39 elif o in ("-i", "--ignore-failure"):
40 options["ignore-failure"] = True
41 + elif o in ("--unique-use"):
42 + options["unique-use"] = True
43 else:
44 return_code = False
45 # sanity check of --deep only options:
46 @@ -431,7 +438,11 @@ def parseArgs(options={}):
47 getopt_options["short"]["distfiles"] = "fs:"
48 getopt_options["long"]["distfiles"] = ["fetch-restricted", "size-limit="]
49 getopt_options["short"]["packages"] = "i"
50 - getopt_options["long"]["packages"] = ["ignore-failure", "changed-deps"]
51 + getopt_options["long"]["packages"] = [
52 + "ignore-failure",
53 + "changed-deps",
54 + "unique-use",
55 + ]
56 # set default options, except 'nocolor', which is set in main()
57 options["interactive"] = False
58 options["pretend"] = False
59 @@ -446,6 +457,7 @@ def parseArgs(options={}):
60 options["verbose"] = False
61 options["changed-deps"] = False
62 options["ignore-failure"] = False
63 + options["unique-use"] = False
64 # if called by a well-named symlink, set the action accordingly:
65 action = None
66 # temp print line to ensure it is the svn/branch code running, etc..
67
68 diff --git a/pym/gentoolkit/eclean/search.py b/pym/gentoolkit/eclean/search.py
69 index cb695c0..365970c 100644
70 --- a/pym/gentoolkit/eclean/search.py
71 +++ b/pym/gentoolkit/eclean/search.py
72 @@ -560,6 +560,7 @@ def findPackages(
73 # Dictionary of binary packages to clean. Organized as cpv->[pkgs] in order
74 # to support FEATURES=binpkg-multi-instance.
75 dead_binpkgs = {}
76 + keep_binpkgs = {}
77
78 bin_dbapi = portage.binarytree(pkgdir=pkgdir, settings=var_dbapi.settings).dbapi
79 for cpv in bin_dbapi.cpv_all():
80 @@ -575,6 +576,28 @@ def findPackages(
81 if mtime >= time_limit:
82 continue
83
84 + # Exclude if binpkg has exact same USEs
85 + if not destructive and options["unique-use"]:
86 + keys = ("CPV", "EAPI", "USE")
87 + binpkg_metadata = dict(zip(keys, bin_dbapi.aux_get(cpv, keys)))
88 + cpv_key = "_".join(binpkg_metadata[key] for key in keys)
89 + if cpv_key in keep_binpkgs:
90 + old_cpv = keep_binpkgs[cpv_key]
91 + # compare BUILD_TIME, keep the new one
92 + old_time = int(bin_dbapi.aux_get(old_cpv, ["BUILD_TIME"])[0])
93 + new_time = int(bin_dbapi.aux_get(cpv, ["BUILD_TIME"])[0])
94 + drop_cpv = old_cpv if new_time >= old_time else cpv
95 +
96 + binpkg_path = bin_dbapi.bintree.getname(drop_cpv)
97 + dead_binpkgs.setdefault(drop_cpv, []).append(binpkg_path)
98 +
99 + if new_time >= old_time:
100 + keep_binpkgs[cpv_key] = cpv
101 + else:
102 + continue
103 + else:
104 + keep_binpkgs[cpv_key] = cpv
105 +
106 # Exclude if binpkg exists in the porttree and not --deep
107 if not destructive and port_dbapi.cpv_exists(cpv):
108 if not options["changed-deps"]:
109 @@ -605,6 +628,9 @@ def findPackages(
110 if buildtime == bin_dbapi.aux_get(cpv, ["BUILD_TIME"])[0]:
111 continue
112
113 + if not destructive and options["unique-use"]:
114 + del keep_binpkgs[cpv_key]
115 +
116 binpkg_path = bin_dbapi.bintree.getname(cpv)
117 dead_binpkgs.setdefault(cpv, []).append(binpkg_path)