self.spinner = spinner
self.verbose = verbose
self.searchdesc = searchdesc
+ self.root_config = root_config
self.setconfig = root_config.setconfig
def fake_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):
def __init__(self, settings, trees, setconfig):
self.trees = trees
self.settings = settings
+ self.iuse_implicit = tuple(sorted(settings._get_implicit_iuse()))
self.root = self.settings["ROOT"]
self.setconfig = setconfig
self.sets = self.setconfig.getSets()
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", "regex", "tokens")
+
+ def __init__(self, tokens, iuse_implicit):
+ self.tokens = tuple(tokens)
+ self.iuse_implicit = iuse_implicit
+ 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))
+
+ def __getattribute__(self, name):
+ if name == "regex":
+ try:
+ return object.__getattribute__(self, "regex")
+ except AttributeError:
+ all = object.__getattribute__(self, "all")
+ iuse_implicit = object.__getattribute__(self, "iuse_implicit")
+ self.regex = re.compile("^(%s)$" % "|".join(
+ chain((re.escape(x) for x in all), iuse_implicit)))
+ return object.__getattribute__(self, name)
+
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(), self._pkg.root_config.iuse_implicit)
+
+ 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,
pkgsettings, db, pkg_type, built, installed, db_keys)
if atom.use and not mreasons:
missing_use.append(Package(built=built, cpv=cpv,
- installed=installed, metadata=metadata, root=root))
+ installed=installed, metadata=metadata,
+ root_config=root_config))
else:
masked_packages.append(
(root_config, pkgsettings, cpv, metadata, mreasons))
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 = []
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"]