From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 7FCC81380DC for ; Wed, 5 Feb 2014 19:42:16 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 3A058E0CC6; Wed, 5 Feb 2014 19:42:15 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 853EDE0CC6 for ; Wed, 5 Feb 2014 19:42:14 +0000 (UTC) Received: from spoonbill.gentoo.org (spoonbill.gentoo.org [81.93.255.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 57F8933F918 for ; Wed, 5 Feb 2014 19:42:13 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by spoonbill.gentoo.org (Postfix) with ESMTP id C6DDC18888 for ; Wed, 5 Feb 2014 19:42:09 +0000 (UTC) From: "Sebastian Luther" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Sebastian Luther" Message-ID: <1391629161.c0051a11f714c49defbd63d82a507e592937f29f.few@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: pym/_emerge/resolver/ X-VCS-Repository: proj/portage X-VCS-Files: pym/_emerge/resolver/output.py X-VCS-Directories: pym/_emerge/resolver/ X-VCS-Committer: few X-VCS-Committer-Name: Sebastian Luther X-VCS-Revision: c0051a11f714c49defbd63d82a507e592937f29f X-VCS-Branch: master Date: Wed, 5 Feb 2014 19:42:09 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 636fb479-8ab9-41ff-af78-59f53d988075 X-Archives-Hash: a40950f4f768e820eb62a054b06f2a87 commit: c0051a11f714c49defbd63d82a507e592937f29f Author: Sebastian Luther gmx de> AuthorDate: Mon Jan 27 22:16:20 2014 +0000 Commit: Sebastian Luther gmx de > CommitDate: Wed Feb 5 19:39:21 2014 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=c0051a11 format_unmatched_atom: Pretty printing for unmatched atoms This is a split out from the slot conflict handler to be used in other places. --- pym/_emerge/resolver/output.py | 109 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 106 insertions(+), 3 deletions(-) diff --git a/pym/_emerge/resolver/output.py b/pym/_emerge/resolver/output.py index 3e8552f..5f550be 100644 --- a/pym/_emerge/resolver/output.py +++ b/pym/_emerge/resolver/output.py @@ -1,4 +1,4 @@ -# Copyright 2010-2013 Gentoo Foundation +# Copyright 2010-2014 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 """Resolver output display operation. @@ -7,7 +7,7 @@ from __future__ import unicode_literals __all__ = ( - "Display", + "Display", "format_unmatched_atom", ) import sys @@ -23,8 +23,9 @@ from portage.package.ebuild._spawn_nofetch import spawn_nofetch from portage.output import ( blue, colorize, create_color_func, darkblue, darkgreen, green, nc_len, teal) bad = create_color_func("BAD") +from portage._sets.base import InternalPackageSet from portage.util import writemsg_stdout -from portage.versions import best +from portage.versions import best, cpv_getversion from _emerge.Blocker import Blocker from _emerge.create_world_atom import create_world_atom @@ -916,3 +917,105 @@ class Display(object): self.print_changelog() return os.EX_OK + + +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()