Merge code for the Package.root_config attribute from trunk r10440,
authorZac Medico <zmedico@gentoo.org>
Tue, 27 May 2008 04:32:58 +0000 (04:32 -0000)
committerZac Medico <zmedico@gentoo.org>
Tue, 27 May 2008 04:32:58 +0000 (04:32 -0000)
excluding USE deps code.

svn path=/main/branches/2.1.2/; revision=10442

bin/emerge

index 1b4983cf928f0af36bdec02cd968f7f09257875d..ffb550b476d0e7e8fdc2f94b52dba1228fca5411 100755 (executable)
@@ -390,16 +390,18 @@ class search:
        #
        # public interface
        #
-       def __init__(self, settings, trees, spinner, searchdesc,
+       def __init__(self, root_config, spinner, searchdesc,
                verbose, usepkg, usepkgonly):
                """Searches the available and installed packages for the supplied search key.
                The list of available and installed packages is created at object instantiation.
                This makes successive searches faster."""
-               self.settings = settings
-               self.vartree = trees["vartree"]
+               self.settings = root_config.settings
+               self.vartree = root_config.trees["vartree"]
                self.spinner = spinner
                self.verbose = verbose
                self.searchdesc = searchdesc
+               self.root_config = root_config
+               self.setconfig = root_config.setconfig
 
                def fake_portdb():
                        pass
@@ -410,9 +412,9 @@ class search:
 
                self._dbs = []
 
-               portdb = trees["porttree"].dbapi
-               bindb = trees["bintree"].dbapi
-               vardb = trees["vartree"].dbapi
+               portdb = root_config.trees["porttree"].dbapi
+               bindb = root_config.trees["bintree"].dbapi
+               vardb = root_config.trees["vartree"].dbapi
 
                if not usepkgonly and portdb._have_root_eclass_dir:
                        self._dbs.append(portdb)
@@ -470,7 +472,7 @@ class search:
                elif built:
                        pkg_type = "binary"
                return visible(self.settings,
-                       Package(type_name=pkg_type, root=self.settings["ROOT"],
+                       Package(type_name=pkg_type, root_config=self.root_config,
                        cpv=cpv, built=built, installed=installed, metadata=metadata))
 
        def _xmatch(self, level, atom):
@@ -898,7 +900,7 @@ def create_world_atom(pkg_key, metadata, args_set, root_config):
        in world since system atoms can only match one slot while world atoms can
        be greedy with respect to slots.  Unslotted system packages will not be
        stored in world."""
-       pkg = Package(cpv=pkg_key, metadata=metadata)
+       pkg = Package(cpv=pkg_key, root_config=root_config, metadata=metadata)
        arg_atom = args_set.findAtomForPackage(pkg)
        if not arg_atom:
                return None
@@ -1134,11 +1136,14 @@ class FakeVartree(portage.vartree):
        user doesn't necessarily need write access to the vardb in cases where
        global updates are necessary (updates are performed when necessary if there
        is not a matching ebuild in the tree)."""
-       def __init__(self, real_vartree, portdb,
-               db_keys, pkg_cache, acquire_lock=1):
+       def __init__(self, root_config, pkg_cache=None, acquire_lock=1):
+               if pkg_cache is None:
+                       pkg_cache = {}
+               real_vartree = root_config.trees["vartree"]
+               portdb = root_config.trees["porttree"].dbapi
                self.root = real_vartree.root
                self.settings = real_vartree.settings
-               mykeys = db_keys[:]
+               mykeys = list(Package.metadata_keys)
                for required_key in ("COUNTER", "SLOT"):
                        if required_key not in mykeys:
                                mykeys.append(required_key)
@@ -1179,7 +1184,7 @@ class FakeVartree(portage.vartree):
                                if pkg is None:
                                        pkg = Package(built=True, cpv=cpv,
                                                installed=True, metadata=metadata,
-                                               root=self.root, type_name="installed")
+                                               root_config=root_config, type_name="installed")
                                self._pkg_cache[pkg] = pkg
                                self.dbapi.cpv_inject(pkg)
                        real_dbapi.flush_cache()
@@ -1311,7 +1316,7 @@ def get_mask_info(root_config, cpv, pkgsettings,
        if metadata is None:
                mreasons = ["corruption"]
        else:
-               pkg = Package(type_name=pkg_type, root=root_config.root,
+               pkg = Package(type_name=pkg_type, root_config=root_config,
                        cpv=cpv, built=built, installed=installed, metadata=metadata)
                mreasons = get_masking_status(pkg, pkgsettings, root_config)
        return metadata, mreasons
@@ -1401,9 +1406,9 @@ class Blocker(Task):
 class Package(Task):
        __slots__ = ("built", "cpv", "depth",
                "installed", "metadata", "onlydeps", "operation",
-               "root", "type_name",
-               "category", "cp", "cpv_split",
-               "pf", "pv_split", "slot", "slot_atom", "use")
+               "root_config", "type_name",
+               "category", "cp", "cpv_split", "iuse",
+               "pf", "pv_split", "root", "slot", "slot_atom", "use")
 
        metadata_keys = [
                "CHOST", "COUNTER", "DEPEND", "EAPI", "IUSE", "KEYWORDS",
@@ -1412,6 +1417,7 @@ class Package(Task):
 
        def __init__(self, **kwargs):
                Task.__init__(self, **kwargs)
+               self.root = self.root_config.root
                self.metadata = self._metadata_wrapper(self, self.metadata)
                self.cp = portage.cpv_getkey(self.cpv)
                self.slot_atom = portage_dep.Atom("%s:%s" % (self.cp, self.slot))
@@ -1420,13 +1426,39 @@ class Package(Task):
                self.pv_split = self.cpv_split[1:]
 
        class _use(object):
+
+               __slots__ = ("__weakref__", "enabled")
+
                def __init__(self, use):
                        self.enabled = frozenset(use)
 
+       class _iuse(object):
+
+               __slots__ = ("__weakref__", "all", "enabled", "disabled", "iuse_implicit", "tokens")
+
+               def __init__(self, tokens):
+                       self.tokens = tuple(tokens)
+                       enabled = []
+                       disabled = []
+                       other = []
+                       for x in tokens:
+                               prefix = x[:1]
+                               if prefix == "+":
+                                       enabled.append(x[1:])
+                               elif prefix == "-":
+                                       disabled.append(x[1:])
+                               else:
+                                       other.append(x)
+                       self.enabled = frozenset(enabled)
+                       self.disabled = frozenset(disabled)
+                       self.all = frozenset(chain(enabled, disabled, other))
+
        class _metadata_wrapper(dict):
                """
                Detect metadata updates and synchronize Package attributes.
                """
+               _wrapped_keys = frozenset(["IUSE", "SLOT", "USE"])
+
                def __init__(self, pkg, metadata):
                        dict.__init__(self)
                        self._pkg = pkg
@@ -1440,10 +1472,17 @@ class Package(Task):
 
                def __setitem__(self, k, v):
                        dict.__setitem__(self, k, v)
-                       if k == "USE":
-                               self._pkg.use = self._pkg._use(v.split())
-                       elif k == "SLOT":
-                               self._pkg.slot = v
+                       if k in self._wrapped_keys:
+                               getattr(self, "_set_" + k.lower())(k, v)
+
+               def _set_iuse(self, k, v):
+                       self._pkg.iuse = self._pkg._iuse(v.split())
+
+               def _set_slot(self, k, v):
+                       self._pkg.slot = v
+
+               def _set_use(self, k, v):
+                       self._pkg.use = self._pkg._use(v.split())
 
        def _get_hash_key(self):
                hash_key = getattr(self, "_hash_key", None)
@@ -1680,9 +1719,10 @@ class BlockerCache(DictMixin):
 
 class BlockerDB(object):
 
-       def __init__(self, vartree, portdb):
-               self._vartree = vartree
-               self._portdb = portdb
+       def __init__(self, root_config):
+               self._root_config = root_config
+               self._vartree = root_config.trees["vartree"]
+               self._portdb = root_config.trees["porttree"].dbapi
                self._blocker_cache = \
                        BlockerCache(self._vartree.root, vartree.dbapi)
                self._dep_check_trees = { self._vartree.root : {
@@ -1697,9 +1737,7 @@ class BlockerDB(object):
                settings = self._vartree.settings
                stale_cache = set(blocker_cache)
                fake_vartree = \
-                       FakeVartree(self._vartree,
-                               self._portdb, Package.metadata_keys, {},
-                               acquire_lock=acquire_lock)
+                       FakeVartree(self._root_config, acquire_lock=acquire_lock)
                vardb = fake_vartree.dbapi
                installed_pkgs = list(vardb)
 
@@ -1975,9 +2013,8 @@ class depgraph(object):
                        for tree in ("porttree", "bintree"):
                                self.trees[myroot][tree] = trees[myroot][tree]
                        self.trees[myroot]["vartree"] = \
-                               FakeVartree(trees[myroot]["vartree"],
-                                       trees[myroot]["porttree"].dbapi,
-                                       self._mydbapi_keys, self._pkg_cache)
+                               FakeVartree(trees[myroot]["root_config"],
+                                       pkg_cache=self._pkg_cache)
                        self.pkgsettings[myroot] = portage.config(
                                clone=self.trees[myroot]["vartree"].settings)
                        self._slot_pkg_map[myroot] = {}
@@ -1988,14 +2025,10 @@ class depgraph(object):
                        # have after new packages have been installed.
                        fakedb = PackageVirtualDbapi(vardb.settings)
                        if preload_installed_pkgs:
-                               for cpv in vardb.cpv_all():
+                               for pkg in vardb:
                                        self.spinner.update()
-                                       metadata = dict(izip(self._mydbapi_keys,
-                                               vardb.aux_get(cpv, self._mydbapi_keys)))
-                                       pkg = Package(built=True, cpv=cpv,
-                                               installed=True, metadata=metadata,
-                                               root=myroot, type_name="installed")
-                                       self._pkg_cache[pkg] = pkg
+                                       # This triggers metadata updates via FakeVartree.
+                                       vardb.aux_get(pkg.cpv, [])
                                        fakedb.cpv_inject(pkg)
                        self.mydbapi[myroot] = fakedb
                        def graph_tree():
@@ -2639,7 +2672,7 @@ class depgraph(object):
                                        return 0, myfavorites
                                metadata = dict(izip(self._mydbapi_keys,
                                        bindb.aux_get(mykey, self._mydbapi_keys)))
-                               pkg = Package(type_name="binary", root=myroot,
+                               pkg = Package(type_name="binary", root_config=root_config,
                                        cpv=mykey, built=True, metadata=metadata,
                                        onlydeps=onlydeps)
                                self._pkg_cache[pkg] = pkg
@@ -2679,7 +2712,7 @@ class depgraph(object):
                                        portdb.aux_get(mykey, self._mydbapi_keys)))
                                pkgsettings.setcpv(mykey, mydb=metadata)
                                metadata["USE"] = pkgsettings["PORTAGE_USE"]
-                               pkg = Package(type_name="ebuild", root=myroot,
+                               pkg = Package(type_name="ebuild", root_config=root_config,
                                        cpv=mykey, metadata=metadata, onlydeps=onlydeps)
                                self._pkg_cache[pkg] = pkg
                                args.append(PackageArg(arg=x, package=pkg,
@@ -3069,6 +3102,7 @@ class depgraph(object):
                return ret
 
        def _select_pkg_highest_available_imp(self, root, atom, onlydeps=False):
+               root_config = self.roots[root]
                pkgsettings = self.pkgsettings[root]
                dbs = self._filtered_trees[root]["dbs"]
                vardb = self.roots[root].trees["vartree"].dbapi
@@ -3154,7 +3188,8 @@ class depgraph(object):
                                                        continue
                                                pkg = Package(built=built, cpv=cpv,
                                                        installed=installed, metadata=metadata,
-                                                       onlydeps=onlydeps, root=root, type_name=pkg_type)
+                                                       onlydeps=onlydeps, root_config=root_config,
+                                                       type_name=pkg_type)
                                                metadata = pkg.metadata
                                                if not built and ("?" in metadata["LICENSE"] or \
                                                        "?" in metadata["PROVIDE"]):
@@ -3680,7 +3715,8 @@ class depgraph(object):
                                                uninst_task = Package(built=inst_pkg.built,
                                                        cpv=inst_pkg.cpv, installed=inst_pkg.installed,
                                                        metadata=inst_pkg.metadata,
-                                                       operation="uninstall", root=inst_pkg.root,
+                                                       operation="uninstall",
+                                                       root_config=inst_pkg.root_config,
                                                        type_name=inst_pkg.type_name)
                                                self._pkg_cache[uninst_task] = uninst_task
                                                # Enforce correct merge order with a hard dep.
@@ -5300,9 +5336,10 @@ class depgraph(object):
                                raise portage_exception.PackageNotFound(pkg_key)
                        installed = action == "uninstall"
                        built = pkg_type != "ebuild"
+                       root_config = self.roots[myroot]
                        pkg = Package(built=built, cpv=pkg_key,
                                installed=installed, metadata=metadata,
-                               operation=action, root=myroot,
+                               operation=action, root_config=root_config,
                                type_name=pkg_type)
                        if pkg_type == "ebuild":
                                pkgsettings = self.pkgsettings[myroot]
@@ -5743,9 +5780,7 @@ class MergeTask(object):
                for root in trees:
                        self.pkgsettings[root] = portage.config(
                                clone=trees[root]["vartree"].settings)
-                       self._blocker_db[root] = BlockerDB(
-                               trees[root]["vartree"],
-                               trees[root]["porttree"].dbapi)
+                       self._blocker_db[root] = BlockerDB(trees[root]["root_config"])
                self.curval = 0
                self._spawned_pids = []
 
@@ -7677,11 +7712,11 @@ def action_info(settings, trees, myopts, myfiles):
                                mydbapi=trees[settings["ROOT"]]["vartree"].dbapi,
                                tree="vartree")
 
-def action_search(settings, trees, myopts, myfiles, spinner):
+def action_search(root_config, myopts, myfiles, spinner):
        if not myfiles:
                print "emerge: no search terms provided."
        else:
-               searchinstance = search(settings, trees,
+               searchinstance = search(root_config,
                        spinner, "--searchdesc" in myopts,
                        "--quiet" not in myopts, "--usepkg" in myopts,
                        "--usepkgonly" in myopts)
@@ -7735,9 +7770,7 @@ def action_depclean(settings, trees, ldpath_mtimes,
        dep_check_trees = {}
        dep_check_trees[myroot] = {}
        dep_check_trees[myroot]["vartree"] = \
-               FakeVartree(trees[myroot]["vartree"],
-               trees[myroot]["porttree"].dbapi,
-               depgraph._mydbapi_keys, pkg_cache)
+               FakeVartree(trees[myroot]["root_config"], pkg_cache=pkg_cache)
        vardb = dep_check_trees[myroot]["vartree"].dbapi
        # Constrain dependency selection to the installed packages.
        dep_check_trees[myroot]["porttree"] = dep_check_trees[myroot]["vartree"]
@@ -9003,7 +9036,7 @@ def emerge_main():
        # SEARCH action
        elif "search"==myaction:
                validate_ebuild_environment(trees)
-               action_search(settings, trees[settings["ROOT"]],
+               action_search(trees[settings["ROOT"]]["root_config"],
                        myopts, myfiles, spinner)
        elif myaction in ("clean", "unmerge") or \
                (myaction == "prune" and "--nodeps" in myopts):