Ejemplo n.º 1
0
    def _aux_get_wrapper(self, pkg, wants, myrepo=None):
        if pkg in self._aux_get_history:
            return self._aux_get(pkg, wants)
        self._aux_get_history.add(pkg)
        # We need to check the EAPI, and this also raises
        # a KeyError to the caller if appropriate.
        pkg_obj = self.dbapi._cpv_map[pkg]
        installed_eapi = pkg_obj.metadata['EAPI']
        repo = pkg_obj.metadata['repository']
        eapi_attrs = _get_eapi_attrs(installed_eapi)
        built_slot_operator_atoms = None

        if eapi_attrs.slot_operator and not self._ignore_built_slot_operator_deps:
            try:
                built_slot_operator_atoms = find_built_slot_operator_atoms(
                    pkg_obj)
            except InvalidDependString:
                pass

        try:
            # Use the live ebuild metadata if possible.
            repo = _gen_valid_repo(repo)
            live_metadata = dict(
                zip(self._portdb_keys,
                    self._portdb.aux_get(pkg, self._portdb_keys, myrepo=repo)))
            # Use the metadata from the installed instance if the EAPI
            # of either instance is unsupported, since if the installed
            # instance has an unsupported or corrupt EAPI then we don't
            # want to attempt to do complex operations such as execute
            # pkg_config, pkg_prerm or pkg_postrm phases. If both EAPIs
            # are supported then go ahead and use the live_metadata, in
            # order to respect dep updates without revision bump or EAPI
            # bump, as in bug #368725.
            if not (portage.eapi_is_supported(live_metadata["EAPI"]) and \
             portage.eapi_is_supported(installed_eapi)):
                raise KeyError(pkg)

            # preserve built slot/sub-slot := operator deps
            if built_slot_operator_atoms:
                live_eapi_attrs = _get_eapi_attrs(live_metadata["EAPI"])
                if not live_eapi_attrs.slot_operator:
                    raise KeyError(pkg)
                for k, v in built_slot_operator_atoms.items():
                    live_metadata[k] += (
                        " " + " ".join(_unicode(atom) for atom in v))

            self.dbapi.aux_update(pkg, live_metadata)
        except (KeyError, portage.exception.PortageException):
            if self._global_updates is None:
                self._global_updates = \
                 grab_global_updates(self._portdb)
            perform_global_updates(pkg, self.dbapi, self._global_updates)
        return self._aux_get(pkg, wants)
Ejemplo n.º 2
0
	def _aux_get_wrapper(self, pkg, wants, myrepo=None):
		if pkg in self._aux_get_history:
			return self._aux_get(pkg, wants)
		self._aux_get_history.add(pkg)
		# We need to check the EAPI, and this also raises
		# a KeyError to the caller if appropriate.
		pkg_obj = self.dbapi._cpv_map[pkg]
		installed_eapi = pkg_obj.metadata['EAPI']
		repo = pkg_obj.metadata['repository']
		eapi_attrs = _get_eapi_attrs(installed_eapi)
		built_slot_operator_atoms = None

		if eapi_attrs.slot_operator and not self._ignore_built_slot_operator_deps:
			try:
				built_slot_operator_atoms = find_built_slot_operator_atoms(pkg_obj)
			except InvalidDependString:
				pass

		try:
			# Use the live ebuild metadata if possible.
			repo = _gen_valid_repo(repo)
			live_metadata = dict(zip(self._portdb_keys,
				self._portdb.aux_get(pkg, self._portdb_keys, myrepo=repo)))
			# Use the metadata from the installed instance if the EAPI
			# of either instance is unsupported, since if the installed
			# instance has an unsupported or corrupt EAPI then we don't
			# want to attempt to do complex operations such as execute
			# pkg_config, pkg_prerm or pkg_postrm phases. If both EAPIs
			# are supported then go ahead and use the live_metadata, in
			# order to respect dep updates without revision bump or EAPI
			# bump, as in bug #368725.
			if not (portage.eapi_is_supported(live_metadata["EAPI"]) and \
				portage.eapi_is_supported(installed_eapi)):
				raise KeyError(pkg)

			# preserve built slot/sub-slot := operator deps
			if built_slot_operator_atoms:
				live_eapi_attrs = _get_eapi_attrs(live_metadata["EAPI"])
				if not live_eapi_attrs.slot_operator:
					raise KeyError(pkg)
				for k, v in built_slot_operator_atoms.items():
					live_metadata[k] += (" " +
						" ".join(_unicode(atom) for atom in v))

			self.dbapi.aux_update(pkg, live_metadata)
		except (KeyError, portage.exception.PortageException):
			if self._global_updates is None:
				self._global_updates = \
					grab_global_updates(self._portdb)
			perform_global_updates(
				pkg, self.dbapi, self._global_updates)
		return self._aux_get(pkg, wants)
Ejemplo n.º 3
0
    def __init__(self, **kwargs):
        metadata = _PackageMetadataWrapperBase(kwargs.pop('metadata'))
        Task.__init__(self, **kwargs)
        # the SlotObject constructor assigns self.root_config from keyword args
        # and is an instance of a '_emerge.RootConfig.RootConfig class
        self.root = self.root_config.root
        self._raw_metadata = metadata
        self._metadata = _PackageMetadataWrapper(self, metadata)
        if not self.built:
            self._metadata['CHOST'] = self.root_config.settings.get(
                'CHOST', '')
        eapi_attrs = _get_eapi_attrs(self.eapi)
        self.cpv = _pkg_str(self.cpv,
                            metadata=self._metadata,
                            settings=self.root_config.settings)
        if hasattr(self.cpv, 'slot_invalid'):
            self._invalid_metadata(
                'SLOT.invalid',
                "SLOT: invalid value: '%s'" % self._metadata["SLOT"])
        self.cpv_split = self.cpv.cpv_split
        self.category, self.pf = portage.catsplit(self.cpv)
        self.cp = self.cpv.cp
        self.version = self.cpv.version
        self.slot = self.cpv.slot
        self.sub_slot = self.cpv.sub_slot
        self.slot_atom = Atom("%s%s%s" % (self.cp, _slot_separator, self.slot))
        # sync metadata with validated repo (may be UNKNOWN_REPO)
        self._metadata['repository'] = self.cpv.repo

        if eapi_attrs.iuse_effective:
            implicit_match = self.root_config.settings._iuse_effective_match
        else:
            implicit_match = self.root_config.settings._iuse_implicit_match
        usealiases = self.root_config.settings._use_manager.getUseAliases(self)
        self.iuse = self._iuse(self, self._metadata["IUSE"].split(),
                               implicit_match, usealiases, self.eapi)

        if (self.iuse.enabled or self.iuse.disabled) and \
         not eapi_attrs.iuse_defaults:
            if not self.installed:
                self._invalid_metadata(
                    'EAPI.incompatible',
                    "IUSE contains defaults, but EAPI doesn't allow them")
        if self.inherited is None:
            self.inherited = frozenset()

        if self.operation is None:
            if self.onlydeps or self.installed:
                self.operation = "nomerge"
            else:
                self.operation = "merge"

        self._hash_key = Package._gen_hash_key(cpv=self.cpv,
                                               installed=self.installed,
                                               onlydeps=self.onlydeps,
                                               operation=self.operation,
                                               repo_name=self.cpv.repo,
                                               root_config=self.root_config,
                                               type_name=self.type_name)
        self._hash_value = hash(self._hash_key)
Ejemplo n.º 4
0
	def __init__(self, cpv, metadata=None, settings=None, eapi=None,
		repo=None, slot=None, build_time=None, build_id=None,
		file_size=None, mtime=None):
		if not isinstance(cpv, _unicode):
			# Avoid TypeError from _unicode.__init__ with PyPy.
			cpv = _unicode_decode(cpv)
		_unicode.__init__(cpv)
		if metadata is not None:
			self.__dict__['_metadata'] = metadata
			slot = metadata.get('SLOT', slot)
			repo = metadata.get('repository', repo)
			eapi = metadata.get('EAPI', eapi)
			build_time = metadata.get('BUILD_TIME', build_time)
			file_size = metadata.get('SIZE', file_size)
			build_id = metadata.get('BUILD_ID', build_id)
			mtime = metadata.get('_mtime_', mtime)
		if settings is not None:
			self.__dict__['_settings'] = settings
		if eapi is not None:
			self.__dict__['eapi'] = eapi

		self.__dict__['build_time'] = self._long(build_time, 0)
		self.__dict__['file_size'] = self._long(file_size, None)
		self.__dict__['build_id'] = self._long(build_id, None)
		self.__dict__['mtime'] = self._long(mtime, None)
		self.__dict__['cpv_split'] = catpkgsplit(cpv, eapi=eapi)
		if self.cpv_split is None:
			raise InvalidData(cpv)
		self.__dict__['cp'] = self.cpv_split[0] + '/' + self.cpv_split[1]
		if self.cpv_split[-1] == "r0" and cpv[-3:] != "-r0":
			self.__dict__['version'] = "-".join(self.cpv_split[2:-1])
		else:
			self.__dict__['version'] = "-".join(self.cpv_split[2:])
		# for match_from_list introspection
		self.__dict__['cpv'] = self
		if slot is not None:
			eapi_attrs = _get_eapi_attrs(eapi)
			slot_match = _get_slot_re(eapi_attrs).match(slot)
			if slot_match is None:
				# Avoid an InvalidAtom exception when creating SLOT atoms
				self.__dict__['slot'] = '0'
				self.__dict__['sub_slot'] = '0'
				self.__dict__['slot_invalid'] = slot
			else:
				if eapi_attrs.slot_operator:
					slot_split = slot.split("/")
					self.__dict__['slot'] = slot_split[0]
					if len(slot_split) > 1:
						self.__dict__['sub_slot'] = slot_split[1]
					else:
						self.__dict__['sub_slot'] = slot_split[0]
				else:
					self.__dict__['slot'] = slot
					self.__dict__['sub_slot'] = slot

		if repo is not None:
			repo = _gen_valid_repo(repo)
			if not repo:
				repo = _unknown_repo
			self.__dict__['repo'] = repo
Ejemplo n.º 5
0
def evaluate_slot_operator_equal_deps(settings, use, trees):

	metadata = settings.configdict['pkg']
	eapi = metadata['EAPI']
	eapi_attrs = _get_eapi_attrs(eapi)
	running_vardb = trees[trees._running_eroot]["vartree"].dbapi
	target_vardb = trees[trees._target_eroot]["vartree"].dbapi
	vardbs = [target_vardb]
	deps = {}
	for k in Package._dep_keys:
		deps[k] = use_reduce(metadata[k],
			uselist=use, eapi=eapi, token_class=Atom)

	for k in Package._runtime_keys:
		_eval_deps(deps[k], vardbs)

	if eapi_attrs.bdepend:
		_eval_deps(deps["BDEPEND"], [running_vardb])
		_eval_deps(deps["DEPEND"], [target_vardb])
	else:
		if running_vardb is not target_vardb:
			vardbs.append(running_vardb)
		_eval_deps(deps["DEPEND"], vardbs)

	result = {}
	for k, v in deps.items():
		result[k] = paren_enclose(v)

	return result
Ejemplo n.º 6
0
	def _apply_dynamic_deps(self, pkg, live_metadata):

		try:
			if live_metadata is None:
				raise _DynamicDepsNotApplicable()
			# Use the metadata from the installed instance if the EAPI
			# of either instance is unsupported, since if the installed
			# instance has an unsupported or corrupt EAPI then we don't
			# want to attempt to do complex operations such as execute
			# pkg_config, pkg_prerm or pkg_postrm phases. If both EAPIs
			# are supported then go ahead and use the live_metadata, in
			# order to respect dep updates without revision bump or EAPI
			# bump, as in bug #368725.
			if not (portage.eapi_is_supported(live_metadata["EAPI"]) and \
				portage.eapi_is_supported(pkg.eapi)):
				raise _DynamicDepsNotApplicable()

			# preserve built slot/sub-slot := operator deps
			built_slot_operator_atoms = None
			if not self._ignore_built_slot_operator_deps and \
				_get_eapi_attrs(pkg.eapi).slot_operator:
				try:
					built_slot_operator_atoms = \
						find_built_slot_operator_atoms(pkg)
				except InvalidDependString:
					pass

			if built_slot_operator_atoms:
				live_eapi_attrs = _get_eapi_attrs(live_metadata["EAPI"])
				if not live_eapi_attrs.slot_operator:
					raise _DynamicDepsNotApplicable()
				for k, v in built_slot_operator_atoms.items():
					live_metadata[k] += (" " +
						" ".join(_unicode(atom) for atom in v))

			self.dbapi.aux_update(pkg.cpv, live_metadata)
		except _DynamicDepsNotApplicable:
			if self._global_updates is None:
				self._global_updates = \
					grab_global_updates(self._portdb)

			# Bypass _aux_get_wrapper, since calling that
			# here would trigger infinite recursion.
			aux_keys = Package._dep_keys + self.dbapi._pkg_str_aux_keys
			aux_dict = dict(zip(aux_keys, self._aux_get(pkg.cpv, aux_keys)))
			perform_global_updates(
				pkg.cpv, aux_dict, self.dbapi, self._global_updates)
Ejemplo n.º 7
0
	def _apply_dynamic_deps(self, pkg, live_metadata):

		try:
			if live_metadata is None:
				raise _DynamicDepsNotApplicable()
			# Use the metadata from the installed instance if the EAPI
			# of either instance is unsupported, since if the installed
			# instance has an unsupported or corrupt EAPI then we don't
			# want to attempt to do complex operations such as execute
			# pkg_config, pkg_prerm or pkg_postrm phases. If both EAPIs
			# are supported then go ahead and use the live_metadata, in
			# order to respect dep updates without revision bump or EAPI
			# bump, as in bug #368725.
			if not (portage.eapi_is_supported(live_metadata["EAPI"]) and \
				portage.eapi_is_supported(pkg.eapi)):
				raise _DynamicDepsNotApplicable()

			# preserve built slot/sub-slot := operator deps
			built_slot_operator_atoms = None
			if not self._ignore_built_slot_operator_deps and \
				_get_eapi_attrs(pkg.eapi).slot_operator:
				try:
					built_slot_operator_atoms = \
						find_built_slot_operator_atoms(pkg)
				except InvalidDependString:
					pass

			if built_slot_operator_atoms:
				live_eapi_attrs = _get_eapi_attrs(live_metadata["EAPI"])
				if not live_eapi_attrs.slot_operator:
					raise _DynamicDepsNotApplicable()
				for k, v in built_slot_operator_atoms.items():
					live_metadata[k] += (" " +
						" ".join(_unicode(atom) for atom in v))

			self.dbapi.aux_update(pkg.cpv, live_metadata)
		except _DynamicDepsNotApplicable:
			if self._global_updates is None:
				self._global_updates = \
					grab_global_updates(self._portdb)

			# Bypass _aux_get_wrapper, since calling that
			# here would trigger infinite recursion.
			aux_keys = Package._dep_keys + self.dbapi._pkg_str_aux_keys
			aux_dict = dict(zip(aux_keys, self._aux_get(pkg.cpv, aux_keys)))
			perform_global_updates(
				pkg.cpv, aux_dict, self.dbapi, self._global_updates)
Ejemplo n.º 8
0
	def __init__(self, **kwargs):
		metadata = _PackageMetadataWrapperBase(kwargs.pop('metadata'))
		Task.__init__(self, **kwargs)
		# the SlotObject constructor assigns self.root_config from keyword args
		# and is an instance of a '_emerge.RootConfig.RootConfig class
		self.root = self.root_config.root
		self._raw_metadata = metadata
		self._metadata = _PackageMetadataWrapper(self, metadata)
		if not self.built:
			self._metadata['CHOST'] = self.root_config.settings.get('CHOST', '')
		eapi_attrs = _get_eapi_attrs(self.eapi)
		self.cpv = _pkg_str(self.cpv, metadata=self._metadata,
			settings=self.root_config.settings)
		if hasattr(self.cpv, 'slot_invalid'):
			self._invalid_metadata('SLOT.invalid',
				"SLOT: invalid value: '%s'" % self._metadata["SLOT"])
		self.cpv_split = self.cpv.cpv_split
		self.category, self.pf = portage.catsplit(self.cpv)
		self.cp = self.cpv.cp
		self.version = self.cpv.version
		self.slot = self.cpv.slot
		self.sub_slot = self.cpv.sub_slot
		self.slot_atom = Atom("%s%s%s" % (self.cp, _slot_separator, self.slot))
		# sync metadata with validated repo (may be UNKNOWN_REPO)
		self._metadata['repository'] = self.cpv.repo

		if eapi_attrs.iuse_effective:
			implicit_match = self.root_config.settings._iuse_effective_match
			if self.built:
				implicit_match = functools.partial(
					self._built_iuse_effective_match,
					implicit_match, frozenset(self._metadata['USE'].split()))
		else:
			implicit_match = self.root_config.settings._iuse_implicit_match
		usealiases = self.root_config.settings._use_manager.getUseAliases(self)
		self.iuse = self._iuse(self, self._metadata["IUSE"].split(), implicit_match,
			usealiases, self.eapi)

		if (self.iuse.enabled or self.iuse.disabled) and \
			not eapi_attrs.iuse_defaults:
			if not self.installed:
				self._invalid_metadata('EAPI.incompatible',
					"IUSE contains defaults, but EAPI doesn't allow them")
		if self.inherited is None:
			self.inherited = frozenset()

		if self.operation is None:
			if self.onlydeps or self.installed:
				self.operation = "nomerge"
			else:
				self.operation = "merge"

		self._hash_key = Package._gen_hash_key(cpv=self.cpv,
			installed=self.installed, onlydeps=self.onlydeps,
			operation=self.operation, repo_name=self.cpv.repo,
			root_config=self.root_config,
			type_name=self.type_name)
		self._hash_value = hash(self._hash_key)
Ejemplo n.º 9
0
    def __init__(self,
                 cpv,
                 metadata=None,
                 settings=None,
                 eapi=None,
                 repo=None,
                 slot=None):
        if not isinstance(cpv, _unicode):
            # Avoid TypeError from _unicode.__init__ with PyPy.
            cpv = _unicode_decode(cpv)
        _unicode.__init__(cpv)
        if metadata is not None:
            self.__dict__['_metadata'] = metadata
            slot = metadata.get('SLOT', slot)
            repo = metadata.get('repository', repo)
            eapi = metadata.get('EAPI', eapi)
        if settings is not None:
            self.__dict__['_settings'] = settings
        if eapi is not None:
            self.__dict__['eapi'] = eapi
        self.__dict__['cpv_split'] = catpkgsplit(cpv, eapi=eapi)
        if self.cpv_split is None:
            raise InvalidData(cpv)
        self.__dict__['cp'] = self.cpv_split[0] + '/' + self.cpv_split[1]
        if self.cpv_split[-1] == "r0" and cpv[-3:] != "-r0":
            self.__dict__['version'] = "-".join(self.cpv_split[2:-1])
        else:
            self.__dict__['version'] = "-".join(self.cpv_split[2:])
        # for match_from_list introspection
        self.__dict__['cpv'] = self
        if slot is not None:
            eapi_attrs = _get_eapi_attrs(eapi)
            slot_match = _get_slot_re(eapi_attrs).match(slot)
            if slot_match is None:
                # Avoid an InvalidAtom exception when creating SLOT atoms
                self.__dict__['slot'] = '0'
                self.__dict__['sub_slot'] = '0'
                self.__dict__['slot_invalid'] = slot
            else:
                if eapi_attrs.slot_operator:
                    slot_split = slot.split("/")
                    self.__dict__['slot'] = slot_split[0]
                    if len(slot_split) > 1:
                        self.__dict__['sub_slot'] = slot_split[1]
                    else:
                        self.__dict__['sub_slot'] = slot_split[0]
                else:
                    self.__dict__['slot'] = slot
                    self.__dict__['sub_slot'] = slot

        if repo is not None:
            repo = _gen_valid_repo(repo)
            if not repo:
                repo = _unknown_repo
            self.__dict__['repo'] = repo
Ejemplo n.º 10
0
	def _repoman_iuse_implicit_cnstr(self, pkg, metadata):
		"""
		In repoman's version of _iuse_implicit_cnstr, account for modifications
		of the self.settings reference between calls.
		"""
		eapi_attrs = _get_eapi_attrs(metadata["EAPI"])
		if eapi_attrs.iuse_effective:
			iuse_implicit_match = lambda flag: self.settings._iuse_effective_match(flag)
		else:
			iuse_implicit_match = lambda flag: self.settings._iuse_implicit_match(flag)
		return iuse_implicit_match
Ejemplo n.º 11
0
	def _repoman_iuse_implicit_cnstr(self, pkg, metadata):
		"""
		In repoman's version of _iuse_implicit_cnstr, account for modifications
		of the self.settings reference between calls.
		"""
		eapi_attrs = _get_eapi_attrs(metadata["EAPI"])
		if eapi_attrs.iuse_effective:
			iuse_implicit_match = lambda flag: self.settings._iuse_effective_match(flag)
		else:
			iuse_implicit_match = lambda flag: self.settings._iuse_implicit_match(flag)
		return iuse_implicit_match
Ejemplo n.º 12
0
    def __init__(self, cpv, metadata=None, settings=None, eapi=None, repo=None, slot=None):
        if not isinstance(cpv, _unicode):
            # Avoid TypeError from _unicode.__init__ with PyPy.
            cpv = _unicode_decode(cpv)
        _unicode.__init__(cpv)
        if metadata is not None:
            self.__dict__["_metadata"] = metadata
            slot = metadata.get("SLOT", slot)
            repo = metadata.get("repository", repo)
            eapi = metadata.get("EAPI", eapi)
        if settings is not None:
            self.__dict__["_settings"] = settings
        if eapi is not None:
            self.__dict__["eapi"] = eapi
        self.__dict__["cpv_split"] = catpkgsplit(cpv, eapi=eapi)
        if self.cpv_split is None:
            raise InvalidData(cpv)
        self.__dict__["cp"] = self.cpv_split[0] + "/" + self.cpv_split[1]
        if self.cpv_split[-1] == "r0" and cpv[-3:] != "-r0":
            self.__dict__["version"] = "-".join(self.cpv_split[2:-1])
        else:
            self.__dict__["version"] = "-".join(self.cpv_split[2:])
            # for match_from_list introspection
        self.__dict__["cpv"] = self
        if slot is not None:
            eapi_attrs = _get_eapi_attrs(eapi)
            slot_match = _get_slot_re(eapi_attrs).match(slot)
            if slot_match is None:
                # Avoid an InvalidAtom exception when creating SLOT atoms
                self.__dict__["slot"] = "0"
                self.__dict__["sub_slot"] = "0"
                self.__dict__["slot_invalid"] = slot
            else:
                if eapi_attrs.slot_operator:
                    slot_split = slot.split("/")
                    self.__dict__["slot"] = slot_split[0]
                    if len(slot_split) > 1:
                        self.__dict__["sub_slot"] = slot_split[1]
                    else:
                        self.__dict__["sub_slot"] = slot_split[0]
                else:
                    self.__dict__["slot"] = slot
                    self.__dict__["sub_slot"] = slot

        if repo is not None:
            repo = _gen_valid_repo(repo)
            if not repo:
                repo = _unknown_repo
            self.__dict__["repo"] = repo
Ejemplo n.º 13
0
    def recheck_hidden(self, pkg):
        """ Prevent USE_EXPAND_HIDDEN flags from being hidden if they
		are the only thing that triggered reinstallation.

		@param pkg: _emerge.Package.Package instance
		Modifies self.use_expand_hidden, self.use_expand, self.verboseadd
		"""
        reinst_flags_map = {}
        reinstall_for_flags = self.conf.reinstall_nodes.get(pkg)
        reinst_expand_map = None
        if reinstall_for_flags:
            reinst_flags_map = self.map_to_use_expand(
                list(reinstall_for_flags), remove_hidden=False)
            for k in list(reinst_flags_map):
                if not reinst_flags_map[k]:
                    del reinst_flags_map[k]
            if not reinst_flags_map.get("USE"):
                reinst_expand_map = reinst_flags_map.copy()
                reinst_expand_map.pop("USE", None)
        if reinst_expand_map and \
         not set(reinst_expand_map).difference(
         self.use_expand_hidden):
            self.use_expand_hidden = \
             set(self.use_expand_hidden).difference(
             reinst_expand_map)

        cur_iuse_map, iuse_forced = \
         self.map_to_use_expand(self.cur_iuse, forced_flags=True)
        cur_use_map = self.map_to_use_expand(self.cur_use)
        old_iuse_map = self.map_to_use_expand(self.old_iuse)
        old_use_map = self.map_to_use_expand(self.old_use)

        use_expand = sorted(self.use_expand)
        use_expand.insert(0, "USE")
        feature_flags = _get_feature_flags(
            _get_eapi_attrs(pkg.metadata["EAPI"]))

        for key in use_expand:
            if key in self.use_expand_hidden:
                continue
            self.verboseadd += _create_use_string(
                self.conf, key.upper(), cur_iuse_map[key], iuse_forced[key],
                cur_use_map[key], old_iuse_map[key], old_use_map[key],
                self.is_new, feature_flags, reinst_flags_map.get(key))
        return
Ejemplo n.º 14
0
	def recheck_hidden(self, pkg):
		""" Prevent USE_EXPAND_HIDDEN flags from being hidden if they
		are the only thing that triggered reinstallation.

		@param pkg: _emerge.Package.Package instance
		Modifies self.use_expand_hidden, self.use_expand, self.verboseadd
		"""
		reinst_flags_map = {}
		reinstall_for_flags = self.conf.reinstall_nodes.get(pkg)
		reinst_expand_map = None
		if reinstall_for_flags:
			reinst_flags_map = self.map_to_use_expand(
				list(reinstall_for_flags), remove_hidden=False)
			for k in list(reinst_flags_map):
				if not reinst_flags_map[k]:
					del reinst_flags_map[k]
			if not reinst_flags_map.get("USE"):
				reinst_expand_map = reinst_flags_map.copy()
				reinst_expand_map.pop("USE", None)
		if reinst_expand_map and \
			not set(reinst_expand_map).difference(
			self.use_expand_hidden):
			self.use_expand_hidden = \
				set(self.use_expand_hidden).difference(
				reinst_expand_map)

		cur_iuse_map, iuse_forced = \
			self.map_to_use_expand(self.cur_iuse, forced_flags=True)
		cur_use_map = self.map_to_use_expand(self.cur_use)
		old_iuse_map = self.map_to_use_expand(self.old_iuse)
		old_use_map = self.map_to_use_expand(self.old_use)

		use_expand = sorted(self.use_expand)
		use_expand.insert(0, "USE")
		feature_flags = _get_feature_flags(_get_eapi_attrs(pkg.metadata["EAPI"]))

		for key in use_expand:
			if key in self.use_expand_hidden:
				continue
			self.verboseadd += _create_use_string(self.conf, key.upper(),
				cur_iuse_map[key], iuse_forced[key],
				cur_use_map[key], old_iuse_map[key],
				old_use_map[key], self.is_new, feature_flags,
				reinst_flags_map.get(key))
		return
Ejemplo n.º 15
0
def _pkgsplit(mypkg, eapi=None):
    """
	@param mypkg: pv
	@return:
	1. None if input is invalid.
	2. (pn, ver, rev) if input is pv
	"""
    m = _get_pv_re(_get_eapi_attrs(eapi)).match(mypkg)
    if m is None:
        return None

    if m.group('pn_inval') is not None:
        # package name appears to have a version-like suffix
        return None

    rev = m.group('rev')
    if rev is None:
        rev = '0'
    rev = 'r' + rev

    return (m.group('pn'), m.group('ver'), rev)
Ejemplo n.º 16
0
def _pkgsplit(mypkg, eapi=None):
	"""
	@param mypkg: pv
	@return:
	1. None if input is invalid.
	2. (pn, ver, rev) if input is pv
	"""
	m = _get_pv_re(_get_eapi_attrs(eapi)).match(mypkg)
	if m is None:
		return None

	if m.group('pn_inval') is not None:
		# package name appears to have a version-like suffix
		return None

	rev = m.group('rev')
	if rev is None:
		rev = '0'
	rev = 'r' + rev

	return  (m.group('pn'), m.group('ver'), rev) 
Ejemplo n.º 17
0
	def _iuse_implicit_cnstr(self, pkg, metadata):
		"""
		Construct a callable that checks if a given USE flag should
		be considered to be a member of the implicit IUSE for the
		given package.

		@param pkg: package
		@type pkg: _pkg_str
		@param metadata: package metadata
		@type metadata: Mapping
		@return: a callable that accepts a single USE flag argument,
			and returns True only if the USE flag should be considered
			to be a member of the implicit IUSE for the given package.
		@rtype: callable
		"""
		eapi_attrs = _get_eapi_attrs(metadata["EAPI"])
		if eapi_attrs.iuse_effective:
			iuse_implicit_match = self.settings._iuse_effective_match
		else:
			iuse_implicit_match = self.settings._iuse_implicit_match

		if not self._use_mutable and eapi_attrs.iuse_effective:
			# For built packages, it is desirable for the built USE setting to
			# be independent of the profile's current IUSE_IMPLICIT state, since
			# the profile's IUSE_IMPLICT setting may have diverged. Therefore,
			# any member of the built USE setting is considered to be a valid
			# member of IUSE_EFFECTIVE. Note that the binary package may be
			# remote, so it's only possible to rely on metadata that is available
			# in the remote Packages file, and the IUSE_IMPLICIT header in the
			# Packages file is vulnerable to mutation (see bug 640318).
			#
			# This behavior is only used for EAPIs that support IUSE_EFFECTIVE,
			# since built USE settings for earlier EAPIs may contain a large
			# number of irrelevant flags.
			prof_iuse = iuse_implicit_match
			enabled = frozenset(metadata["USE"].split()).__contains__
			iuse_implicit_match = lambda flag: prof_iuse(flag) or enabled(flag)

		return iuse_implicit_match
Ejemplo n.º 18
0
    def _iuse_implicit_cnstr(self, pkg, metadata):
        """
        Construct a callable that checks if a given USE flag should
        be considered to be a member of the implicit IUSE for the
        given package.

        @param pkg: package
        @type pkg: _pkg_str
        @param metadata: package metadata
        @type metadata: Mapping
        @return: a callable that accepts a single USE flag argument,
                and returns True only if the USE flag should be considered
                to be a member of the implicit IUSE for the given package.
        @rtype: callable
        """
        eapi_attrs = _get_eapi_attrs(metadata["EAPI"])
        if eapi_attrs.iuse_effective:
            iuse_implicit_match = self.settings._iuse_effective_match
        else:
            iuse_implicit_match = self.settings._iuse_implicit_match

        if not self._use_mutable and eapi_attrs.iuse_effective:
            # For built packages, it is desirable for the built USE setting to
            # be independent of the profile's current IUSE_IMPLICIT state, since
            # the profile's IUSE_IMPLICT setting may have diverged. Therefore,
            # any member of the built USE setting is considered to be a valid
            # member of IUSE_EFFECTIVE. Note that the binary package may be
            # remote, so it's only possible to rely on metadata that is available
            # in the remote Packages file, and the IUSE_IMPLICIT header in the
            # Packages file is vulnerable to mutation (see bug 640318).
            #
            # This behavior is only used for EAPIs that support IUSE_EFFECTIVE,
            # since built USE settings for earlier EAPIs may contain a large
            # number of irrelevant flags.
            prof_iuse = iuse_implicit_match
            enabled = frozenset(metadata["USE"].split()).__contains__
            iuse_implicit_match = lambda flag: prof_iuse(flag) or enabled(flag)

        return iuse_implicit_match
Ejemplo n.º 19
0
    def __init__(self, **kwargs):
        metadata = _PackageMetadataWrapperBase(kwargs.pop("metadata"))
        Task.__init__(self, **kwargs)
        # the SlotObject constructor assigns self.root_config from keyword args
        # and is an instance of a '_emerge.RootConfig.RootConfig class
        self.root = self.root_config.root
        self._raw_metadata = metadata
        self._metadata = _PackageMetadataWrapper(self, metadata)
        if not self.built:
            self._metadata["CHOST"] = self.root_config.settings.get("CHOST", "")
        eapi_attrs = _get_eapi_attrs(self.eapi)

        try:
            db = self.cpv._db
        except AttributeError:
            if self.built:
                # For independence from the source ebuild repository and
                # profile implicit IUSE state, require the _db attribute
                # for built packages.
                raise
            db = self.root_config.trees["porttree"].dbapi

        self.cpv = _pkg_str(
            self.cpv, metadata=self._metadata, settings=self.root_config.settings, db=db
        )
        if hasattr(self.cpv, "slot_invalid"):
            self._invalid_metadata(
                "SLOT.invalid", "SLOT: invalid value: '%s'" % self._metadata["SLOT"]
            )
        self.cpv_split = self.cpv.cpv_split
        self.category, self.pf = portage.catsplit(self.cpv)
        self.cp = self.cpv.cp
        self.version = self.cpv.version
        self.slot = self.cpv.slot
        self.sub_slot = self.cpv.sub_slot
        self.slot_atom = Atom("%s%s%s" % (self.cp, _slot_separator, self.slot))
        # sync metadata with validated repo (may be UNKNOWN_REPO)
        self._metadata["repository"] = self.cpv.repo

        implicit_match = db._iuse_implicit_cnstr(self.cpv, self._metadata)
        self.iuse = self._iuse(
            self, self._metadata["IUSE"].split(), implicit_match, self.eapi
        )

        if (self.iuse.enabled or self.iuse.disabled) and not eapi_attrs.iuse_defaults:
            if not self.installed:
                self._invalid_metadata(
                    "EAPI.incompatible",
                    "IUSE contains defaults, but EAPI doesn't allow them",
                )
        if self.inherited is None:
            self.inherited = frozenset()

        if self.operation is None:
            if self.onlydeps or self.installed:
                self.operation = "nomerge"
            else:
                self.operation = "merge"

        self._hash_key = Package._gen_hash_key(
            cpv=self.cpv,
            installed=self.installed,
            onlydeps=self.onlydeps,
            operation=self.operation,
            repo_name=self.cpv.repo,
            root_config=self.root_config,
            type_name=self.type_name,
        )
        self._hash_value = hash(self._hash_key)
Ejemplo n.º 20
0
	def _match_use(self, atom, cpv, metadata):
		eapi_attrs = _get_eapi_attrs(metadata["EAPI"])
		if eapi_attrs.iuse_effective:
			iuse_implicit_match = self.settings._iuse_effective_match
		else:
			iuse_implicit_match = self.settings._iuse_implicit_match
		iuse = frozenset(x.lstrip('+-') for x in metadata["IUSE"].split())

		for x in atom.unevaluated_atom.use.required:
			if x not in iuse and not iuse_implicit_match(x):
				return False

		if atom.use is None:
			pass

		elif not self._use_mutable:
			# Use IUSE to validate USE settings for built packages,
			# in case the package manager that built this package
			# failed to do that for some reason (or in case of
			# data corruption).
			use = frozenset(x for x in metadata["USE"].split()
				if x in iuse or iuse_implicit_match(x))
			missing_enabled = atom.use.missing_enabled.difference(iuse)
			missing_disabled = atom.use.missing_disabled.difference(iuse)

			if atom.use.enabled:
				if any(x in atom.use.enabled for x in missing_disabled):
					return False
				need_enabled = atom.use.enabled.difference(use)
				if need_enabled:
					if any(x not in missing_enabled for x in need_enabled):
						return False

			if atom.use.disabled:
				if any(x in atom.use.disabled for x in missing_enabled):
					return False
				need_disabled = atom.use.disabled.intersection(use)
				if need_disabled:
					if any(x not in missing_disabled for x in need_disabled):
						return False

		elif not self.settings.local_config:
			# Check masked and forced flags for repoman.
			try:
				cpv.slot
			except AttributeError:
				pkg = _pkg_str(cpv, metadata=metadata, settings=self.settings)
			else:
				pkg = cpv
			usemask = self.settings._getUseMask(pkg)
			if any(x in usemask for x in atom.use.enabled):
				return False

			useforce = self.settings._getUseForce(pkg)
			if any(x in useforce and x not in usemask
				for x in atom.use.disabled):
				return False

			# Check unsatisfied use-default deps
			if atom.use.enabled:
				missing_disabled = atom.use.missing_disabled.difference(iuse)
				if any(x in atom.use.enabled for x in missing_disabled):
					return False
			if atom.use.disabled:
				missing_enabled = atom.use.missing_enabled.difference(iuse)
				if any(x in atom.use.disabled for x in missing_enabled):
					return False

		return True
Ejemplo n.º 21
0
def expand_new_virt(vardb, atom):
    """
	Iterate over the recursively expanded RDEPEND atoms of
	a new-style virtual. If atom is not a new-style virtual
	or it does not match an installed package then it is
	yielded without any expansion.
	"""
    if not isinstance(atom, Atom):
        atom = Atom(atom)

    if not atom.cp.startswith("virtual/"):
        yield atom
        return

    traversed = set()
    stack = [atom]

    while stack:
        atom = stack.pop()
        if atom.blocker or \
         not atom.cp.startswith("virtual/"):
            yield atom
            continue

        matches = vardb.match(atom)
        if not (matches and matches[-1].startswith("virtual/")):
            yield atom
            continue

        virt_cpv = matches[-1]
        if virt_cpv in traversed:
            continue

        traversed.add(virt_cpv)
        eapi, iuse, rdepend, use = vardb.aux_get(
            virt_cpv, ["EAPI", "IUSE", "RDEPEND", "USE"])
        if not portage.eapi_is_supported(eapi):
            yield atom
            continue

        eapi_attrs = _get_eapi_attrs(eapi)
        # Validate IUSE and IUSE, for early detection of vardb corruption.
        useflag_re = _get_useflag_re(eapi)
        valid_iuse = []
        for x in iuse.split():
            if x[:1] in ("+", "-"):
                x = x[1:]
            if useflag_re.match(x) is not None:
                valid_iuse.append(x)
        valid_iuse = frozenset(valid_iuse)

        if eapi_attrs.iuse_effective:
            iuse_implicit_match = vardb.settings._iuse_effective_match
        else:
            iuse_implicit_match = vardb.settings._iuse_implicit_match

        valid_use = []
        for x in use.split():
            if x in valid_iuse or iuse_implicit_match(x):
                valid_use.append(x)
        valid_use = frozenset(valid_use)

        success, atoms = portage.dep_check(rdepend,
                                           None,
                                           vardb.settings,
                                           myuse=valid_use,
                                           myroot=vardb.settings['EROOT'],
                                           trees={
                                               vardb.settings['EROOT']: {
                                                   "porttree": vardb.vartree,
                                                   "vartree": vardb.vartree
                                               }
                                           })

        if success:
            stack.extend(atoms)
        else:
            yield atom
Ejemplo n.º 22
0
    def _match_use(self, atom, pkg, metadata):
        eapi_attrs = _get_eapi_attrs(metadata["EAPI"])
        if eapi_attrs.iuse_effective:
            iuse_implicit_match = self.settings._iuse_effective_match
        else:
            iuse_implicit_match = self.settings._iuse_implicit_match
        usealiases = self.settings._use_manager.getUseAliases(pkg)
        iuse = Package._iuse(None, metadata["IUSE"].split(),
                             iuse_implicit_match, usealiases, metadata["EAPI"])

        for x in atom.unevaluated_atom.use.required:
            if iuse.get_real_flag(x) is None:
                return False

        if atom.use is None:
            pass

        elif not self._use_mutable:
            # Use IUSE to validate USE settings for built packages,
            # in case the package manager that built this package
            # failed to do that for some reason (or in case of
            # data corruption). The enabled flags must be consistent
            # with implicit IUSE, in order to avoid potential
            # inconsistencies in USE dep matching (see bug #453400).
            use = frozenset(x for x in metadata["USE"].split()
                            if iuse.get_real_flag(x) is not None)
            missing_enabled = frozenset(x for x in atom.use.missing_enabled
                                        if iuse.get_real_flag(x) is None)
            missing_disabled = frozenset(x for x in atom.use.missing_disabled
                                         if iuse.get_real_flag(x) is None)
            enabled = frozenset(
                (iuse.get_real_flag(x) or x) for x in atom.use.enabled)
            disabled = frozenset(
                (iuse.get_real_flag(x) or x) for x in atom.use.disabled)

            if enabled:
                if any(x in enabled for x in missing_disabled):
                    return False
                need_enabled = enabled.difference(use)
                if need_enabled:
                    if any(x not in missing_enabled for x in need_enabled):
                        return False

            if disabled:
                if any(x in disabled for x in missing_enabled):
                    return False
                need_disabled = disabled.intersection(use)
                if need_disabled:
                    if any(x not in missing_disabled for x in need_disabled):
                        return False

        elif not self.settings.local_config:
            # Check masked and forced flags for repoman.
            usemask = self.settings._getUseMask(
                pkg, stable=self.settings._parent_stable)
            if any(x in usemask for x in atom.use.enabled):
                return False

            useforce = self.settings._getUseForce(
                pkg, stable=self.settings._parent_stable)
            if any(x in useforce and x not in usemask
                   for x in atom.use.disabled):
                return False

            # Check unsatisfied use-default deps
            if atom.use.enabled:
                missing_disabled = frozenset(x
                                             for x in atom.use.missing_disabled
                                             if iuse.get_real_flag(x) is None)
                if any(x in atom.use.enabled for x in missing_disabled):
                    return False
            if atom.use.disabled:
                missing_enabled = frozenset(x for x in atom.use.missing_enabled
                                            if iuse.get_real_flag(x) is None)
                if any(x in atom.use.disabled for x in missing_enabled):
                    return False

        return True
Ejemplo n.º 23
0
	def _validate_deps(self):
		"""
		Validate deps. This does not trigger USE calculation since that
		is expensive for ebuilds and therefore we want to avoid doing
		it unnecessarily (like for masked packages).
		"""
		eapi = self.eapi
		dep_eapi = eapi
		dep_valid_flag = self.iuse.is_valid_flag
		if self.installed:
			# Ignore EAPI.incompatible and conditionals missing
			# from IUSE for installed packages since these issues
			# aren't relevant now (re-evaluate when new EAPIs are
			# deployed).
			dep_eapi = None
			dep_valid_flag = None

		validated_atoms = []
		for k in self._dep_keys:
			v = self._metadata.get(k)
			if not v:
				continue
			try:
				atoms = use_reduce(v, eapi=dep_eapi,
					matchall=True, is_valid_flag=dep_valid_flag,
					token_class=Atom, flat=True)
			except InvalidDependString as e:
				self._metadata_exception(k, e)
			else:
				validated_atoms.extend(atoms)
				if not self.built:
					for atom in atoms:
						if not isinstance(atom, Atom):
							continue
						if atom.slot_operator_built:
							e = InvalidDependString(
								_("Improper context for slot-operator "
								"\"built\" atom syntax: %s") %
								(atom.unevaluated_atom,))
							self._metadata_exception(k, e)

		self._validated_atoms = tuple(set(atom for atom in
			validated_atoms if isinstance(atom, Atom)))

		for k in self._use_conditional_misc_keys:
			v = self._metadata.get(k)
			if not v:
				continue
			try:
				use_reduce(v, eapi=dep_eapi, matchall=True,
					is_valid_flag=dep_valid_flag)
			except InvalidDependString as e:
				self._metadata_exception(k, e)

		k = 'REQUIRED_USE'
		v = self._metadata.get(k)
		if v and not self.built:
			if not _get_eapi_attrs(eapi).required_use:
				self._invalid_metadata('EAPI.incompatible',
					"REQUIRED_USE set, but EAPI='%s' doesn't allow it" % eapi)
			else:
				try:
					check_required_use(v, (),
						self.iuse.is_valid_flag, eapi=eapi)
				except InvalidDependString as e:
					self._invalid_metadata(k + ".syntax", "%s: %s" % (k, e))

		k = 'SRC_URI'
		v = self._metadata.get(k)
		if v:
			try:
				use_reduce(v, is_src_uri=True, eapi=eapi, matchall=True,
					is_valid_flag=self.iuse.is_valid_flag)
			except InvalidDependString as e:
				if not self.installed:
					self._metadata_exception(k, e)

		if self.built:
			k = 'PROVIDES'
			try:
				self._provides = frozenset(
					parse_soname_deps(self._metadata[k]))
			except InvalidData as e:
				self._invalid_metadata(k + ".syntax", "%s: %s" % (k, e))

			k = 'REQUIRES'
			try:
				self._requires = frozenset(
					parse_soname_deps(self._metadata[k]))
			except InvalidData as e:
				self._invalid_metadata(k + ".syntax", "%s: %s" % (k, e))
Ejemplo n.º 24
0
	def _match_use(self, atom, pkg, metadata, ignore_profile=False):
		eapi_attrs = _get_eapi_attrs(metadata["EAPI"])
		if eapi_attrs.iuse_effective:
			iuse_implicit_match = self.settings._iuse_effective_match
		else:
			iuse_implicit_match = self.settings._iuse_implicit_match
		usealiases = self.settings._use_manager.getUseAliases(pkg)
		iuse = Package._iuse(None, metadata["IUSE"].split(), iuse_implicit_match, usealiases, metadata["EAPI"])

		for x in atom.unevaluated_atom.use.required:
			if iuse.get_real_flag(x) is None:
				return False

		if atom.use is None:
			pass

		elif not self._use_mutable:
			# Use IUSE to validate USE settings for built packages,
			# in case the package manager that built this package
			# failed to do that for some reason (or in case of
			# data corruption). The enabled flags must be consistent
			# with implicit IUSE, in order to avoid potential
			# inconsistencies in USE dep matching (see bug #453400).
			use = frozenset(x for x in metadata["USE"].split() if iuse.get_real_flag(x) is not None)
			missing_enabled = frozenset(x for x in atom.use.missing_enabled if iuse.get_real_flag(x) is None)
			missing_disabled = frozenset(x for x in atom.use.missing_disabled if iuse.get_real_flag(x) is None)
			enabled = frozenset((iuse.get_real_flag(x) or x) for x in atom.use.enabled)
			disabled = frozenset((iuse.get_real_flag(x) or x) for x in atom.use.disabled)

			if enabled:
				if any(x in enabled for x in missing_disabled):
					return False
				need_enabled = enabled.difference(use)
				if need_enabled:
					if any(x not in missing_enabled for x in need_enabled):
						return False

			if disabled:
				if any(x in disabled for x in missing_enabled):
					return False
				need_disabled = disabled.intersection(use)
				if need_disabled:
					if any(x not in missing_disabled for x in need_disabled):
						return False

		elif not self.settings.local_config:
			if not ignore_profile:
				# Check masked and forced flags for repoman.
				usemask = self.settings._getUseMask(pkg,
					stable=self.settings._parent_stable)
				if any(x in usemask for x in atom.use.enabled):
					return False

				useforce = self.settings._getUseForce(pkg,
					stable=self.settings._parent_stable)
				if any(x in useforce and x not in usemask
					for x in atom.use.disabled):
					return False

			# Check unsatisfied use-default deps
			if atom.use.enabled:
				missing_disabled = frozenset(x for x in atom.use.missing_disabled if iuse.get_real_flag(x) is None)
				if any(x in atom.use.enabled for x in missing_disabled):
					return False
			if atom.use.disabled:
				missing_enabled = frozenset(x for x in atom.use.missing_enabled if iuse.get_real_flag(x) is None)
				if any(x in atom.use.disabled for x in missing_enabled):
					return False

		return True
Ejemplo n.º 25
0
	def _validate_deps(self):
		"""
		Validate deps. This does not trigger USE calculation since that
		is expensive for ebuilds and therefore we want to avoid doing
		it unnecessarily (like for masked packages).
		"""
		eapi = self.eapi
		dep_eapi = eapi
		dep_valid_flag = self.iuse.is_valid_flag
		if self.installed:
			# Ignore EAPI.incompatible and conditionals missing
			# from IUSE for installed packages since these issues
			# aren't relevant now (re-evaluate when new EAPIs are
			# deployed).
			dep_eapi = None
			dep_valid_flag = None

		validated_atoms = []
		for k in self._dep_keys:
			v = self._metadata.get(k)
			if not v:
				continue
			try:
				atoms = use_reduce(v, eapi=dep_eapi,
					matchall=True, is_valid_flag=dep_valid_flag,
					token_class=Atom, flat=True)
			except InvalidDependString as e:
				self._metadata_exception(k, e)
			else:
				validated_atoms.extend(atoms)
				if not self.built:
					for atom in atoms:
						if not isinstance(atom, Atom):
							continue
						if atom.slot_operator_built:
							e = InvalidDependString(
								_("Improper context for slot-operator "
								"\"built\" atom syntax: %s") %
								(atom.unevaluated_atom,))
							self._metadata_exception(k, e)

		self._validated_atoms = tuple(set(atom for atom in
			validated_atoms if isinstance(atom, Atom)))

		k = 'PROVIDE'
		v = self._metadata.get(k)
		if v:
			try:
				use_reduce(v, eapi=dep_eapi, matchall=True,
					is_valid_flag=dep_valid_flag, token_class=Atom)
			except InvalidDependString as e:
				self._invalid_metadata("PROVIDE.syntax", "%s: %s" % (k, e))

		for k in self._use_conditional_misc_keys:
			v = self._metadata.get(k)
			if not v:
				continue
			try:
				use_reduce(v, eapi=dep_eapi, matchall=True,
					is_valid_flag=dep_valid_flag)
			except InvalidDependString as e:
				self._metadata_exception(k, e)

		k = 'REQUIRED_USE'
		v = self._metadata.get(k)
		if v and not self.built:
			if not _get_eapi_attrs(eapi).required_use:
				self._invalid_metadata('EAPI.incompatible',
					"REQUIRED_USE set, but EAPI='%s' doesn't allow it" % eapi)
			else:
				try:
					check_required_use(v, (),
						self.iuse.is_valid_flag, eapi=eapi)
				except InvalidDependString as e:
					self._invalid_metadata(k + ".syntax", "%s: %s" % (k, e))

		k = 'SRC_URI'
		v = self._metadata.get(k)
		if v:
			try:
				use_reduce(v, is_src_uri=True, eapi=eapi, matchall=True,
					is_valid_flag=self.iuse.is_valid_flag)
			except InvalidDependString as e:
				if not self.installed:
					self._metadata_exception(k, e)

		if self.built:
			k = 'PROVIDES'
			try:
				self._provides = frozenset(
					parse_soname_deps(self._metadata[k]))
			except InvalidData as e:
				self._invalid_metadata(k + ".syntax", "%s: %s" % (k, e))

			k = 'REQUIRES'
			try:
				self._requires = frozenset(
					parse_soname_deps(self._metadata[k]))
			except InvalidData as e:
				self._invalid_metadata(k + ".syntax", "%s: %s" % (k, e))
Ejemplo n.º 26
0
def expand_new_virt(vardb, atom):
	"""
	Iterate over the recursively expanded RDEPEND atoms of
	a new-style virtual. If atom is not a new-style virtual
	or it does not match an installed package then it is
	yielded without any expansion.
	"""
	if not isinstance(atom, Atom):
		atom = Atom(atom)

	if not atom.cp.startswith("virtual/"):
		yield atom
		return

	traversed = set()
	stack = [atom]

	while stack:
		atom = stack.pop()
		if atom.blocker or \
			not atom.cp.startswith("virtual/"):
			yield atom
			continue

		matches = vardb.match(atom)
		if not (matches and matches[-1].startswith("virtual/")):
			yield atom
			continue

		virt_cpv = matches[-1]
		if virt_cpv in traversed:
			continue

		traversed.add(virt_cpv)
		eapi, iuse, rdepend, use = vardb.aux_get(virt_cpv,
			["EAPI", "IUSE", "RDEPEND", "USE"])
		if not portage.eapi_is_supported(eapi):
			yield atom
			continue

		eapi_attrs = _get_eapi_attrs(eapi)
		# Validate IUSE and IUSE, for early detection of vardb corruption.
		useflag_re = _get_useflag_re(eapi)
		valid_iuse = []
		for x in iuse.split():
			if x[:1] in ("+", "-"):
				x = x[1:]
			if useflag_re.match(x) is not None:
				valid_iuse.append(x)
		valid_iuse = frozenset(valid_iuse)

		if eapi_attrs.iuse_effective:
			iuse_implicit_match = vardb.settings._iuse_effective_match
		else:
			iuse_implicit_match = vardb.settings._iuse_implicit_match

		valid_use = []
		for x in use.split():
			if x in valid_iuse or iuse_implicit_match(x):
				valid_use.append(x)
		valid_use = frozenset(valid_use)

		success, atoms = portage.dep_check(rdepend,
			None, vardb.settings, myuse=valid_use,
			myroot=vardb.settings['EROOT'],
			trees={vardb.settings['EROOT']:{"porttree":vardb.vartree,
			"vartree":vardb.vartree}})

		if success:
			stack.extend(atoms)
		else:
			yield atom
Ejemplo n.º 27
0
    def __init__(
        self,
        cpv,
        metadata=None,
        settings=None,
        eapi=None,
        repo=None,
        slot=None,
        build_time=None,
        build_id=None,
        file_size=None,
        mtime=None,
        db=None,
    ):
        if not isinstance(cpv, str):
            # Avoid TypeError from str.__init__ with PyPy.
            cpv = _unicode_decode(cpv)
        str.__init__(cpv)
        if metadata is not None:
            self.__dict__["_metadata"] = metadata
            slot = metadata.get("SLOT", slot)
            repo = metadata.get("repository", repo)
            eapi = metadata.get("EAPI", eapi)
            build_time = metadata.get("BUILD_TIME", build_time)
            file_size = metadata.get("SIZE", file_size)
            build_id = metadata.get("BUILD_ID", build_id)
            mtime = metadata.get("_mtime_", mtime)
        if settings is not None:
            self.__dict__["_settings"] = settings
        if db is not None:
            self.__dict__["_db"] = db
        if eapi is not None:
            self.__dict__["eapi"] = eapi

        self.__dict__["build_time"] = self._long(build_time, 0)
        self.__dict__["file_size"] = self._long(file_size, None)
        self.__dict__["build_id"] = self._long(build_id, None)
        self.__dict__["mtime"] = self._long(mtime, None)
        self.__dict__["cpv_split"] = catpkgsplit(cpv, eapi=eapi)
        if self.cpv_split is None:
            raise InvalidData(cpv)
        self.__dict__["cp"] = self.cpv_split[0] + "/" + self.cpv_split[1]
        if self.cpv_split[-1] == "r0" and cpv[-3:] != "-r0":
            self.__dict__["version"] = "-".join(self.cpv_split[2:-1])
        else:
            self.__dict__["version"] = "-".join(self.cpv_split[2:])
        # for match_from_list introspection
        self.__dict__["cpv"] = self
        if slot is not None:
            eapi_attrs = _get_eapi_attrs(eapi)
            slot_match = _get_slot_re(eapi_attrs).match(slot)
            if slot_match is None:
                # Avoid an InvalidAtom exception when creating SLOT atoms
                self.__dict__["slot"] = "0"
                self.__dict__["sub_slot"] = "0"
                self.__dict__["slot_invalid"] = slot
            else:
                if eapi_attrs.slot_operator:
                    slot_split = slot.split("/")
                    self.__dict__["slot"] = slot_split[0]
                    if len(slot_split) > 1:
                        self.__dict__["sub_slot"] = slot_split[1]
                    else:
                        self.__dict__["sub_slot"] = slot_split[0]
                else:
                    self.__dict__["slot"] = slot
                    self.__dict__["sub_slot"] = slot

        if repo is not None:
            repo = _gen_valid_repo(repo)
            if not repo:
                repo = _unknown_repo
            self.__dict__["repo"] = repo
Ejemplo n.º 28
0
	def _match_use(self, atom, cpv, metadata):
		eapi_attrs = _get_eapi_attrs(metadata["EAPI"])
		if eapi_attrs.iuse_effective:
			iuse_implicit_match = self.settings._iuse_effective_match
		else:
			iuse_implicit_match = self.settings._iuse_implicit_match
		iuse = frozenset(x.lstrip('+-') for x in metadata["IUSE"].split())

		for x in atom.unevaluated_atom.use.required:
			if x not in iuse and not iuse_implicit_match(x):
				return False

		if atom.use is None:
			pass

		elif not self._use_mutable:
			# Use IUSE to validate USE settings for built packages,
			# in case the package manager that built this package
			# failed to do that for some reason (or in case of
			# data corruption).
			use = frozenset(x for x in metadata["USE"].split()
				if x in iuse or iuse_implicit_match(x))
			missing_enabled = atom.use.missing_enabled.difference(iuse)
			missing_disabled = atom.use.missing_disabled.difference(iuse)

			if atom.use.enabled:
				if any(x in atom.use.enabled for x in missing_disabled):
					return False
				need_enabled = atom.use.enabled.difference(use)
				if need_enabled:
					if any(x not in missing_enabled for x in need_enabled):
						return False

			if atom.use.disabled:
				if any(x in atom.use.disabled for x in missing_enabled):
					return False
				need_disabled = atom.use.disabled.intersection(use)
				if need_disabled:
					if any(x not in missing_disabled for x in need_disabled):
						return False

		elif not self.settings.local_config:
			# Check masked and forced flags for repoman.
			try:
				cpv.slot
			except AttributeError:
				pkg = _pkg_str(cpv, metadata=metadata, settings=self.settings)
			else:
				pkg = cpv
			usemask = self.settings._getUseMask(pkg)
			if any(x in usemask for x in atom.use.enabled):
				return False

			useforce = self.settings._getUseForce(pkg)
			if any(x in useforce and x not in usemask
				for x in atom.use.disabled):
				return False

			# Check unsatisfied use-default deps
			if atom.use.enabled:
				missing_disabled = atom.use.missing_disabled.difference(iuse)
				if any(x in atom.use.enabled for x in missing_disabled):
					return False
			if atom.use.disabled:
				missing_enabled = atom.use.missing_enabled.difference(iuse)
				if any(x in atom.use.disabled for x in missing_enabled):
					return False

		return True
Ejemplo n.º 29
0
	def _display_use(self, pkg, pkg_info):
		""" USE flag display

		@param pkg: _emerge.Package.Package instance
		@param pkg_info: PkgInfo instance
		Modifies self.use_expand_hidden, self.use_expand, self.verboseadd,
			self.forced_flags
		"""

		self.forced_flags = set()
		self.forced_flags.update(pkg.use.force)
		self.forced_flags.update(pkg.use.mask)

		cur_use = [flag for flag in self.conf.pkg_use_enabled(pkg) \
			if flag in pkg.iuse.all]
		cur_iuse = sorted(pkg.iuse.all)

		if pkg_info.previous_pkg is not None:
			previous_pkg = pkg_info.previous_pkg
			old_iuse = sorted(previous_pkg.iuse.all)
			old_use = previous_pkg.use.enabled
			is_new = False
		else:
			old_iuse = []
			old_use = []
			is_new = True

		old_use = [flag for flag in old_use if flag in old_iuse]

		self.use_expand = pkg.use.expand
		self.use_expand_hidden = pkg.use.expand_hidden

		# Prevent USE_EXPAND_HIDDEN flags from being hidden if they
		# are the only thing that triggered reinstallation.
		reinst_flags_map = {}
		reinstall_for_flags = self.conf.reinstall_nodes.get(pkg)
		reinst_expand_map = None
		if reinstall_for_flags:
			reinst_flags_map = self.map_to_use_expand(
				list(reinstall_for_flags), remove_hidden=False)
			for k in list(reinst_flags_map):
				if not reinst_flags_map[k]:
					del reinst_flags_map[k]
			if not reinst_flags_map.get("USE"):
				reinst_expand_map = reinst_flags_map.copy()
				reinst_expand_map.pop("USE", None)
		if reinst_expand_map and \
			not set(reinst_expand_map).difference(
			self.use_expand_hidden):
			self.use_expand_hidden = \
				set(self.use_expand_hidden).difference(
				reinst_expand_map)

		cur_iuse_map, iuse_forced = \
			self.map_to_use_expand(cur_iuse, forced_flags=True)
		cur_use_map = self.map_to_use_expand(cur_use)
		old_iuse_map = self.map_to_use_expand(old_iuse)
		old_use_map = self.map_to_use_expand(old_use)

		use_expand = sorted(self.use_expand)
		use_expand.insert(0, "USE")
		feature_flags = _get_feature_flags(_get_eapi_attrs(pkg.eapi))

		for key in use_expand:
			if key in self.use_expand_hidden:
				continue
			self.verboseadd += _create_use_string(self.conf, key.upper(),
				cur_iuse_map[key], iuse_forced[key],
				cur_use_map[key], old_iuse_map[key],
				old_use_map[key], is_new, feature_flags,
				reinst_flags_map.get(key))
		return
Ejemplo n.º 30
0
    def _display_use(self, pkg, pkg_info):
        """ USE flag display

		@param pkg: _emerge.Package.Package instance
		@param pkg_info: PkgInfo instance
		Modifies self.use_expand_hidden, self.use_expand, self.verboseadd,
			self.forced_flags
		"""

        self.forced_flags = set()
        self.forced_flags.update(pkg.use.force)
        self.forced_flags.update(pkg.use.mask)

        cur_use = [flag for flag in self.conf.pkg_use_enabled(pkg) \
         if flag in pkg.iuse.all]
        cur_iuse = sorted(pkg.iuse.all)

        if pkg_info.previous_pkg is not None:
            previous_pkg = pkg_info.previous_pkg
            old_iuse = sorted(previous_pkg.iuse.all)
            old_use = previous_pkg.use.enabled
            is_new = False
        else:
            old_iuse = []
            old_use = []
            is_new = True

        old_use = [flag for flag in old_use if flag in old_iuse]

        self.use_expand = pkg.use.expand
        self.use_expand_hidden = pkg.use.expand_hidden

        # Prevent USE_EXPAND_HIDDEN flags from being hidden if they
        # are the only thing that triggered reinstallation.
        reinst_flags_map = {}
        reinstall_for_flags = self.conf.reinstall_nodes.get(pkg)
        reinst_expand_map = None
        if reinstall_for_flags:
            reinst_flags_map = self.map_to_use_expand(
                list(reinstall_for_flags), remove_hidden=False)
            for k in list(reinst_flags_map):
                if not reinst_flags_map[k]:
                    del reinst_flags_map[k]
            if not reinst_flags_map.get("USE"):
                reinst_expand_map = reinst_flags_map.copy()
                reinst_expand_map.pop("USE", None)
        if reinst_expand_map and \
         not set(reinst_expand_map).difference(
         self.use_expand_hidden):
            self.use_expand_hidden = \
             set(self.use_expand_hidden).difference(
             reinst_expand_map)

        cur_iuse_map, iuse_forced = \
         self.map_to_use_expand(cur_iuse, forced_flags=True)
        cur_use_map = self.map_to_use_expand(cur_use)
        old_iuse_map = self.map_to_use_expand(old_iuse)
        old_use_map = self.map_to_use_expand(old_use)

        use_expand = sorted(self.use_expand)
        use_expand.insert(0, "USE")
        feature_flags = _get_feature_flags(_get_eapi_attrs(pkg.eapi))

        for key in use_expand:
            if key in self.use_expand_hidden:
                continue
            self.verboseadd += _create_use_string(
                self.conf, key.upper(), cur_iuse_map[key], iuse_forced[key],
                cur_use_map[key], old_iuse_map[key], old_use_map[key], is_new,
                feature_flags, reinst_flags_map.get(key))
        return
Ejemplo n.º 31
0
def parse_updates(mycontent):
	"""Valid updates are returned as a list of split update commands."""
	eapi_attrs = _get_eapi_attrs(None)
	slot_re = _get_slot_re(eapi_attrs)
	myupd = []
	errors = []
	mylines = mycontent.splitlines()
	for myline in mylines:
		mysplit = myline.split()
		if len(mysplit) == 0:
			continue
		if mysplit[0] not in ("move", "slotmove"):
			errors.append(_("ERROR: Update type not recognized '%s'") % myline)
			continue
		if mysplit[0] == "move":
			if len(mysplit) != 3:
				errors.append(_("ERROR: Update command invalid '%s'") % myline)
				continue
			valid = True
			for i in (1, 2):
				try:
					atom = Atom(mysplit[i])
				except InvalidAtom:
					atom = None
				else:
					if atom.blocker or atom != atom.cp:
						atom = None
				if atom is not None:
					mysplit[i] = atom
				else:
					errors.append(
						_("ERROR: Malformed update entry '%s'") % myline)
					valid = False
					break
			if not valid:
				continue

		if mysplit[0] == "slotmove":
			if len(mysplit)!=4:
				errors.append(_("ERROR: Update command invalid '%s'") % myline)
				continue
			pkg, origslot, newslot = mysplit[1], mysplit[2], mysplit[3]
			try:
				atom = Atom(pkg)
			except InvalidAtom:
				atom = None
			else:
				if atom.blocker:
					atom = None
			if atom is not None:
				mysplit[1] = atom
			else:
				errors.append(_("ERROR: Malformed update entry '%s'") % myline)
				continue

			invalid_slot = False
			for slot in (origslot, newslot):
				m = slot_re.match(slot)
				if m is None:
					invalid_slot = True
					break
				if "/" in slot:
					# EAPI 4-slot-abi style SLOT is currently not supported.
					invalid_slot = True
					break

			if invalid_slot:
				errors.append(_("ERROR: Malformed update entry '%s'") % myline)
				continue

		# The list of valid updates is filtered by continue statements above.
		myupd.append(mysplit)
	return myupd, errors
Ejemplo n.º 32
0
	def __init__(self, **kwargs):
		metadata = _PackageMetadataWrapperBase(kwargs.pop('metadata'))
		Task.__init__(self, **kwargs)
		# the SlotObject constructor assigns self.root_config from keyword args
		# and is an instance of a '_emerge.RootConfig.RootConfig class
		self.root = self.root_config.root
		self._raw_metadata = metadata
		self._metadata = _PackageMetadataWrapper(self, metadata)
		if not self.built:
			self._metadata['CHOST'] = self.root_config.settings.get('CHOST', '')
		eapi_attrs = _get_eapi_attrs(self.eapi)

		try:
			db = self.cpv._db
		except AttributeError:
			if self.built:
				# For independence from the source ebuild repository and
				# profile implicit IUSE state, require the _db attribute
				# for built packages.
				raise
			db = self.root_config.trees['porttree'].dbapi

		self.cpv = _pkg_str(self.cpv, metadata=self._metadata,
			settings=self.root_config.settings, db=db)
		if hasattr(self.cpv, 'slot_invalid'):
			self._invalid_metadata('SLOT.invalid',
				"SLOT: invalid value: '%s'" % self._metadata["SLOT"])
		self.cpv_split = self.cpv.cpv_split
		self.category, self.pf = portage.catsplit(self.cpv)
		self.cp = self.cpv.cp
		self.version = self.cpv.version
		self.slot = self.cpv.slot
		self.sub_slot = self.cpv.sub_slot
		self.slot_atom = Atom("%s%s%s" % (self.cp, _slot_separator, self.slot))
		# sync metadata with validated repo (may be UNKNOWN_REPO)
		self._metadata['repository'] = self.cpv.repo

		if self.root_config.settings.local_config:
			implicit_match = db._iuse_implicit_cnstr(self.cpv, self._metadata)
		else:
			implicit_match = db._repoman_iuse_implicit_cnstr(self.cpv, self._metadata)
		usealiases = self.root_config.settings._use_manager.getUseAliases(self)
		self.iuse = self._iuse(self, self._metadata["IUSE"].split(),
			implicit_match, usealiases, self.eapi)

		if (self.iuse.enabled or self.iuse.disabled) and \
			not eapi_attrs.iuse_defaults:
			if not self.installed:
				self._invalid_metadata('EAPI.incompatible',
					"IUSE contains defaults, but EAPI doesn't allow them")
		if self.inherited is None:
			self.inherited = frozenset()

		if self.operation is None:
			if self.onlydeps or self.installed:
				self.operation = "nomerge"
			else:
				self.operation = "merge"

		self._hash_key = Package._gen_hash_key(cpv=self.cpv,
			installed=self.installed, onlydeps=self.onlydeps,
			operation=self.operation, repo_name=self.cpv.repo,
			root_config=self.root_config,
			type_name=self.type_name)
		self._hash_value = hash(self._hash_key)
Ejemplo n.º 33
0
def parse_updates(mycontent):
	"""Valid updates are returned as a list of split update commands."""
	eapi_attrs = _get_eapi_attrs(None)
	slot_re = _get_slot_re(eapi_attrs)
	myupd = []
	errors = []
	mylines = mycontent.splitlines()
	for myline in mylines:
		mysplit = myline.split()
		if len(mysplit) == 0:
			continue
		if mysplit[0] not in ("move", "slotmove"):
			errors.append(_("ERROR: Update type not recognized '%s'") % myline)
			continue
		if mysplit[0] == "move":
			if len(mysplit) != 3:
				errors.append(_("ERROR: Update command invalid '%s'") % myline)
				continue
			valid = True
			for i in (1, 2):
				try:
					atom = Atom(mysplit[i])
				except InvalidAtom:
					atom = None
				else:
					if atom.blocker or atom != atom.cp:
						atom = None
				if atom is not None:
					mysplit[i] = atom
				else:
					errors.append(
						_("ERROR: Malformed update entry '%s'") % myline)
					valid = False
					break
			if not valid:
				continue

		if mysplit[0] == "slotmove":
			if len(mysplit)!=4:
				errors.append(_("ERROR: Update command invalid '%s'") % myline)
				continue
			pkg, origslot, newslot = mysplit[1], mysplit[2], mysplit[3]
			try:
				atom = Atom(pkg)
			except InvalidAtom:
				atom = None
			else:
				if atom.blocker:
					atom = None
			if atom is not None:
				mysplit[1] = atom
			else:
				errors.append(_("ERROR: Malformed update entry '%s'") % myline)
				continue

			invalid_slot = False
			for slot in (origslot, newslot):
				m = slot_re.match(slot)
				if m is None:
					invalid_slot = True
					break
				if "/" in slot:
					# EAPI 4-slot-abi style SLOT is currently not supported.
					invalid_slot = True
					break

			if invalid_slot:
				errors.append(_("ERROR: Malformed update entry '%s'") % myline)
				continue

		# The list of valid updates is filtered by continue statements above.
		myupd.append(mysplit)
	return myupd, errors