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