1 |
commit: c0051a11f714c49defbd63d82a507e592937f29f |
2 |
Author: Sebastian Luther <SebastianLuther <AT> gmx <DOT> de> |
3 |
AuthorDate: Mon Jan 27 22:16:20 2014 +0000 |
4 |
Commit: Sebastian Luther <SebastianLuther <AT> gmx <DOT> de > |
5 |
CommitDate: Wed Feb 5 19:39:21 2014 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=c0051a11 |
7 |
|
8 |
format_unmatched_atom: Pretty printing for unmatched atoms |
9 |
|
10 |
This is a split out from the slot conflict handler to be |
11 |
used in other places. |
12 |
|
13 |
--- |
14 |
pym/_emerge/resolver/output.py | 109 +++++++++++++++++++++++++++++++++++++++-- |
15 |
1 file changed, 106 insertions(+), 3 deletions(-) |
16 |
|
17 |
diff --git a/pym/_emerge/resolver/output.py b/pym/_emerge/resolver/output.py |
18 |
index 3e8552f..5f550be 100644 |
19 |
--- a/pym/_emerge/resolver/output.py |
20 |
+++ b/pym/_emerge/resolver/output.py |
21 |
@@ -1,4 +1,4 @@ |
22 |
-# Copyright 2010-2013 Gentoo Foundation |
23 |
+# Copyright 2010-2014 Gentoo Foundation |
24 |
# Distributed under the terms of the GNU General Public License v2 |
25 |
|
26 |
"""Resolver output display operation. |
27 |
@@ -7,7 +7,7 @@ |
28 |
from __future__ import unicode_literals |
29 |
|
30 |
__all__ = ( |
31 |
- "Display", |
32 |
+ "Display", "format_unmatched_atom", |
33 |
) |
34 |
|
35 |
import sys |
36 |
@@ -23,8 +23,9 @@ from portage.package.ebuild._spawn_nofetch import spawn_nofetch |
37 |
from portage.output import ( blue, colorize, create_color_func, |
38 |
darkblue, darkgreen, green, nc_len, teal) |
39 |
bad = create_color_func("BAD") |
40 |
+from portage._sets.base import InternalPackageSet |
41 |
from portage.util import writemsg_stdout |
42 |
-from portage.versions import best |
43 |
+from portage.versions import best, cpv_getversion |
44 |
|
45 |
from _emerge.Blocker import Blocker |
46 |
from _emerge.create_world_atom import create_world_atom |
47 |
@@ -916,3 +917,105 @@ class Display(object): |
48 |
self.print_changelog() |
49 |
|
50 |
return os.EX_OK |
51 |
+ |
52 |
+ |
53 |
+def format_unmatched_atom(pkg, atom, pkg_use_enabled): |
54 |
+ """ |
55 |
+ Returns two strings. The first string contains the |
56 |
+ 'atom' with parts of the atom colored, which 'pkg' |
57 |
+ doesn't match. The second string has the same number |
58 |
+ of characters as the first one, but consists of only |
59 |
+ white space or ^. The ^ characters have the same position |
60 |
+ as the colored parts of the first string. |
61 |
+ """ |
62 |
+ # Things to check: |
63 |
+ # 1. Version |
64 |
+ # 2. cp |
65 |
+ # 3. slot/sub_slot |
66 |
+ # 4. repository |
67 |
+ # 5. USE |
68 |
+ |
69 |
+ highlight = set() |
70 |
+ |
71 |
+ def perform_coloring(): |
72 |
+ atom_str = "" |
73 |
+ marker_str = "" |
74 |
+ for ii, x in enumerate(atom): |
75 |
+ if ii in highlight: |
76 |
+ atom_str += colorize("BAD", x) |
77 |
+ marker_str += "^" |
78 |
+ else: |
79 |
+ atom_str += x |
80 |
+ marker_str += " " |
81 |
+ return atom_str, marker_str |
82 |
+ |
83 |
+ if atom.cp != pkg.cp: |
84 |
+ # Highlight the cp part only. |
85 |
+ ii = atom.find(atom.cp) |
86 |
+ highlight.update(range(ii, ii + len(atom.cp))) |
87 |
+ return perform_coloring() |
88 |
+ |
89 |
+ version_atom = atom.without_repo.without_slot.without_use |
90 |
+ version_atom_set = InternalPackageSet(initial_atoms=(version_atom,)) |
91 |
+ highlight_version = not bool(version_atom_set.findAtomForPackage(pkg, |
92 |
+ modified_use=pkg_use_enabled(pkg))) |
93 |
+ |
94 |
+ highlight_slot = False |
95 |
+ if (atom.slot and atom.slot != pkg.slot) or \ |
96 |
+ (atom.sub_slot and atom.sub_slot != pkg.sub_slot): |
97 |
+ highlight_slot = True |
98 |
+ |
99 |
+ if highlight_version: |
100 |
+ op = atom.operator |
101 |
+ ver = None |
102 |
+ if atom.cp != atom.cpv: |
103 |
+ ver = cpv_getversion(atom.cpv) |
104 |
+ |
105 |
+ if op == "=*": |
106 |
+ op = "=" |
107 |
+ ver += "*" |
108 |
+ |
109 |
+ if op is not None: |
110 |
+ highlight.update(range(len(op))) |
111 |
+ |
112 |
+ if ver is not None: |
113 |
+ start = atom.rfind(ver) |
114 |
+ end = start + len(ver) |
115 |
+ highlight.update(range(start, end)) |
116 |
+ |
117 |
+ if highlight_slot: |
118 |
+ slot_str = ":" + atom.slot |
119 |
+ if atom.sub_slot: |
120 |
+ slot_str += "/" + atom.sub_slot |
121 |
+ if atom.slot_operator: |
122 |
+ slot_str += atom.slot_operator |
123 |
+ start = atom.find(slot_str) |
124 |
+ end = start + len(slot_str) |
125 |
+ highlight.update(range(start, end)) |
126 |
+ |
127 |
+ highlight_use = set() |
128 |
+ if atom.use: |
129 |
+ use_atom = "%s[%s]" % (atom.cp, str(atom.use)) |
130 |
+ use_atom_set = InternalPackageSet(initial_atoms=(use_atom,)) |
131 |
+ if not use_atom_set.findAtomForPackage(pkg, \ |
132 |
+ modified_use=pkg_use_enabled(pkg)): |
133 |
+ missing_iuse = pkg.iuse.get_missing_iuse( |
134 |
+ atom.unevaluated_atom.use.required) |
135 |
+ if missing_iuse: |
136 |
+ highlight_use = set(missing_iuse) |
137 |
+ else: |
138 |
+ #Use conditionals not met. |
139 |
+ violated_atom = atom.violated_conditionals( |
140 |
+ pkg_use_enabled(pkg), pkg.iuse.is_valid_flag) |
141 |
+ if violated_atom.use is not None: |
142 |
+ highlight_use = set(violated_atom.use.enabled.union( |
143 |
+ violated_atom.use.disabled)) |
144 |
+ |
145 |
+ if highlight_use: |
146 |
+ ii = atom.find("[") + 1 |
147 |
+ for token in atom.use.tokens: |
148 |
+ if token.lstrip("-!").rstrip("=?") in highlight_use: |
149 |
+ highlight.update(range(ii, ii + len(token))) |
150 |
+ ii += len(token) + 1 |
151 |
+ |
152 |
+ return perform_coloring() |