Gentoo Archives: gentoo-portage-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-portage-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: [gentoo-portage-dev] [PATCH] sets: introduce @changed-deps to update packages which need dep changes.
Date: Thu, 24 Jul 2014 22:25:55
Message-Id: 1406240765-4626-1-git-send-email-mgorny@gentoo.org
1 The @changed-deps set tries to compare RDEPEND and PDEPEND entries of
2 installed packages with ebuild counterparts, and pulls the ebuild
3 whenever the two are not in sync. This could be used, for example, to
4 clean up the system after disabling --dynamic-deps.
5 ---
6 cnf/sets/portage.conf | 5 +++++
7 pym/portage/_sets/dbapi.py | 53 ++++++++++++++++++++++++++++++++++++++++++++--
8 2 files changed, 56 insertions(+), 2 deletions(-)
9
10 diff --git a/cnf/sets/portage.conf b/cnf/sets/portage.conf
11 index b73afb1..fd2c387 100644
12 --- a/cnf/sets/portage.conf
13 +++ b/cnf/sets/portage.conf
14 @@ -84,3 +84,8 @@ class = portage.sets.dbapi.UnavailableSet
15 # are not available.
16 [unavailable-binaries]
17 class = portage.sets.dbapi.UnavailableBinaries
18 +
19 +# Installed packages for which vdb *DEPEND entries are outdated compared
20 +# to the matching portdb entry.
21 +[changed-deps]
22 +class = portage.sets.dbapi.ChangedDepsSet
23 diff --git a/pym/portage/_sets/dbapi.py b/pym/portage/_sets/dbapi.py
24 index 384fb3a..9b2cb8b 100644
25 --- a/pym/portage/_sets/dbapi.py
26 +++ b/pym/portage/_sets/dbapi.py
27 @@ -1,17 +1,18 @@
28 # Copyright 2007-2012 Gentoo Foundation
29 # Distributed under the terms of the GNU General Public License v2
30
31 +import re
32 import time
33
34 from portage import os
35 from portage.versions import best, catsplit, vercmp
36 -from portage.dep import Atom
37 +from portage.dep import Atom, use_reduce
38 from portage.localization import _
39 from portage._sets.base import PackageSet
40 from portage._sets import SetConfigError, get_boolean
41 import portage
42
43 -__all__ = ["CategorySet", "DowngradeSet",
44 +__all__ = ["CategorySet", "ChangedDepsSet", "DowngradeSet",
45 "EverythingSet", "OwnerSet", "VariableSet"]
46
47 class EverythingSet(PackageSet):
48 @@ -456,3 +457,51 @@ class RebuiltBinaries(EverythingSet):
49 bindb=trees["bintree"].dbapi)
50
51 singleBuilder = classmethod(singleBuilder)
52 +
53 +class ChangedDepsSet(PackageSet):
54 +
55 + _operations = ["merge", "unmerge"]
56 +
57 + description = "Package set which contains all installed " + \
58 + "packages for which the vdb *DEPEND entries are outdated " + \
59 + "compared to corresponding portdb entries."
60 +
61 + def __init__(self, portdb=None, vardb=None):
62 + super(ChangedDepsSet, self).__init__()
63 + self._portdb = portdb
64 + self._vardb = vardb
65 +
66 + def load(self):
67 + depvars = ('RDEPEND', 'PDEPEND')
68 +
69 + subslot_repl_re = re.compile(r':[^[]*=')
70 +
71 + atoms = []
72 + for cpv in self._vardb.cpv_all():
73 + # no ebuild, no dynamic-deps to break it :)
74 + if not self._portdb.cpv_exists(cpv):
75 + continue
76 +
77 + use, eapi = self._vardb.aux_get(cpv, ('USE', 'EAPI'))
78 +
79 + def clean_subslots(depatom):
80 + if isinstance(depatom, list):
81 + return [clean_subslots(x) for x in depatom]
82 + else:
83 + return subslot_repl_re.sub(':=', depatom)
84 +
85 + vdbvars = [clean_subslots(use_reduce(x, uselist=use, eapi=eapi))
86 + for x in self._vardb.aux_get(cpv, depvars)]
87 + pdbvars = [clean_subslots(use_reduce(x, uselist=use, eapi=eapi))
88 + for x in self._portdb.aux_get(cpv, depvars)]
89 +
90 + if vdbvars != pdbvars:
91 + atoms.append('=%s' % cpv)
92 +
93 + self._setAtoms(atoms)
94 +
95 + def singleBuilder(cls, options, settings, trees):
96 + return cls(portdb=trees["porttree"].dbapi,
97 + vardb=trees["vartree"].dbapi)
98 +
99 + singleBuilder = classmethod(singleBuilder)
100 --
101 2.0.2

Replies