Exemplo n.º 1
0
                    def highlight_violations(atom, version, use=[]):
                        """Colorize parts of an atom"""
                        atom_str = str(atom)
                        if version:
                            op = atom.operator
                            ver = cpv_getversion(atom.cpv)
                            slot = atom.slot
                            atom_str = atom_str.replace(
                                op, colorize("BAD", op), 1)

                            start = atom_str.rfind(ver)
                            end = start + len(ver)
                            atom_str = atom_str[:start] + \
                             colorize("BAD", ver) + \
                             atom_str[end+1:]
                            if slot:
                                atom_str = atom_str.replace(
                                    ":" + slot, colorize("BAD", ":" + slot))

                        if use and atom.use.tokens:
                            use_part_start = atom_str.find("[")
                            use_part_end = atom_str.find("]")

                            new_tokens = []
                            for token in atom.use.tokens:
                                if token.lstrip("-!").rstrip("=?") in use:
                                    new_tokens.append(colorize("BAD", token))
                                else:
                                    new_tokens.append(token)

                            atom_str = atom_str[:use_part_start] \
                             + "[%s]" % (",".join(new_tokens),) + \
                             atom_str[use_part_end+1:]

                        return atom_str
Exemplo n.º 2
0
					def highlight_violations(atom, version, use=[]):
						"""Colorize parts of an atom"""
						atom_str = str(atom)
						if version:
							op = atom.operator
							ver = cpv_getversion(atom.cpv)
							slot = atom.slot
							atom_str = atom_str.replace(op, colorize("BAD", op), 1)
							
							start = atom_str.rfind(ver)
							end = start + len(ver)
							atom_str = atom_str[:start] + \
								colorize("BAD", ver) + \
								atom_str[end+1:]
							if slot:
								atom_str = atom_str.replace(":" + slot, colorize("BAD", ":" + slot))
						
						if use and atom.use.tokens:
							use_part_start = atom_str.find("[")
							use_part_end = atom_str.find("]")
							
							new_tokens = []
							for token in atom.use.tokens:
								if token.lstrip("-!").rstrip("=?") in use:
									new_tokens.append(colorize("BAD", token))
								else:
									new_tokens.append(token)

							atom_str = atom_str[:use_part_start] \
								+ "[%s]" % (",".join(new_tokens),) + \
								atom_str[use_part_end+1:]
						
						return atom_str
Exemplo n.º 3
0
def gen_structure(dbapi, repo_name):
    trees = [getcwd()]
    ret = {}

    for cp in dbapi.cp_all(trees=trees):
        cpvlist = dbapi.cp_list(cp, mytree=trees)
        category, pkgname = catpkgsplit(cpvlist[0])[:2]

        cat = ret.setdefault(category, {})
        pn = cat.setdefault(pkgname, {})

        pn["data"] = dbapi.aux_get(cpvlist[-1], WANT_DATA)
        pn["versions"] = [cpv_getversion(cpv) for cpv in cpvlist]

    return ret
Exemplo n.º 4
0
    def atomVersion(self):
        """Returns the package version"""

        return cpv_getversion(self.atom)
Exemplo n.º 5
0
	def _prepare_conflict_msg_and_check_for_specificity(self):
		"""
		Print all slot conflicts in a human readable way.
		"""
		_pkg_use_enabled = self.depgraph._pkg_use_enabled
		verboseconflicts = "--verbose-conflicts" in self.myopts
		msg = self.conflict_msg
		indent = "  "
		msg.append("\n!!! Multiple package instances within a single " + \
			"package slot have been pulled\n")
		msg.append("!!! into the dependency graph, resulting" + \
			" in a slot conflict:\n\n")

		for (slot_atom, root), pkgs \
			in self.slot_collision_info.items():
			msg.append("%s" % (slot_atom,))
			if root != self.depgraph._frozen_config._running_root.root:
				msg.append(" for %s" % (root,))
			msg.append("\n\n")

			for pkg in pkgs:
				msg.append(indent)
				msg.append("%s" % (pkg,))
				parent_atoms = self.all_parents.get(pkg)
				if parent_atoms:
					#Create a list of collision reasons and map them to sets
					#of atoms.
					#Possible reasons:
					#	("version", "ge") for operator >=, >
					#	("version", "eq") for operator =, ~
					#	("version", "le") for operator <=, <
					#	("use", "<some use flag>") for unmet use conditionals
					collision_reasons = {}
					num_all_specific_atoms = 0

					for ppkg, atom in parent_atoms:
						atom_set = InternalPackageSet(initial_atoms=(atom,))
						atom_without_use_set = InternalPackageSet(initial_atoms=(atom.without_use,))

						for other_pkg in pkgs:
							if other_pkg == pkg:
								continue

							if not atom_without_use_set.findAtomForPackage(other_pkg, \
								modified_use=_pkg_use_enabled(other_pkg)):
								if atom.operator is not None:
									# The version range does not match.
									sub_type = None
									if atom.operator in (">=", ">"):
										sub_type = "ge"
									elif atom.operator in ("=", "~"):
										sub_type = "eq"
									elif atom.operator in ("<=", "<"):
										sub_type = "le"

									key = ("version", sub_type)
									atoms = collision_reasons.get(key, set())
									atoms.add((ppkg, atom, other_pkg))
									num_all_specific_atoms += 1
									collision_reasons[key] = atoms
								else:
									# The sub_slot does not match.
									key = ("sub-slot", atom.sub_slot)
									atoms = collision_reasons.get(key, set())
									atoms.add((ppkg, atom, other_pkg))
									num_all_specific_atoms += 1
									collision_reasons[key] = atoms

							elif not atom_set.findAtomForPackage(other_pkg, \
								modified_use=_pkg_use_enabled(other_pkg)):
								missing_iuse = other_pkg.iuse.get_missing_iuse(
									atom.unevaluated_atom.use.required)
								if missing_iuse:
									for flag in missing_iuse:
										atoms = collision_reasons.get(("use", flag), set())
										atoms.add((ppkg, atom, other_pkg))
										collision_reasons[("use", flag)] = atoms
									num_all_specific_atoms += 1
								else:
									#Use conditionals not met.
									violated_atom = atom.violated_conditionals(_pkg_use_enabled(other_pkg), \
										other_pkg.iuse.is_valid_flag)
									if violated_atom.use is None:
										# Something like bug #453400 caused the
										# above findAtomForPackage call to
										# return None unexpectedly.
										msg = ("\n\n!!! BUG: Detected "
											"USE dep match inconsistency:\n"
											"\tppkg: %s\n"
											"\tviolated_atom: %s\n"
											"\tatom: %s unevaluated: %s\n"
											"\tother_pkg: %s IUSE: %s USE: %s\n" %
											(ppkg,
											violated_atom,
											atom,
											atom.unevaluated_atom,
											other_pkg,
											sorted(other_pkg.iuse.all),
											sorted(_pkg_use_enabled(other_pkg))))
										writemsg(msg, noiselevel=-2)
										raise AssertionError(
											'BUG: USE dep match inconsistency')
									for flag in violated_atom.use.enabled.union(violated_atom.use.disabled):
										atoms = collision_reasons.get(("use", flag), set())
										atoms.add((ppkg, atom, other_pkg))
										collision_reasons[("use", flag)] = atoms
									num_all_specific_atoms += 1

					msg.append(" pulled in by\n")

					selected_for_display = set()
					unconditional_use_deps = set()

					for (type, sub_type), parents in collision_reasons.items():
						#From each (type, sub_type) pair select at least one atom.
						#Try to select as few atoms as possible

						if type == "version":
							#Find the atom with version that is as far away as possible.
							best_matches = {}
							for ppkg, atom, other_pkg in parents:
								if atom.cp in best_matches:
									cmp = vercmp( \
										cpv_getversion(atom.cpv), \
										cpv_getversion(best_matches[atom.cp][1].cpv))

									if (sub_type == "ge" and  cmp > 0) \
										or (sub_type == "le" and cmp < 0) \
										or (sub_type == "eq" and cmp > 0):
										best_matches[atom.cp] = (ppkg, atom)
								else:
									best_matches[atom.cp] = (ppkg, atom)
								if verboseconflicts:
									selected_for_display.add((ppkg, atom))
							if not verboseconflicts:
								selected_for_display.update(
										best_matches.values())
						elif type == "sub-slot":
							for ppkg, atom, other_pkg in parents:
								selected_for_display.add((ppkg, atom))
						elif type == "use":
							#Prefer atoms with unconditional use deps over, because it's
							#not possible to change them on the parent, which means there
							#are fewer possible solutions.
							use = sub_type
							for ppkg, atom, other_pkg in parents:
								missing_iuse = other_pkg.iuse.get_missing_iuse(
									atom.unevaluated_atom.use.required)
								if missing_iuse:
									unconditional_use_deps.add((ppkg, atom))
								else:
									parent_use = None
									if isinstance(ppkg, Package):
										parent_use = _pkg_use_enabled(ppkg)
									violated_atom = atom.unevaluated_atom.violated_conditionals(
										_pkg_use_enabled(other_pkg),
										other_pkg.iuse.is_valid_flag,
										parent_use=parent_use)
									# It's possible for autounmask to change
									# parent_use such that the unevaluated form
									# of the atom now matches, even though the
									# earlier evaluated form (from before
									# autounmask changed parent_use) does not.
									# In this case (see bug #374423), it's
									# expected that violated_atom.use is None.
									# Since the atom now matches, we don't want
									# to display it in the slot conflict
									# message, so we simply ignore it and rely
									# on the autounmask display to communicate
									# the necessary USE change to the user.
									if violated_atom.use is None:
										continue
									if use in violated_atom.use.enabled or \
										use in violated_atom.use.disabled:
										unconditional_use_deps.add((ppkg, atom))
								# When USE flags are removed, it can be
								# essential to see all broken reverse
								# dependencies here, so don't omit any.
								# If the list is long, people can simply
								# use a pager.
								selected_for_display.add((ppkg, atom))

					def highlight_violations(atom, version, use=[]):
						"""Colorize parts of an atom"""
						atom_str = "%s" % (atom,)
						if version:
							op = atom.operator
							ver = None
							if atom.cp != atom.cpv:
								ver = cpv_getversion(atom.cpv)
							slot = atom.slot

							if op == "=*":
								op = "="
								ver += "*"

							if op is not None:
								atom_str = atom_str.replace(op, colorize("BAD", op), 1)

							if ver is not None:
								start = atom_str.rfind(ver)
								end = start + len(ver)
								atom_str = atom_str[:start] + \
									colorize("BAD", ver) + \
									atom_str[end:]
							if slot:
								atom_str = atom_str.replace(":" + slot, colorize("BAD", ":" + slot))
						
						if use and atom.use.tokens:
							use_part_start = atom_str.find("[")
							use_part_end = atom_str.find("]")
							
							new_tokens = []
							for token in atom.use.tokens:
								if token.lstrip("-!").rstrip("=?") in use:
									new_tokens.append(colorize("BAD", token))
								else:
									new_tokens.append(token)

							atom_str = atom_str[:use_part_start] \
								+ "[%s]" % (",".join(new_tokens),) + \
								atom_str[use_part_end+1:]
						
						return atom_str

					# Show unconditional use deps first, since those
					# are more problematic than the conditional kind.
					ordered_list = list(unconditional_use_deps)
					if len(selected_for_display) > len(unconditional_use_deps):
						for parent_atom in selected_for_display:
							if parent_atom not in unconditional_use_deps:
								ordered_list.append(parent_atom)
					for parent_atom in ordered_list:
						parent, atom = parent_atom
						msg.append(2*indent)
						if isinstance(parent,
							(PackageArg, AtomArg)):
							# For PackageArg and AtomArg types, it's
							# redundant to display the atom attribute.
							msg.append("%s" % (parent,))
						else:
							# Display the specific atom from SetArg or
							# Package types.
							version_violated = False
							sub_slot_violated = False
							use = []
							for (type, sub_type), parents in collision_reasons.items():
								for x in parents:
									if parent == x[0] and atom == x[1]:
										if type == "version":
											version_violated = True
										elif type == "sub-slot":
											sub_slot_violated = True
										elif type == "use":
											use.append(sub_type)
										break

							atom_str = highlight_violations(atom.unevaluated_atom, version_violated, use)

							if version_violated or sub_slot_violated:
								self.is_a_version_conflict = True

							msg.append("%s required by %s" % (atom_str, parent))
						msg.append("\n")
					
					if not selected_for_display:
						msg.append(2*indent)
						msg.append("(no parents that aren't satisfied by other packages in this slot)\n")
						self.conflict_is_unspecific = True
					
					omitted_parents = num_all_specific_atoms - len(selected_for_display)
					if omitted_parents:
						msg.append(2*indent)
						if len(selected_for_display) > 1:
							msg.append("(and %d more with the same problems)\n" % omitted_parents)
						else:
							msg.append("(and %d more with the same problem)\n" % omitted_parents)
				else:
					msg.append(" (no parents)\n")
				msg.append("\n")
		msg.append("\n")
Exemplo n.º 6
0
def format_unmatched_atom(pkg, atom, pkg_use_enabled):
	"""
	Returns two strings. The first string contains the
	'atom' with parts of the atom colored, which 'pkg'
	doesn't match. The second string has the same number
	of characters as the first one, but consists of only
	white space or ^. The ^ characters have the same position
	as the colored parts of the first string.
	"""
	# Things to check:
	#	1. Version
	#	2. cp
	#   3. slot/sub_slot
	#	4. repository
	#	5. USE

	highlight = set()

	def perform_coloring():
		atom_str = ""
		marker_str = ""
		for ii, x in enumerate(atom):
			if ii in highlight:
				atom_str += colorize("BAD", x)
				marker_str += "^"
			else:
				atom_str += x
				marker_str += " "
		return atom_str, marker_str

	if atom.cp != pkg.cp:
		# Highlight the cp part only.
		ii = atom.find(atom.cp)
		highlight.update(range(ii, ii + len(atom.cp)))
		return perform_coloring()

	version_atom = atom.without_repo.without_slot.without_use
	version_atom_set = InternalPackageSet(initial_atoms=(version_atom,))
	highlight_version = not bool(version_atom_set.findAtomForPackage(pkg,
		modified_use=pkg_use_enabled(pkg)))

	highlight_slot = False
	if (atom.slot and atom.slot != pkg.slot) or \
		(atom.sub_slot and atom.sub_slot != pkg.sub_slot):
		highlight_slot = True

	if highlight_version:
		op = atom.operator
		ver = None
		if atom.cp != atom.cpv:
			ver = cpv_getversion(atom.cpv)

		if op == "=*":
			op = "="
			ver += "*"

		if op is not None:
			highlight.update(range(len(op)))

		if ver is not None:
			start = atom.rfind(ver)
			end = start + len(ver)
			highlight.update(range(start, end))

	if highlight_slot:
		slot_str = ":" + atom.slot
		if atom.sub_slot:
			slot_str += "/" + atom.sub_slot
		if atom.slot_operator:
			slot_str += atom.slot_operator
		start = atom.find(slot_str)
		end = start + len(slot_str)
		highlight.update(range(start, end))

	highlight_use = set()
	if atom.use:
		use_atom = "%s[%s]" % (atom.cp, str(atom.use))
		use_atom_set = InternalPackageSet(initial_atoms=(use_atom,))
		if not use_atom_set.findAtomForPackage(pkg, \
			modified_use=pkg_use_enabled(pkg)):
			missing_iuse = pkg.iuse.get_missing_iuse(
				atom.unevaluated_atom.use.required)
			if missing_iuse:
				highlight_use = set(missing_iuse)
			else:
				#Use conditionals not met.
				violated_atom = atom.violated_conditionals(
					pkg_use_enabled(pkg), pkg.iuse.is_valid_flag)
				if violated_atom.use is not None:
					highlight_use = set(violated_atom.use.enabled.union(
						violated_atom.use.disabled))

	if highlight_use:
		ii = atom.find("[") + 1
		for token in atom.use.tokens:
			if token.lstrip("-!").rstrip("=?") in highlight_use:
				highlight.update(range(ii, ii + len(token)))
			ii += len(token) + 1

	return perform_coloring()
Exemplo n.º 7
0
    def _prepare_conflict_msg_and_check_for_specificity(self):
        """
		Print all slot conflicts in a human readable way.
		"""
        _pkg_use_enabled = self.depgraph._pkg_use_enabled
        msg = self.conflict_msg
        indent = "  "
        msg.append("\n!!! Multiple package instances within a single " + \
         "package slot have been pulled\n")
        msg.append("!!! into the dependency graph, resulting" + \
         " in a slot conflict:\n\n")

        for (slot_atom, root), pkgs \
         in self.slot_collision_info.items():
            msg.append(str(slot_atom))
            if root != '/':
                msg.append(" for %s" % (root, ))
            msg.append("\n\n")

            for pkg in pkgs:
                msg.append(indent)
                msg.append(str(pkg))
                parent_atoms = self.all_parents.get(pkg)
                if parent_atoms:
                    #Create a list of collision reasons and map them to sets
                    #of atoms.
                    #Possible reasons:
                    #	("version", "ge") for operator >=, >
                    #	("version", "eq") for operator =, ~
                    #	("version", "le") for operator <=, <
                    #	("use", "<some use flag>") for unmet use conditionals
                    collision_reasons = {}
                    num_all_specific_atoms = 0

                    for ppkg, atom in parent_atoms:
                        atom_set = InternalPackageSet(initial_atoms=(atom, ))
                        atom_without_use_set = InternalPackageSet(
                            initial_atoms=(atom.without_use, ))

                        for other_pkg in pkgs:
                            if other_pkg == pkg:
                                continue

                            if not atom_without_use_set.findAtomForPackage(other_pkg, \
                             modified_use=_pkg_use_enabled(other_pkg)):
                                #The version range does not match.
                                sub_type = None
                                if atom.operator in (">=", ">"):
                                    sub_type = "ge"
                                elif atom.operator in ("=", "~"):
                                    sub_type = "eq"
                                elif atom.operator in ("<=", "<"):
                                    sub_type = "le"

                                atoms = collision_reasons.get(
                                    ("version", sub_type), set())
                                atoms.add((ppkg, atom, other_pkg))
                                num_all_specific_atoms += 1
                                collision_reasons[("version",
                                                   sub_type)] = atoms
                            elif not atom_set.findAtomForPackage(other_pkg, \
                             modified_use=_pkg_use_enabled(other_pkg)):
                                #Use conditionals not met.
                                violated_atom = atom.violated_conditionals(_pkg_use_enabled(other_pkg), \
                                 other_pkg.iuse.is_valid_flag)
                                for flag in violated_atom.use.enabled.union(
                                        violated_atom.use.disabled):
                                    atoms = collision_reasons.get(
                                        ("use", flag), set())
                                    atoms.add((ppkg, atom, other_pkg))
                                    collision_reasons[("use", flag)] = atoms
                                num_all_specific_atoms += 1

                    msg.append(" pulled in by\n")

                    selected_for_display = set()

                    for (type, sub_type), parents in collision_reasons.items():
                        #From each (type, sub_type) pair select at least one atom.
                        #Try to select as few atoms as possible

                        if type == "version":
                            #Find the atom with version that is as far away as possible.
                            best_matches = {}
                            for ppkg, atom, other_pkg in parents:
                                if atom.cp in best_matches:
                                    cmp = vercmp( \
                                     cpv_getversion(atom.cpv), \
                                     cpv_getversion(best_matches[atom.cp][1].cpv))

                                    if (sub_type == "ge" and  cmp > 0) \
                                     or (sub_type == "le" and cmp < 0) \
                                     or (sub_type == "eq" and cmp > 0):
                                        best_matches[atom.cp] = (ppkg, atom)
                                else:
                                    best_matches[atom.cp] = (ppkg, atom)
                            selected_for_display.update(best_matches.values())
                        elif type == "use":
                            #Prefer atoms with unconditional use deps over, because it's
                            #not possible to change them on the parent, which means there
                            #are fewer possible solutions.
                            use = sub_type
                            hard_matches = set()
                            conditional_matches = set()
                            for ppkg, atom, other_pkg in parents:
                                parent_use = None
                                if isinstance(ppkg, Package):
                                    parent_use = _pkg_use_enabled(ppkg)
                                violated_atom = atom.unevaluated_atom.violated_conditionals( \
                                 _pkg_use_enabled(other_pkg), other_pkg.iuse.is_valid_flag,
                                 parent_use=parent_use)
                                if use in violated_atom.use.enabled.union(
                                        violated_atom.use.disabled):
                                    hard_matches.add((ppkg, atom))
                                else:
                                    conditional_matches.add((ppkg, atom))

                            if hard_matches:
                                matches = hard_matches
                            else:
                                matches = conditional_matches

                            if not selected_for_display.intersection(matches):
                                selected_for_display.add(matches.pop())

                    def highlight_violations(atom, version, use=[]):
                        """Colorize parts of an atom"""
                        atom_str = str(atom)
                        if version:
                            op = atom.operator
                            ver = cpv_getversion(atom.cpv)
                            slot = atom.slot
                            atom_str = atom_str.replace(
                                op, colorize("BAD", op), 1)

                            start = atom_str.rfind(ver)
                            end = start + len(ver)
                            atom_str = atom_str[:start] + \
                             colorize("BAD", ver) + \
                             atom_str[end+1:]
                            if slot:
                                atom_str = atom_str.replace(
                                    ":" + slot, colorize("BAD", ":" + slot))

                        if use and atom.use.tokens:
                            use_part_start = atom_str.find("[")
                            use_part_end = atom_str.find("]")

                            new_tokens = []
                            for token in atom.use.tokens:
                                if token.lstrip("-!").rstrip("=?") in use:
                                    new_tokens.append(colorize("BAD", token))
                                else:
                                    new_tokens.append(token)

                            atom_str = atom_str[:use_part_start] \
                             + "[%s]" % (",".join(new_tokens),) + \
                             atom_str[use_part_end+1:]

                        return atom_str

                    for parent_atom in selected_for_display:
                        parent, atom = parent_atom
                        msg.append(2 * indent)
                        if isinstance(parent, (PackageArg, AtomArg)):
                            # For PackageArg and AtomArg types, it's
                            # redundant to display the atom attribute.
                            msg.append(str(parent))
                        else:
                            # Display the specific atom from SetArg or
                            # Package types.
                            version_violated = False
                            use = []
                            for type, sub_type in collision_reasons:
                                if type == "version":
                                    for x in collision_reasons[(type,
                                                                sub_type)]:
                                        if ppkg == x[0] and atom == x[1]:
                                            version_violated = True
                                elif type == "use":
                                    use.append(sub_type)

                            atom_str = highlight_violations(
                                atom.unevaluated_atom, version_violated, use)

                            if version_violated:
                                self.is_a_version_conflict = True

                            msg.append("%s required by %s" %
                                       (atom_str, parent))
                        msg.append("\n")

                    if not selected_for_display:
                        msg.append(2 * indent)
                        msg.append(
                            "(no parents that aren't satisfied by other packages in this slot)\n"
                        )
                        self.conflict_is_unspecific = True

                    omitted_parents = num_all_specific_atoms - len(
                        selected_for_display)
                    if omitted_parents:
                        msg.append(2 * indent)
                        if len(selected_for_display) > 1:
                            msg.append(
                                "(and %d more with the same problems)\n" %
                                omitted_parents)
                        else:
                            msg.append(
                                "(and %d more with the same problem)\n" %
                                omitted_parents)
                else:
                    msg.append(" (no parents)\n")
                msg.append("\n")
        msg.append("\n")
Exemplo n.º 8
0
def format_unmatched_atom(pkg, atom, pkg_use_enabled):
    """
	Returns two strings. The first string contains the
	'atom' with parts of the atom colored, which 'pkg'
	doesn't match. The second string has the same number
	of characters as the first one, but consists of only
	white space or ^. The ^ characters have the same position
	as the colored parts of the first string.
	"""
    # Things to check:
    #	1. Version
    #	2. cp
    #   3. slot/sub_slot
    #	4. repository
    #	5. USE

    if atom.soname:
        return "%s" % (atom, ), ""

    highlight = set()

    def perform_coloring():
        atom_str = ""
        marker_str = ""
        for ii, x in enumerate(atom):
            if ii in highlight:
                atom_str += colorize("BAD", x)
                marker_str += "^"
            else:
                atom_str += x
                marker_str += " "
        return atom_str, marker_str

    if atom.cp != pkg.cp:
        # Highlight the cp part only.
        ii = atom.find(atom.cp)
        highlight.update(range(ii, ii + len(atom.cp)))
        return perform_coloring()

    version_atom = atom.without_repo.without_slot.without_use
    version_atom_set = InternalPackageSet(initial_atoms=(version_atom, ))
    highlight_version = not bool(
        version_atom_set.findAtomForPackage(pkg,
                                            modified_use=pkg_use_enabled(pkg)))

    highlight_slot = False
    if (atom.slot and atom.slot != pkg.slot) or \
     (atom.sub_slot and atom.sub_slot != pkg.sub_slot):
        highlight_slot = True

    if highlight_version:
        op = atom.operator
        ver = None
        if atom.cp != atom.cpv:
            ver = cpv_getversion(atom.cpv)

        if op == "=*":
            op = "="
            ver += "*"

        if op is not None:
            highlight.update(range(len(op)))

        if ver is not None:
            start = atom.rfind(ver)
            end = start + len(ver)
            highlight.update(range(start, end))

    if highlight_slot:
        slot_str = ":" + atom.slot
        if atom.sub_slot:
            slot_str += "/" + atom.sub_slot
        if atom.slot_operator:
            slot_str += atom.slot_operator
        start = atom.find(slot_str)
        end = start + len(slot_str)
        highlight.update(range(start, end))

    highlight_use = set()
    if atom.use:
        use_atom = "%s[%s]" % (atom.cp, str(atom.use))
        use_atom_set = InternalPackageSet(initial_atoms=(use_atom, ))
        if not use_atom_set.findAtomForPackage(pkg, \
         modified_use=pkg_use_enabled(pkg)):
            missing_iuse = pkg.iuse.get_missing_iuse(
                atom.unevaluated_atom.use.required)
            if missing_iuse:
                highlight_use = set(missing_iuse)
            else:
                #Use conditionals not met.
                violated_atom = atom.violated_conditionals(
                    pkg_use_enabled(pkg), pkg.iuse.is_valid_flag)
                if violated_atom.use is not None:
                    highlight_use = set(
                        violated_atom.use.enabled.union(
                            violated_atom.use.disabled))

    if highlight_use:
        ii = atom.find("[") + 1
        for token in atom.use.tokens:
            if token.lstrip("-!").rstrip("=?") in highlight_use:
                highlight.update(range(ii, ii + len(token)))
            ii += len(token) + 1

    return perform_coloring()
Exemplo n.º 9
0
					def highlight_violations(atom, version, use, slot_violated):
						"""Colorize parts of an atom"""
						atom_str = "%s" % (atom,)
						colored_idx = set()
						if version:
							op = atom.operator
							ver = None
							if atom.cp != atom.cpv:
								ver = cpv_getversion(atom.cpv)
							slot = atom.slot
							sub_slot = atom.sub_slot
							slot_operator = atom.slot_operator

							if op == "=*":
								op = "="
								ver += "*"

							slot_str = ""
							if slot:
								slot_str = ":" + slot
							if sub_slot:
								slot_str += "/" + sub_slot
							if slot_operator:
								slot_str += slot_operator

							# Compute color_idx before adding the color codes
							# as these change the indices of the letters.
							if op is not None:
								colored_idx.update(range(len(op)))

							if ver is not None:
								start = atom_str.rfind(ver)
								end = start + len(ver)
								colored_idx.update(range(start, end))

							if slot_str:
								ii = atom_str.find(slot_str)
								colored_idx.update(range(ii, ii + len(slot_str)))


							if op is not None:
								atom_str = atom_str.replace(op, colorize("BAD", op), 1)

							if ver is not None:
								start = atom_str.rfind(ver)
								end = start + len(ver)
								atom_str = atom_str[:start] + \
									colorize("BAD", ver) + \
									atom_str[end:]

							if slot_str:
								atom_str = atom_str.replace(slot_str, colorize("BAD", slot_str), 1)

						elif slot_violated:
							slot = atom.slot
							sub_slot = atom.sub_slot
							slot_operator = atom.slot_operator

							slot_str = ""
							if slot:
								slot_str = ":" + slot
							if sub_slot:
								slot_str += "/" + sub_slot
							if slot_operator:
								slot_str += slot_operator

							if slot_str:
								ii = atom_str.find(slot_str)
								colored_idx.update(range(ii, ii + len(slot_str)))
								atom_str = atom_str.replace(slot_str, colorize("BAD", slot_str), 1)
						
						if use and atom.use.tokens:
							use_part_start = atom_str.find("[")
							use_part_end = atom_str.find("]")
							
							new_tokens = []
							# Compute start index in non-colored atom.
							ii = str(atom).find("[") +  1
							for token in atom.use.tokens:
								if token.lstrip("-!").rstrip("=?") in use:
									new_tokens.append(colorize("BAD", token))
									colored_idx.update(range(ii, ii + len(token)))
								else:
									new_tokens.append(token)
								ii += 1 + len(token)

							atom_str = atom_str[:use_part_start] \
								+ "[%s]" % (",".join(new_tokens),) + \
								atom_str[use_part_end+1:]
						
						return atom_str, colored_idx
Exemplo n.º 10
0
	def _prepare_conflict_msg_and_check_for_specificity(self):
		"""
		Print all slot conflicts in a human readable way.
		"""
		_pkg_use_enabled = self.depgraph._pkg_use_enabled
		usepkgonly = "--usepkgonly" in self.myopts
		need_rebuild = {}
		verboseconflicts = "--verbose-conflicts" in self.myopts
		any_omitted_parents = False
		msg = self.conflict_msg
		indent = "  "
		msg.append("\n!!! Multiple package instances within a single " + \
			"package slot have been pulled\n")
		msg.append("!!! into the dependency graph, resulting" + \
			" in a slot conflict:\n\n")

		for root, slot_atom, pkgs in self.all_conflicts:
			msg.append("%s" % (slot_atom,))
			if root != self.depgraph._frozen_config._running_root.root:
				msg.append(" for %s" % (root,))
			msg.append("\n\n")

			for pkg in pkgs:
				msg.append(indent)
				msg.append("%s" % (pkg,))
				parent_atoms = self.all_parents.get(pkg)
				if parent_atoms:
					#Create a list of collision reasons and map them to sets
					#of atoms.
					#Possible reasons:
					#	("version", "ge") for operator >=, >
					#	("version", "eq") for operator =, ~
					#	("version", "le") for operator <=, <
					#	("use", "<some use flag>") for unmet use conditionals
					collision_reasons = {}
					num_all_specific_atoms = 0

					for ppkg, atom in parent_atoms:
						if not atom.soname:
							atom_set = InternalPackageSet(
								initial_atoms=(atom,))
							atom_without_use_set = InternalPackageSet(
								initial_atoms=(atom.without_use,))
							atom_without_use_and_slot_set = \
								InternalPackageSet(initial_atoms=(
								atom.without_use.without_slot,))

						for other_pkg in pkgs:
							if other_pkg == pkg:
								continue

							if atom.soname:
								# The soname does not match.
								key = ("soname", atom)
								atoms = collision_reasons.get(key, set())
								atoms.add((ppkg, atom, other_pkg))
								num_all_specific_atoms += 1
								collision_reasons[key] = atoms
							elif not atom_without_use_and_slot_set.findAtomForPackage(other_pkg,
								modified_use=_pkg_use_enabled(other_pkg)):
								if atom.operator is not None:
									# The version range does not match.
									sub_type = None
									if atom.operator in (">=", ">"):
										sub_type = "ge"
									elif atom.operator in ("=", "~"):
										sub_type = "eq"
									elif atom.operator in ("<=", "<"):
										sub_type = "le"

									key = ("version", sub_type)
									atoms = collision_reasons.get(key, set())
									atoms.add((ppkg, atom, other_pkg))
									num_all_specific_atoms += 1
									collision_reasons[key] = atoms

							elif not atom_without_use_set.findAtomForPackage(other_pkg, \
								modified_use=_pkg_use_enabled(other_pkg)):
									# The slot and/or sub_slot does not match.
									key = ("slot", (atom.slot, atom.sub_slot, atom.slot_operator))
									atoms = collision_reasons.get(key, set())
									atoms.add((ppkg, atom, other_pkg))
									num_all_specific_atoms += 1
									collision_reasons[key] = atoms

							elif not atom_set.findAtomForPackage(other_pkg, \
								modified_use=_pkg_use_enabled(other_pkg)):
								missing_iuse = other_pkg.iuse.get_missing_iuse(
									atom.unevaluated_atom.use.required)
								if missing_iuse:
									for flag in missing_iuse:
										atoms = collision_reasons.get(("use", flag), set())
										atoms.add((ppkg, atom, other_pkg))
										collision_reasons[("use", flag)] = atoms
									num_all_specific_atoms += 1
								else:
									#Use conditionals not met.
									violated_atom = atom.violated_conditionals(_pkg_use_enabled(other_pkg), \
										other_pkg.iuse.is_valid_flag)
									if violated_atom.use is None:
										# Something like bug #453400 caused the
										# above findAtomForPackage call to
										# return None unexpectedly.
										msg = ("\n\n!!! BUG: Detected "
											"USE dep match inconsistency:\n"
											"\tppkg: %s\n"
											"\tviolated_atom: %s\n"
											"\tatom: %s unevaluated: %s\n"
											"\tother_pkg: %s IUSE: %s USE: %s\n" %
											(ppkg,
											violated_atom,
											atom,
											atom.unevaluated_atom,
											other_pkg,
											sorted(other_pkg.iuse.all),
											sorted(_pkg_use_enabled(other_pkg))))
										writemsg(msg, noiselevel=-2)
										raise AssertionError(
											'BUG: USE dep match inconsistency')
									for flag in violated_atom.use.enabled.union(violated_atom.use.disabled):
										atoms = collision_reasons.get(("use", flag), set())
										atoms.add((ppkg, atom, other_pkg))
										collision_reasons[("use", flag)] = atoms
									num_all_specific_atoms += 1
							elif isinstance(ppkg, AtomArg) and other_pkg.installed:
								parent_atoms = collision_reasons.get(("AtomArg", None), set())
								parent_atoms.add((ppkg, atom))
								collision_reasons[("AtomArg", None)] = parent_atoms
								num_all_specific_atoms += 1

					msg.append(" pulled in by\n")

					selected_for_display = set()
					unconditional_use_deps = set()

					for (type, sub_type), parents in collision_reasons.items():
						#From each (type, sub_type) pair select at least one atom.
						#Try to select as few atoms as possible

						if type == "version":
							#Find the atom with version that is as far away as possible.
							best_matches = {}
							for ppkg, atom, other_pkg in parents:
								if atom.cp in best_matches:
									cmp = vercmp( \
										cpv_getversion(atom.cpv), \
										cpv_getversion(best_matches[atom.cp][1].cpv))

									if (sub_type == "ge" and  cmp > 0) \
										or (sub_type == "le" and cmp < 0) \
										or (sub_type == "eq" and cmp > 0):
										best_matches[atom.cp] = (ppkg, atom)
								else:
									best_matches[atom.cp] = (ppkg, atom)
								if verboseconflicts:
									selected_for_display.add((ppkg, atom))
							if not verboseconflicts:
								selected_for_display.update(
										best_matches.values())
						elif type in ("soname", "slot"):
							# Check for packages that might need to
							# be rebuilt, but cannot be rebuilt for
							# some reason.
							for ppkg, atom, other_pkg in parents:
								if not (isinstance(ppkg, Package) and ppkg.installed):
									continue
								if not (atom.soname or atom.slot_operator_built):
									continue
								if self.depgraph._frozen_config.excluded_pkgs.findAtomForPackage(ppkg,
									modified_use=self.depgraph._pkg_use_enabled(ppkg)):
									selected_for_display.add((ppkg, atom))
									need_rebuild[ppkg] = 'matched by --exclude argument'
								elif self.depgraph._frozen_config.useoldpkg_atoms.findAtomForPackage(ppkg,
									modified_use=self.depgraph._pkg_use_enabled(ppkg)):
									selected_for_display.add((ppkg, atom))
									need_rebuild[ppkg] = 'matched by --useoldpkg-atoms argument'
								elif usepkgonly:
									# This case is tricky, so keep quiet in order to avoid false-positives.
									pass
								elif not self.depgraph._equiv_ebuild_visible(ppkg):
									selected_for_display.add((ppkg, atom))
									need_rebuild[ppkg] = 'ebuild is masked or unavailable'

							for ppkg, atom, other_pkg in parents:
								selected_for_display.add((ppkg, atom))
								if not verboseconflicts:
									break
						elif type == "use":
							#Prefer atoms with unconditional use deps over, because it's
							#not possible to change them on the parent, which means there
							#are fewer possible solutions.
							use = sub_type
							for ppkg, atom, other_pkg in parents:
								missing_iuse = other_pkg.iuse.get_missing_iuse(
									atom.unevaluated_atom.use.required)
								if missing_iuse:
									unconditional_use_deps.add((ppkg, atom))
								else:
									parent_use = None
									if isinstance(ppkg, Package):
										parent_use = _pkg_use_enabled(ppkg)
									violated_atom = atom.unevaluated_atom.violated_conditionals(
										_pkg_use_enabled(other_pkg),
										other_pkg.iuse.is_valid_flag,
										parent_use=parent_use)
									# It's possible for autounmask to change
									# parent_use such that the unevaluated form
									# of the atom now matches, even though the
									# earlier evaluated form (from before
									# autounmask changed parent_use) does not.
									# In this case (see bug #374423), it's
									# expected that violated_atom.use is None.
									# Since the atom now matches, we don't want
									# to display it in the slot conflict
									# message, so we simply ignore it and rely
									# on the autounmask display to communicate
									# the necessary USE change to the user.
									if violated_atom.use is None:
										continue
									if use in violated_atom.use.enabled or \
										use in violated_atom.use.disabled:
										unconditional_use_deps.add((ppkg, atom))
								# When USE flags are removed, it can be
								# essential to see all broken reverse
								# dependencies here, so don't omit any.
								# If the list is long, people can simply
								# use a pager.
								selected_for_display.add((ppkg, atom))
						elif type == "AtomArg":
							for ppkg, atom in parents:
								selected_for_display.add((ppkg, atom))

					def highlight_violations(atom, version, use, slot_violated):
						"""Colorize parts of an atom"""
						atom_str = "%s" % (atom,)
						colored_idx = set()
						if version:
							op = atom.operator
							ver = None
							if atom.cp != atom.cpv:
								ver = cpv_getversion(atom.cpv)
							slot = atom.slot
							sub_slot = atom.sub_slot
							slot_operator = atom.slot_operator

							if op == "=*":
								op = "="
								ver += "*"

							slot_str = ""
							if slot:
								slot_str = ":" + slot
							if sub_slot:
								slot_str += "/" + sub_slot
							if slot_operator:
								slot_str += slot_operator

							# Compute color_idx before adding the color codes
							# as these change the indices of the letters.
							if op is not None:
								colored_idx.update(range(len(op)))

							if ver is not None:
								start = atom_str.rfind(ver)
								end = start + len(ver)
								colored_idx.update(range(start, end))

							if slot_str:
								ii = atom_str.find(slot_str)
								colored_idx.update(range(ii, ii + len(slot_str)))


							if op is not None:
								atom_str = atom_str.replace(op, colorize("BAD", op), 1)

							if ver is not None:
								start = atom_str.rfind(ver)
								end = start + len(ver)
								atom_str = atom_str[:start] + \
									colorize("BAD", ver) + \
									atom_str[end:]

							if slot_str:
								atom_str = atom_str.replace(slot_str, colorize("BAD", slot_str), 1)

						elif slot_violated:
							slot = atom.slot
							sub_slot = atom.sub_slot
							slot_operator = atom.slot_operator

							slot_str = ""
							if slot:
								slot_str = ":" + slot
							if sub_slot:
								slot_str += "/" + sub_slot
							if slot_operator:
								slot_str += slot_operator

							if slot_str:
								ii = atom_str.find(slot_str)
								colored_idx.update(range(ii, ii + len(slot_str)))
								atom_str = atom_str.replace(slot_str, colorize("BAD", slot_str), 1)
						
						if use and atom.use.tokens:
							use_part_start = atom_str.find("[")
							use_part_end = atom_str.find("]")
							
							new_tokens = []
							# Compute start index in non-colored atom.
							ii = str(atom).find("[") +  1
							for token in atom.use.tokens:
								if token.lstrip("-!").rstrip("=?") in use:
									new_tokens.append(colorize("BAD", token))
									colored_idx.update(range(ii, ii + len(token)))
								else:
									new_tokens.append(token)
								ii += 1 + len(token)

							atom_str = atom_str[:use_part_start] \
								+ "[%s]" % (",".join(new_tokens),) + \
								atom_str[use_part_end+1:]
						
						return atom_str, colored_idx

					# Show unconditional use deps first, since those
					# are more problematic than the conditional kind.
					ordered_list = list(unconditional_use_deps)
					if len(selected_for_display) > len(unconditional_use_deps):
						for parent_atom in selected_for_display:
							if parent_atom not in unconditional_use_deps:
								ordered_list.append(parent_atom)
					for parent_atom in ordered_list:
						parent, atom = parent_atom
						if atom.soname:
							msg.append("%s required by %s\n" %
								(atom, parent))
						elif isinstance(parent, PackageArg):
							# For PackageArg it's
							# redundant to display the atom attribute.
							msg.append("%s\n" % (parent,))
						elif isinstance(parent, AtomArg):
							msg.append(2*indent)
							msg.append("%s (Argument)\n" % (atom,))
						else:
							# Display the specific atom from SetArg or
							# Package types.
							version_violated = False
							slot_violated = False
							use = []
							for (type, sub_type), parents in collision_reasons.items():
								for x in parents:
									if parent == x[0] and atom == x[1]:
										if type == "version":
											version_violated = True
										elif type == "slot":
											slot_violated = True
										elif type == "use":
											use.append(sub_type)
										break

							atom_str, colored_idx = highlight_violations(atom.unevaluated_atom,
								version_violated, use, slot_violated)

							if version_violated or slot_violated:
								self.is_a_version_conflict = True

							cur_line = "%s required by %s\n" % (atom_str, parent)
							marker_line = ""
							for ii in range(len(cur_line)):
								if ii in colored_idx:
									marker_line += "^"
								else:
									marker_line += " "
							marker_line += "\n"
							msg.append(2*indent)
							msg.append(cur_line)
							msg.append(2*indent)
							msg.append(marker_line)

					if not selected_for_display:
						msg.append(2*indent)
						msg.append("(no parents that aren't satisfied by other packages in this slot)\n")
						self.conflict_is_unspecific = True
					
					omitted_parents = num_all_specific_atoms - len(selected_for_display)
					if omitted_parents:
						any_omitted_parents = True
						msg.append(2*indent)
						if len(selected_for_display) > 1:
							msg.append("(and %d more with the same problems)\n" % omitted_parents)
						else:
							msg.append("(and %d more with the same problem)\n" % omitted_parents)
				else:
					msg.append(" (no parents)\n")
				msg.append("\n")

		if any_omitted_parents:
			msg.append(colorize("INFORM",
				"NOTE: Use the '--verbose-conflicts'"
				" option to display parents omitted above"))
			msg.append("\n")

		if need_rebuild:
			msg.append("\n!!! The slot conflict(s) shown above involve package(s) which may need to\n")
			msg.append("!!! be rebuilt in order to solve the conflict(s). However, the following\n")
			msg.append("!!! package(s) cannot be rebuilt for the reason(s) shown:\n\n")
			for ppkg, reason in need_rebuild.items():
				msg.append("%s%s: %s\n" % (indent, ppkg, reason))
			msg.append("\n")

		msg.append("\n")
Exemplo n.º 11
0
					def highlight_violations(atom, version, use, slot_violated):
						"""Colorize parts of an atom"""
						atom_str = "%s" % (atom,)
						colored_idx = set()
						if version:
							op = atom.operator
							ver = None
							if atom.cp != atom.cpv:
								ver = cpv_getversion(atom.cpv)
							slot = atom.slot
							sub_slot = atom.sub_slot
							slot_operator = atom.slot_operator

							if op == "=*":
								op = "="
								ver += "*"

							slot_str = ""
							if slot:
								slot_str = ":" + slot
							if sub_slot:
								slot_str += "/" + sub_slot
							if slot_operator:
								slot_str += slot_operator

							# Compute color_idx before adding the color codes
							# as these change the indices of the letters.
							if op is not None:
								colored_idx.update(range(len(op)))

							if ver is not None:
								start = atom_str.rfind(ver)
								end = start + len(ver)
								colored_idx.update(range(start, end))

							if slot_str:
								ii = atom_str.find(slot_str)
								colored_idx.update(range(ii, ii + len(slot_str)))


							if op is not None:
								atom_str = atom_str.replace(op, colorize("BAD", op), 1)

							if ver is not None:
								start = atom_str.rfind(ver)
								end = start + len(ver)
								atom_str = atom_str[:start] + \
									colorize("BAD", ver) + \
									atom_str[end:]

							if slot_str:
								atom_str = atom_str.replace(slot_str, colorize("BAD", slot_str), 1)

						elif slot_violated:
							slot = atom.slot
							sub_slot = atom.sub_slot
							slot_operator = atom.slot_operator

							slot_str = ""
							if slot:
								slot_str = ":" + slot
							if sub_slot:
								slot_str += "/" + sub_slot
							if slot_operator:
								slot_str += slot_operator

							if slot_str:
								ii = atom_str.find(slot_str)
								colored_idx.update(range(ii, ii + len(slot_str)))
								atom_str = atom_str.replace(slot_str, colorize("BAD", slot_str), 1)
						
						if use and atom.use.tokens:
							use_part_start = atom_str.find("[")
							use_part_end = atom_str.find("]")
							
							new_tokens = []
							# Compute start index in non-colored atom.
							ii = str(atom).find("[") +  1
							for token in atom.use.tokens:
								if token.lstrip("-!").rstrip("=?") in use:
									new_tokens.append(colorize("BAD", token))
									colored_idx.update(range(ii, ii + len(token)))
								else:
									new_tokens.append(token)
								ii += 1 + len(token)

							atom_str = atom_str[:use_part_start] \
								+ "[%s]" % (",".join(new_tokens),) + \
								atom_str[use_part_end+1:]
						
						return atom_str, colored_idx
Exemplo n.º 12
0
	def _prepare_conflict_msg_and_check_for_specificity(self):
		"""
		Print all slot conflicts in a human readable way.
		"""
		_pkg_use_enabled = self.depgraph._pkg_use_enabled
		usepkgonly = "--usepkgonly" in self.myopts
		need_rebuild = {}
		verboseconflicts = "--verbose-conflicts" in self.myopts
		any_omitted_parents = False
		msg = self.conflict_msg
		indent = "  "
		msg.append("\n!!! Multiple package instances within a single " + \
			"package slot have been pulled\n")
		msg.append("!!! into the dependency graph, resulting" + \
			" in a slot conflict:\n\n")

		for root, slot_atom, pkgs in self.all_conflicts:
			msg.append("%s" % (slot_atom,))
			if root != self.depgraph._frozen_config._running_root.root:
				msg.append(" for %s" % (root,))
			msg.append("\n\n")

			for pkg in pkgs:
				msg.append(indent)
				msg.append("%s %s" % (pkg, pkg_use_display(pkg,
					self.depgraph._frozen_config.myopts,
					modified_use=self.depgraph._pkg_use_enabled(pkg))))
				parent_atoms = self.all_parents.get(pkg)
				if parent_atoms:
					#Create a list of collision reasons and map them to sets
					#of atoms.
					#Possible reasons:
					#	("version", "ge") for operator >=, >
					#	("version", "eq") for operator =, ~
					#	("version", "le") for operator <=, <
					#	("use", "<some use flag>") for unmet use conditionals
					collision_reasons = {}
					num_all_specific_atoms = 0

					for ppkg, atom in parent_atoms:
						if not atom.soname:
							atom_set = InternalPackageSet(
								initial_atoms=(atom,))
							atom_without_use_set = InternalPackageSet(
								initial_atoms=(atom.without_use,))
							atom_without_use_and_slot_set = \
								InternalPackageSet(initial_atoms=(
								atom.without_use.without_slot,))

						for other_pkg in pkgs:
							if other_pkg == pkg:
								continue

							if atom.soname:
								# The soname does not match.
								key = ("soname", atom)
								atoms = collision_reasons.get(key, set())
								atoms.add((ppkg, atom, other_pkg))
								num_all_specific_atoms += 1
								collision_reasons[key] = atoms
							elif not atom_without_use_and_slot_set.findAtomForPackage(other_pkg,
								modified_use=_pkg_use_enabled(other_pkg)):
								if atom.operator is not None:
									# The version range does not match.
									sub_type = None
									if atom.operator in (">=", ">"):
										sub_type = "ge"
									elif atom.operator in ("=", "~"):
										sub_type = "eq"
									elif atom.operator in ("<=", "<"):
										sub_type = "le"

									key = ("version", sub_type)
									atoms = collision_reasons.get(key, set())
									atoms.add((ppkg, atom, other_pkg))
									num_all_specific_atoms += 1
									collision_reasons[key] = atoms

							elif not atom_without_use_set.findAtomForPackage(other_pkg, \
								modified_use=_pkg_use_enabled(other_pkg)):
									# The slot and/or sub_slot does not match.
									key = ("slot", (atom.slot, atom.sub_slot, atom.slot_operator))
									atoms = collision_reasons.get(key, set())
									atoms.add((ppkg, atom, other_pkg))
									num_all_specific_atoms += 1
									collision_reasons[key] = atoms

							elif not atom_set.findAtomForPackage(other_pkg, \
								modified_use=_pkg_use_enabled(other_pkg)):
								missing_iuse = other_pkg.iuse.get_missing_iuse(
									atom.unevaluated_atom.use.required)
								if missing_iuse:
									for flag in missing_iuse:
										atoms = collision_reasons.get(("use", flag), set())
										atoms.add((ppkg, atom, other_pkg))
										collision_reasons[("use", flag)] = atoms
									num_all_specific_atoms += 1
								else:
									#Use conditionals not met.
									violated_atom = atom.violated_conditionals(_pkg_use_enabled(other_pkg), \
										other_pkg.iuse.is_valid_flag)
									if violated_atom.use is None:
										# Something like bug #453400 caused the
										# above findAtomForPackage call to
										# return None unexpectedly.
										msg = ("\n\n!!! BUG: Detected "
											"USE dep match inconsistency:\n"
											"\tppkg: %s\n"
											"\tviolated_atom: %s\n"
											"\tatom: %s unevaluated: %s\n"
											"\tother_pkg: %s IUSE: %s USE: %s\n" %
											(ppkg,
											violated_atom,
											atom,
											atom.unevaluated_atom,
											other_pkg,
											sorted(other_pkg.iuse.all),
											sorted(_pkg_use_enabled(other_pkg))))
										writemsg(msg, noiselevel=-2)
										raise AssertionError(
											'BUG: USE dep match inconsistency')
									for flag in violated_atom.use.enabled.union(violated_atom.use.disabled):
										atoms = collision_reasons.get(("use", flag), set())
										atoms.add((ppkg, atom, other_pkg))
										collision_reasons[("use", flag)] = atoms
									num_all_specific_atoms += 1
							elif isinstance(ppkg, AtomArg) and other_pkg.installed:
								parent_atoms = collision_reasons.get(("AtomArg", None), set())
								parent_atoms.add((ppkg, atom))
								collision_reasons[("AtomArg", None)] = parent_atoms
								num_all_specific_atoms += 1

					msg.append(" pulled in by\n")

					selected_for_display = set()
					unconditional_use_deps = set()

					for (type, sub_type), parents in collision_reasons.items():
						#From each (type, sub_type) pair select at least one atom.
						#Try to select as few atoms as possible

						if type == "version":
							#Find the atom with version that is as far away as possible.
							best_matches = {}
							for ppkg, atom, other_pkg in parents:
								if atom.cp in best_matches:
									cmp = vercmp( \
										cpv_getversion(atom.cpv), \
										cpv_getversion(best_matches[atom.cp][1].cpv))

									if (sub_type == "ge" and  cmp > 0) \
										or (sub_type == "le" and cmp < 0) \
										or (sub_type == "eq" and cmp > 0):
										best_matches[atom.cp] = (ppkg, atom)
								else:
									best_matches[atom.cp] = (ppkg, atom)
								if verboseconflicts:
									selected_for_display.add((ppkg, atom))
							if not verboseconflicts:
								selected_for_display.update(
										best_matches.values())
						elif type in ("soname", "slot"):
							# Check for packages that might need to
							# be rebuilt, but cannot be rebuilt for
							# some reason.
							for ppkg, atom, other_pkg in parents:
								if not (isinstance(ppkg, Package) and ppkg.installed):
									continue
								if not (atom.soname or atom.slot_operator_built):
									continue
								if self.depgraph._frozen_config.excluded_pkgs.findAtomForPackage(ppkg,
									modified_use=self.depgraph._pkg_use_enabled(ppkg)):
									selected_for_display.add((ppkg, atom))
									need_rebuild[ppkg] = 'matched by --exclude argument'
								elif self.depgraph._frozen_config.useoldpkg_atoms.findAtomForPackage(ppkg,
									modified_use=self.depgraph._pkg_use_enabled(ppkg)):
									selected_for_display.add((ppkg, atom))
									need_rebuild[ppkg] = 'matched by --useoldpkg-atoms argument'
								elif usepkgonly:
									# This case is tricky, so keep quiet in order to avoid false-positives.
									pass
								elif not self.depgraph._equiv_ebuild_visible(ppkg):
									selected_for_display.add((ppkg, atom))
									need_rebuild[ppkg] = 'ebuild is masked or unavailable'

							for ppkg, atom, other_pkg in parents:
								selected_for_display.add((ppkg, atom))
								if not verboseconflicts:
									break
						elif type == "use":
							#Prefer atoms with unconditional use deps over, because it's
							#not possible to change them on the parent, which means there
							#are fewer possible solutions.
							use = sub_type
							for ppkg, atom, other_pkg in parents:
								missing_iuse = other_pkg.iuse.get_missing_iuse(
									atom.unevaluated_atom.use.required)
								if missing_iuse:
									unconditional_use_deps.add((ppkg, atom))
								else:
									parent_use = None
									if isinstance(ppkg, Package):
										parent_use = _pkg_use_enabled(ppkg)
									violated_atom = atom.unevaluated_atom.violated_conditionals(
										_pkg_use_enabled(other_pkg),
										other_pkg.iuse.is_valid_flag,
										parent_use=parent_use)
									# It's possible for autounmask to change
									# parent_use such that the unevaluated form
									# of the atom now matches, even though the
									# earlier evaluated form (from before
									# autounmask changed parent_use) does not.
									# In this case (see bug #374423), it's
									# expected that violated_atom.use is None.
									# Since the atom now matches, we don't want
									# to display it in the slot conflict
									# message, so we simply ignore it and rely
									# on the autounmask display to communicate
									# the necessary USE change to the user.
									if violated_atom.use is None:
										continue
									if use in violated_atom.use.enabled or \
										use in violated_atom.use.disabled:
										unconditional_use_deps.add((ppkg, atom))
								# When USE flags are removed, it can be
								# essential to see all broken reverse
								# dependencies here, so don't omit any.
								# If the list is long, people can simply
								# use a pager.
								selected_for_display.add((ppkg, atom))
						elif type == "AtomArg":
							for ppkg, atom in parents:
								selected_for_display.add((ppkg, atom))

					def highlight_violations(atom, version, use, slot_violated):
						"""Colorize parts of an atom"""
						atom_str = "%s" % (atom,)
						colored_idx = set()
						if version:
							op = atom.operator
							ver = None
							if atom.cp != atom.cpv:
								ver = cpv_getversion(atom.cpv)
							slot = atom.slot
							sub_slot = atom.sub_slot
							slot_operator = atom.slot_operator

							if op == "=*":
								op = "="
								ver += "*"

							slot_str = ""
							if slot:
								slot_str = ":" + slot
							if sub_slot:
								slot_str += "/" + sub_slot
							if slot_operator:
								slot_str += slot_operator

							# Compute color_idx before adding the color codes
							# as these change the indices of the letters.
							if op is not None:
								colored_idx.update(range(len(op)))

							if ver is not None:
								start = atom_str.rfind(ver)
								end = start + len(ver)
								colored_idx.update(range(start, end))

							if slot_str:
								ii = atom_str.find(slot_str)
								colored_idx.update(range(ii, ii + len(slot_str)))


							if op is not None:
								atom_str = atom_str.replace(op, colorize("BAD", op), 1)

							if ver is not None:
								start = atom_str.rfind(ver)
								end = start + len(ver)
								atom_str = atom_str[:start] + \
									colorize("BAD", ver) + \
									atom_str[end:]

							if slot_str:
								atom_str = atom_str.replace(slot_str, colorize("BAD", slot_str), 1)

						elif slot_violated:
							slot = atom.slot
							sub_slot = atom.sub_slot
							slot_operator = atom.slot_operator

							slot_str = ""
							if slot:
								slot_str = ":" + slot
							if sub_slot:
								slot_str += "/" + sub_slot
							if slot_operator:
								slot_str += slot_operator

							if slot_str:
								ii = atom_str.find(slot_str)
								colored_idx.update(range(ii, ii + len(slot_str)))
								atom_str = atom_str.replace(slot_str, colorize("BAD", slot_str), 1)
						
						if use and atom.use.tokens:
							use_part_start = atom_str.find("[")
							use_part_end = atom_str.find("]")
							
							new_tokens = []
							# Compute start index in non-colored atom.
							ii = str(atom).find("[") +  1
							for token in atom.use.tokens:
								if token.lstrip("-!").rstrip("=?") in use:
									new_tokens.append(colorize("BAD", token))
									colored_idx.update(range(ii, ii + len(token)))
								else:
									new_tokens.append(token)
								ii += 1 + len(token)

							atom_str = atom_str[:use_part_start] \
								+ "[%s]" % (",".join(new_tokens),) + \
								atom_str[use_part_end+1:]
						
						return atom_str, colored_idx

					# Show unconditional use deps first, since those
					# are more problematic than the conditional kind.
					ordered_list = list(unconditional_use_deps)
					if len(selected_for_display) > len(unconditional_use_deps):
						for parent_atom in selected_for_display:
							if parent_atom not in unconditional_use_deps:
								ordered_list.append(parent_atom)
					for parent_atom in ordered_list:
						parent, atom = parent_atom
						if isinstance(parent, Package):
							use_display = pkg_use_display(parent,
								self.depgraph._frozen_config.myopts,
								modified_use=self.depgraph._pkg_use_enabled(parent))
						else:
							use_display = ""
						if atom.soname:
							msg.append("%s required by %s %s\n" %
								(atom, parent, use_display))
						elif isinstance(parent, PackageArg):
							# For PackageArg it's
							# redundant to display the atom attribute.
							msg.append("%s\n" % (parent,))
						elif isinstance(parent, AtomArg):
							msg.append(2*indent)
							msg.append("%s (Argument)\n" % (atom,))
						else:
							# Display the specific atom from SetArg or
							# Package types.
							version_violated = False
							slot_violated = False
							use = []
							for (type, sub_type), parents in collision_reasons.items():
								for x in parents:
									if parent == x[0] and atom == x[1]:
										if type == "version":
											version_violated = True
										elif type == "slot":
											slot_violated = True
										elif type == "use":
											use.append(sub_type)
										break

							atom_str, colored_idx = highlight_violations(atom.unevaluated_atom,
								version_violated, use, slot_violated)

							if version_violated or slot_violated:
								self.is_a_version_conflict = True

							cur_line = "%s required by %s %s\n" % (atom_str, parent, use_display)
							marker_line = ""
							for ii in range(len(cur_line)):
								if ii in colored_idx:
									marker_line += "^"
								else:
									marker_line += " "
							marker_line += "\n"
							msg.append(2*indent)
							msg.append(cur_line)
							msg.append(2*indent)
							msg.append(marker_line)

					if not selected_for_display:
						msg.append(2*indent)
						msg.append("(no parents that aren't satisfied by other packages in this slot)\n")
						self.conflict_is_unspecific = True
					
					omitted_parents = num_all_specific_atoms - len(selected_for_display)
					if omitted_parents:
						any_omitted_parents = True
						msg.append(2*indent)
						if len(selected_for_display) > 1:
							msg.append("(and %d more with the same problems)\n" % omitted_parents)
						else:
							msg.append("(and %d more with the same problem)\n" % omitted_parents)
				else:
					msg.append(" (no parents)\n")
				msg.append("\n")

		if any_omitted_parents:
			msg.append(colorize("INFORM",
				"NOTE: Use the '--verbose-conflicts'"
				" option to display parents omitted above"))
			msg.append("\n")

		if need_rebuild:
			msg.append("\n!!! The slot conflict(s) shown above involve package(s) which may need to\n")
			msg.append("!!! be rebuilt in order to solve the conflict(s). However, the following\n")
			msg.append("!!! package(s) cannot be rebuilt for the reason(s) shown:\n\n")
			for ppkg, reason in need_rebuild.items():
				msg.append("%s%s: %s\n" % (indent, ppkg, reason))
			msg.append("\n")

		msg.append("\n")
Exemplo n.º 13
0
def get_build_dict_db(session, config_id, settings, zobcs_settings_dict, pkg):
	myportdb = portage.portdbapi(mysettings=settings)
	cpvr_list = catpkgsplit(pkg.cpv, silent=1)
	categories = cpvr_list[0]
	package = cpvr_list[1]
	repo = pkg.repo
	ebuild_version = cpv_getversion(pkg.cpv)
	log_msg = "Logging %s:%s" % (pkg.cpv, repo,)
	add_logs(session, log_msg, "info", config_id)
	PackageInfo = get_package_info(session, categories, package, repo)
	build_dict = {}
	build_dict['ebuild_version'] = ebuild_version
	build_dict['package_id'] = PackageInfo.PackageId
	build_dict['cpv'] = pkg.cpv
	build_dict['categories'] = categories
	build_dict['package'] = package
	build_dict['config_id'] = config_id
	init_useflags = zobcs_use_flags(settings, myportdb, pkg.cpv)
	iuse_flags_list, final_use_list = init_useflags.get_flags_pkg(pkg, settings)
	iuse = []
	for iuse_line in iuse_flags_list:
		iuse.append(init_useflags.reduce_flag(iuse_line))
	iuse_flags_list2 = list(set(iuse))
	use_enable = final_use_list
	use_disable = list(set(iuse_flags_list2).difference(set(use_enable)))
	use_flagsDict = {}
	for x in use_enable:
		use_id = get_use_id(session, x)
		use_flagsDict[use_id] = True
	for x in use_disable:
		use_id = get_use_id(session, x)
		use_flagsDict[use_id] = False
	if use_enable == [] and use_disable == []:
		build_dict['build_useflags'] = None
	else:
		build_dict['build_useflags'] = use_flagsDict
	pkgdir = myportdb.getRepositoryPath(repo) + "/" + categories + "/" + package
	ebuild_version_checksum_tree = portage.checksum.sha256hash(pkgdir+ "/" + package + "-" + ebuild_version + ".ebuild")[0]
	build_dict['checksum'] = ebuild_version_checksum_tree
	ebuild_id_list, status = get_ebuild_id_db(session, build_dict['checksum'], build_dict['package_id'])
	if status:
		if ebuild_id_list is None:
			log_msg = "%s:%s Don't have any ebuild_id!" % (pkg.cpv, repo,)
			add_logs(session, log_msg, "info", config_id)
			update_manifest_sql(session, build_dict['package_id'], "0")
			init_package = zobcs_package(session, settings, myportdb, config_id, zobcs_settings_dict)
			init_package.update_package_db(build_dict['package_id'])
			ebuild_id_list, status = get_ebuild_id_db(session, build_dict['checksum'], build_dict['package_id'])
			if status and ebuild_id_list is None:
				log_msg = "%s:%s Don't have any ebuild_id!" % (pkg.cpv, repo,)
				add_logs(session, log_msg, "error", config_id)
		else:
			old_ebuild_id_list = []
			for ebuild_id in ebuild_id_list:
				log_msg = "%s:%s:%s Dups of checksums" % (pkg.cpv, repo, ebuild_id,)
				add_logs(session, log_msg, "error", config_id)
				old_ebuild_id_list.append(ebuild_id)
			add_old_ebuild(session, old_ebuild_id_list)
		return
	build_dict['ebuild_id'] = ebuild_id_list

	build_job_id = get_build_job_id(session, build_dict)
	if build_job_id is None:
		build_dict['build_job_id'] = None
	else:
		build_dict['build_job_id'] = build_job_id
	return build_dict
Exemplo n.º 14
0
 def __new__(self, cpv):
     return PMPackageVersion.__new__(self, cpv_getversion(cpv))
Exemplo n.º 15
0
	def _prepare_conflict_msg_and_check_for_specificity(self):
		"""
		Print all slot conflicts in a human readable way.
		"""
		_pkg_use_enabled = self.depgraph._pkg_use_enabled
		msg = self.conflict_msg
		indent = "  "
		msg.append("\n!!! Multiple package instances within a single " + \
			"package slot have been pulled\n")
		msg.append("!!! into the dependency graph, resulting" + \
			" in a slot conflict:\n\n")

		for (slot_atom, root), pkgs \
			in self.slot_collision_info.items():
			msg.append(str(slot_atom))
			if root != '/':
				msg.append(" for %s" % (root,))
			msg.append("\n\n")

			for pkg in pkgs:
				msg.append(indent)
				msg.append(str(pkg))
				parent_atoms = self.all_parents.get(pkg)
				if parent_atoms:
					#Create a list of collision reasons and map them to sets
					#of atoms.
					#Possible reasons:
					#	("version", "ge") for operator >=, >
					#	("version", "eq") for operator =, ~
					#	("version", "le") for operator <=, <
					#	("use", "<some use flag>") for unmet use conditionals
					collision_reasons = {}
					num_all_specific_atoms = 0

					for ppkg, atom in parent_atoms:
						atom_set = InternalPackageSet(initial_atoms=(atom,))
						atom_without_use_set = InternalPackageSet(initial_atoms=(atom.without_use,))

						for other_pkg in pkgs:
							if other_pkg == pkg:
								continue

							if not atom_without_use_set.findAtomForPackage(other_pkg, \
								modified_use=_pkg_use_enabled(other_pkg)):
								#The version range does not match.
								sub_type = None
								if atom.operator in (">=", ">"):
									sub_type = "ge"
								elif atom.operator in ("=", "~"):
									sub_type = "eq"
								elif atom.operator in ("<=", "<"):
									sub_type = "le"

								atoms = collision_reasons.get(("version", sub_type), set())
								atoms.add((ppkg, atom, other_pkg))
								num_all_specific_atoms += 1
								collision_reasons[("version", sub_type)] = atoms
							elif not atom_set.findAtomForPackage(other_pkg, \
								modified_use=_pkg_use_enabled(other_pkg)):
								#Use conditionals not met.
								violated_atom = atom.violated_conditionals(_pkg_use_enabled(other_pkg), \
									other_pkg.iuse.is_valid_flag)
								for flag in violated_atom.use.enabled.union(violated_atom.use.disabled):
									atoms = collision_reasons.get(("use", flag), set())
									atoms.add((ppkg, atom, other_pkg))
									collision_reasons[("use", flag)] = atoms
								num_all_specific_atoms += 1

					msg.append(" pulled in by\n")

					selected_for_display = set()

					for (type, sub_type), parents in collision_reasons.items():
						#From each (type, sub_type) pair select at least one atom.
						#Try to select as few atoms as possible

						if type == "version":
							#Find the atom with version that is as far away as possible.
							best_matches = {}
							for ppkg, atom, other_pkg in parents:
								if atom.cp in best_matches:
									cmp = vercmp( \
										cpv_getversion(atom.cpv), \
										cpv_getversion(best_matches[atom.cp][1].cpv))

									if (sub_type == "ge" and  cmp > 0) \
										or (sub_type == "le" and cmp < 0) \
										or (sub_type == "eq" and cmp > 0):
										best_matches[atom.cp] = (ppkg, atom)
								else:
									best_matches[atom.cp] = (ppkg, atom)
							selected_for_display.update(best_matches.values())
						elif type == "use":
							#Prefer atoms with unconditional use deps over, because it's
							#not possible to change them on the parent, which means there
							#are fewer possible solutions.
							use = sub_type
							hard_matches = set()
							conditional_matches = set()
							for ppkg, atom, other_pkg in parents:
								parent_use = None
								if isinstance(ppkg, Package):
									parent_use = _pkg_use_enabled(ppkg)
								violated_atom = atom.unevaluated_atom.violated_conditionals( \
									_pkg_use_enabled(other_pkg), other_pkg.iuse.is_valid_flag,
									parent_use=parent_use)
								if use in violated_atom.use.enabled.union(violated_atom.use.disabled):
									hard_matches.add((ppkg, atom))
								else:
									conditional_matches.add((ppkg, atom))

							if hard_matches:
								matches = hard_matches
							else:
								matches = conditional_matches
							
							if not selected_for_display.intersection(matches):
								selected_for_display.add(matches.pop())

					def highlight_violations(atom, version, use=[]):
						"""Colorize parts of an atom"""
						atom_str = str(atom)
						if version:
							op = atom.operator
							ver = cpv_getversion(atom.cpv)
							slot = atom.slot
							atom_str = atom_str.replace(op, colorize("BAD", op), 1)
							
							start = atom_str.rfind(ver)
							end = start + len(ver)
							atom_str = atom_str[:start] + \
								colorize("BAD", ver) + \
								atom_str[end+1:]
							if slot:
								atom_str = atom_str.replace(":" + slot, colorize("BAD", ":" + slot))
						
						if use and atom.use.tokens:
							use_part_start = atom_str.find("[")
							use_part_end = atom_str.find("]")
							
							new_tokens = []
							for token in atom.use.tokens:
								if token.lstrip("-!").rstrip("=?") in use:
									new_tokens.append(colorize("BAD", token))
								else:
									new_tokens.append(token)

							atom_str = atom_str[:use_part_start] \
								+ "[%s]" % (",".join(new_tokens),) + \
								atom_str[use_part_end+1:]
						
						return atom_str

					for parent_atom in selected_for_display:
						parent, atom = parent_atom
						msg.append(2*indent)
						if isinstance(parent,
							(PackageArg, AtomArg)):
							# For PackageArg and AtomArg types, it's
							# redundant to display the atom attribute.
							msg.append(str(parent))
						else:
							# Display the specific atom from SetArg or
							# Package types.
							version_violated = False
							use = []
							for type, sub_type in collision_reasons:
								if type == "version":
									for x in collision_reasons[(type, sub_type)]:
										if ppkg == x[0] and atom == x[1]:
											version_violated = True
								elif type == "use":
									use.append(sub_type)

							atom_str = highlight_violations(atom.unevaluated_atom, version_violated, use)

							if version_violated:
								self.is_a_version_conflict = True

							msg.append("%s required by %s" % (atom_str, parent))
						msg.append("\n")
					
					if not selected_for_display:
						msg.append(2*indent)
						msg.append("(no parents that aren't satisfied by other packages in this slot)\n")
						self.conflict_is_unspecific = True
					
					omitted_parents = num_all_specific_atoms - len(selected_for_display)
					if omitted_parents:
						msg.append(2*indent)
						if len(selected_for_display) > 1:
							msg.append("(and %d more with the same problems)\n" % omitted_parents)
						else:
							msg.append("(and %d more with the same problem)\n" % omitted_parents)
				else:
					msg.append(" (no parents)\n")
				msg.append("\n")
		msg.append("\n")