make debug mode configurable
[portage.git] / pym / portage / sets / libs.py
1 # Copyright 2007 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 from portage.sets.base import PackageSet
6 from portage.sets import get_boolean
7 from portage.dbapi.vartree import dblink
8 from portage.versions import catsplit, catpkgsplit
9
10 import os
11
12 class LibraryConsumerSet(PackageSet):
13         _operations = ["merge", "unmerge"]
14
15         def __init__(self, vardbapi, debug=False):
16                 super(LibraryConsumerSet, self).__init__()
17                 self.dbapi = vardbapi
18                 self.debug = debug
19
20         def mapPathsToAtoms(self, paths):
21                 rValue = set()
22                 for cpv in self.dbapi.cpv_all():
23                         mysplit = catsplit(cpv)
24                         link = dblink(mysplit[0], mysplit[1], myroot=self.dbapi.root, \
25                                         mysettings=self.dbapi.settings, treetype='vartree', \
26                                         vartree=self.dbapi.vartree)
27                         if paths.intersection(link.getcontents()):
28                                 cat, pn = catpkgsplit(cpv)[:2]
29                                 slot = self.dbapi.aux_get(cpv, ["SLOT"])[0]
30                                 rValue.add("%s/%s:%s" % (cat, pn, slot))
31                 return rValue
32         
33
34 class PreservedLibraryConsumerSet(LibraryConsumerSet):
35         def load(self):
36                 reg = self.dbapi.plib_registry
37                 consumers = set()
38                 if reg:
39                         for libs in reg.getPreservedLibs().values():
40                                 for lib in libs:
41                                         if self.debug:
42                                                 print lib
43                                                 for x in sorted(self.dbapi.linkmap.findConsumers(lib)):
44                                                         print "    ", x
45                                                 print "-"*40
46                                         consumers.update(self.dbapi.linkmap.findConsumers(lib))
47                 else:
48                         return
49                 if not consumers:
50                         return
51                 self._setAtoms(self.mapPathsToAtoms(consumers))
52
53         def singleBuilder(cls, options, settings, trees):
54                 debug = get_boolean(options, "debug", False)
55                 return PreservedLibraryConsumerSet(trees["vartree"].dbapi, debug)
56         singleBuilder = classmethod(singleBuilder)