#
# 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
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)
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):
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
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)
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()
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
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",
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))
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
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)
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 : {
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)
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] = {}
# 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():
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
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,
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
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"]):
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.
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]
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 = []
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)
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"]
# 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):