OLD | NEW |
1 # Copyright 2010 Gentoo Foundation | 1 # Copyright 2010 Gentoo Foundation |
2 # Distributed under the terms of the GNU General Public License v2 | 2 # Distributed under the terms of the GNU General Public License v2 |
3 | 3 |
4 import copy | 4 import copy |
5 | 5 |
6 class BacktrackParameter(object): | 6 class BacktrackParameter(object): |
7 | 7 |
8 __slots__ = ( | 8 __slots__ = ( |
9 "needed_unstable_keywords", "runtime_pkg_mask", "needed_use_conf
ig_changes", "needed_license_changes", | 9 "needed_unstable_keywords", "runtime_pkg_mask", "needed_use_conf
ig_changes", "needed_license_changes", |
| 10 "rebuild_list", "reinstall_list" |
10 ) | 11 ) |
11 | 12 |
12 def __init__(self): | 13 def __init__(self): |
13 self.needed_unstable_keywords = set() | 14 self.needed_unstable_keywords = set() |
14 self.runtime_pkg_mask = {} | 15 self.runtime_pkg_mask = {} |
15 self.needed_use_config_changes = {} | 16 self.needed_use_config_changes = {} |
16 self.needed_license_changes = {} | 17 self.needed_license_changes = {} |
| 18 self.rebuild_list = set() |
| 19 self.reinstall_list = set() |
17 | 20 |
18 def __deepcopy__(self, memo=None): | 21 def __deepcopy__(self, memo=None): |
19 if memo is None: | 22 if memo is None: |
20 memo = {} | 23 memo = {} |
21 result = BacktrackParameter() | 24 result = BacktrackParameter() |
22 memo[id(self)] = result | 25 memo[id(self)] = result |
23 | 26 |
24 #Shallow copies are enough here, as we only need to ensure that
nobody adds stuff | 27 #Shallow copies are enough here, as we only need to ensure that
nobody adds stuff |
25 #to our sets and dicts. The existing content is immutable. | 28 #to our sets and dicts. The existing content is immutable. |
26 result.needed_unstable_keywords = copy.copy(self.needed_unstable
_keywords) | 29 result.needed_unstable_keywords = copy.copy(self.needed_unstable
_keywords) |
27 result.runtime_pkg_mask = copy.copy(self.runtime_pkg_mask) | 30 result.runtime_pkg_mask = copy.copy(self.runtime_pkg_mask) |
28 result.needed_use_config_changes = copy.copy(self.needed_use_con
fig_changes) | 31 result.needed_use_config_changes = copy.copy(self.needed_use_con
fig_changes) |
29 result.needed_license_changes = copy.copy(self.needed_license_ch
anges) | 32 result.needed_license_changes = copy.copy(self.needed_license_ch
anges) |
| 33 result.rebuild_list = copy.copy(self.rebuild_list) |
| 34 result.reinstall_list = copy.copy(self.reinstall_list) |
30 | 35 |
31 return result | 36 return result |
32 | 37 |
33 def __eq__(self, other): | 38 def __eq__(self, other): |
34 return self.needed_unstable_keywords == other.needed_unstable_ke
ywords and \ | 39 return self.needed_unstable_keywords == other.needed_unstable_ke
ywords and \ |
35 self.runtime_pkg_mask == other.runtime_pkg_mask and \ | 40 self.runtime_pkg_mask == other.runtime_pkg_mask and \ |
36 self.needed_use_config_changes == other.needed_use_confi
g_changes and \ | 41 self.needed_use_config_changes == other.needed_use_confi
g_changes and \ |
37 » » » self.needed_license_changes == other.needed_license_chan
ges | 42 » » » self.needed_license_changes == other.needed_license_chan
ges and \ |
| 43 » » » self.rebuild_list == other.rebuild_list and \ |
| 44 » » » self.reinstall_list == other.reinstall_list |
38 | 45 |
39 | 46 |
40 class _BacktrackNode: | 47 class _BacktrackNode: |
41 | 48 |
42 __slots__ = ( | 49 __slots__ = ( |
43 "parameter", "depth", "mask_steps", "terminal", | 50 "parameter", "depth", "mask_steps", "terminal", |
44 ) | 51 ) |
45 | 52 |
46 def __init__(self, parameter=BacktrackParameter(), depth=0, mask_steps=0
, terminal=True): | 53 def __init__(self, parameter=BacktrackParameter(), depth=0, mask_steps=0
, terminal=True): |
47 self.parameter = parameter | 54 self.parameter = parameter |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 | 137 |
131 for change, data in changes.items(): | 138 for change, data in changes.items(): |
132 if change == "needed_unstable_keywords": | 139 if change == "needed_unstable_keywords": |
133 para.needed_unstable_keywords.update(data) | 140 para.needed_unstable_keywords.update(data) |
134 elif change == "needed_license_changes": | 141 elif change == "needed_license_changes": |
135 for pkg, missing_licenses in data: | 142 for pkg, missing_licenses in data: |
136 para.needed_license_changes.setdefault(p
kg, set()).update(missing_licenses) | 143 para.needed_license_changes.setdefault(p
kg, set()).update(missing_licenses) |
137 elif change == "needed_use_config_changes": | 144 elif change == "needed_use_config_changes": |
138 for pkg, (new_use, new_changes) in data: | 145 for pkg, (new_use, new_changes) in data: |
139 para.needed_use_config_changes[pkg] = (n
ew_use, new_changes) | 146 para.needed_use_config_changes[pkg] = (n
ew_use, new_changes) |
| 147 elif change == "rebuild_list": |
| 148 para.rebuild_list.update(data) |
| 149 elif change == "reinstall_list": |
| 150 para.reinstall_list.update(data) |
140 | 151 |
141 self._add(new_node, explore=explore) | 152 self._add(new_node, explore=explore) |
142 self._current_node = new_node | 153 self._current_node = new_node |
143 | 154 |
144 | 155 |
145 def feedback(self, infos): | 156 def feedback(self, infos): |
146 """ | 157 """ |
147 Takes information from the depgraph and computes new backtrack p
arameters to try. | 158 Takes information from the depgraph and computes new backtrack p
arameters to try. |
148 """ | 159 """ |
149 assert self._current_node is not None, "call feedback() only aft
er get() was called" | 160 assert self._current_node is not None, "call feedback() only aft
er get() was called" |
(...skipping 22 matching lines...) Expand all Loading... |
172 Like, get() but returns the backtrack parameter that has as many
config changes as possible, | 183 Like, get() but returns the backtrack parameter that has as many
config changes as possible, |
173 but has no masks. This makes --autounmask effective, but prevent
s confusing error messages | 184 but has no masks. This makes --autounmask effective, but prevent
s confusing error messages |
174 with "masked by backtracking". | 185 with "masked by backtracking". |
175 """ | 186 """ |
176 best_node = self._root | 187 best_node = self._root |
177 for node in self._nodes: | 188 for node in self._nodes: |
178 if node.terminal and node.depth > best_node.depth: | 189 if node.terminal and node.depth > best_node.depth: |
179 best_node = node | 190 best_node = node |
180 | 191 |
181 return copy.deepcopy(best_node.parameter) | 192 return copy.deepcopy(best_node.parameter) |
OLD | NEW |