1 |
commit: 1952ecb9f2912968dd2f4487089fa50ed3d3bad1 |
2 |
Author: Zac Medico <zmedico <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sat Jun 25 23:55:33 2016 +0000 |
4 |
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> |
5 |
CommitDate: Fri Jul 1 06:18:27 2016 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=1952ecb9 |
7 |
|
8 |
eclean: optimize binpkg-multi-instance support from bug 586658 |
9 |
|
10 |
Use the portage binarytree API to optimize binary package access, |
11 |
so that metadata is read from $PKGDIR/Packages instead of from the |
12 |
individual binary packages. Symlinks will now be ignored, since |
13 |
portage hasn't used symlinks for years, and there's no harm |
14 |
in ignoring them now. The APIs used are compatible with very old |
15 |
portage, though they internally support binpkg-multi-instance |
16 |
in recent versions of portage. |
17 |
|
18 |
X-Gentoo-bug: 586658 |
19 |
X-Gentoo-bug-url: https://bugs.gentoo.org/show_bug.cgi?id=586658 |
20 |
|
21 |
pym/gentoolkit/eclean/search.py | 47 +++++++++++++++++++---------------------- |
22 |
1 file changed, 22 insertions(+), 25 deletions(-) |
23 |
|
24 |
diff --git a/pym/gentoolkit/eclean/search.py b/pym/gentoolkit/eclean/search.py |
25 |
index ce796f5..b9d111a 100644 |
26 |
--- a/pym/gentoolkit/eclean/search.py |
27 |
+++ b/pym/gentoolkit/eclean/search.py |
28 |
@@ -538,29 +538,20 @@ def findPackages( |
29 |
print( pp.error("(Check your make.conf file and environment)."), file=sys.stderr) |
30 |
print( pp.error("Error: %s" %str(er)), file=sys.stderr) |
31 |
exit(1) |
32 |
- for root, dirs, files in os.walk(pkgdir): |
33 |
- if root[-3:] == 'All': |
34 |
+ |
35 |
+ # if portage supports FEATURES=binpkg-multi-instance, then |
36 |
+ # cpv_all can return multiple instances per cpv, where |
37 |
+ # instances are distinguishable by some extra attributes |
38 |
+ # provided by portage's _pkg_str class |
39 |
+ bin_dbapi = portage.binarytree(pkgdir=pkgdir, settings=var_dbapi.settings).dbapi |
40 |
+ for cpv in bin_dbapi.cpv_all(): |
41 |
+ mtime = int(bin_dbapi.aux_get(cpv, ['_mtime_'])[0]) |
42 |
+ if time_limit and mtime >= time_limit: |
43 |
+ # time-limit exclusion |
44 |
continue |
45 |
- for file in files: |
46 |
- if file[-5:] == ".tbz2": |
47 |
- category = os.path.basename(root) |
48 |
- cpv = category+"/"+file[:-5] |
49 |
- elif file[-5:] == ".xpak": |
50 |
- category = os.path.basename(os.path.dirname(root)) |
51 |
- cpv = category+"/"+file.rpartition('-')[0] |
52 |
- else: |
53 |
- # ignore other files |
54 |
- continue |
55 |
- path = os.path.join(root, file) |
56 |
- st = os.lstat(path) |
57 |
- if time_limit and (st[stat.ST_MTIME] >= time_limit): |
58 |
- # time-limit exclusion |
59 |
- continue |
60 |
- # dict is cpv->[files] (2 files in general, because of symlink) |
61 |
- clean_me.setdefault(cpv,[]).append(path) |
62 |
- #if os.path.islink(path): |
63 |
- if stat.S_ISLNK(st[stat.ST_MODE]): |
64 |
- clean_me[cpv].append(os.path.realpath(path)) |
65 |
+ # dict is cpv->[pkgs] (supports binpkg-multi-instance) |
66 |
+ clean_me.setdefault(cpv, []).append(cpv) |
67 |
+ |
68 |
# keep only obsolete ones |
69 |
if destructive and package_names: |
70 |
cp_all = dict.fromkeys(var_dbapi.cp_all()) |
71 |
@@ -576,10 +567,10 @@ def findPackages( |
72 |
del clean_me[cpv] |
73 |
continue |
74 |
if destructive and var_dbapi.cpv_exists(cpv): |
75 |
- buildtime = var_dbapi.aux_get(cpv, ['BUILD_TIME'])[0].encode('utf-8').strip() |
76 |
- clean_me[cpv] = [path for path in clean_me[cpv] |
77 |
+ buildtime = var_dbapi.aux_get(cpv, ['BUILD_TIME'])[0] |
78 |
+ clean_me[cpv] = [pkg for pkg in clean_me[cpv] |
79 |
# only keep path if BUILD_TIME is identical with vartree |
80 |
- if portage.xpak.tbz2(path).getfile('BUILD_TIME').strip() != buildtime] |
81 |
+ if bin_dbapi.aux_get(pkg, ['BUILD_TIME'])[0] != buildtime] |
82 |
if not clean_me[cpv]: |
83 |
# nothing we can clean for this package |
84 |
del clean_me[cpv] |
85 |
@@ -588,4 +579,10 @@ def findPackages( |
86 |
# exlusion because of --package-names |
87 |
del clean_me[cpv] |
88 |
|
89 |
+ # the getname method correctly supports FEATURES=binpkg-multi-instance, |
90 |
+ # allowing for multiple paths per cpv (the API used here is also compatible |
91 |
+ # with older portage which does not support binpkg-multi-instance) |
92 |
+ for cpv, pkgs in clean_me.items(): |
93 |
+ clean_me[cpv] = [bin_dbapi.bintree.getname(pkg) for pkg in pkgs] |
94 |
+ |
95 |
return clean_me |