1 |
Author: zmedico |
2 |
Date: 2008-06-27 04:00:48 +0000 (Fri, 27 Jun 2008) |
3 |
New Revision: 10809 |
4 |
|
5 |
Modified: |
6 |
main/trunk/pym/_emerge/__init__.py |
7 |
Log: |
8 |
Split the --skipfirst code into a resume_depgraph() function that will |
9 |
be useful for implementing a --keep-going option (bug #12768). |
10 |
|
11 |
|
12 |
Modified: main/trunk/pym/_emerge/__init__.py |
13 |
=================================================================== |
14 |
--- main/trunk/pym/_emerge/__init__.py 2008-06-26 22:05:00 UTC (rev 10808) |
15 |
+++ main/trunk/pym/_emerge/__init__.py 2008-06-27 04:00:48 UTC (rev 10809) |
16 |
@@ -5392,7 +5392,7 @@ |
17 |
world_set.update(all_added) |
18 |
world_set.unlock() |
19 |
|
20 |
- def loadResumeCommand(self, resume_data): |
21 |
+ def loadResumeCommand(self, resume_data, skip_masked=False): |
22 |
""" |
23 |
Add a resume command to the graph and validate it in the process. This |
24 |
will raise a PackageNotFound exception if a package is not available. |
25 |
@@ -5405,7 +5405,6 @@ |
26 |
if not isinstance(mergelist, list): |
27 |
mergelist = [] |
28 |
|
29 |
- skipfirst = "--skipfirst" in self.myopts |
30 |
fakedb = self.mydbapi |
31 |
trees = self.trees |
32 |
serialized_tasks = [] |
33 |
@@ -5443,7 +5442,7 @@ |
34 |
root_config = self.roots[pkg.root] |
35 |
if "merge" == pkg.operation and \ |
36 |
not visible(root_config.settings, pkg): |
37 |
- if skipfirst: |
38 |
+ if skip_masked: |
39 |
masked_tasks.append(Dependency(root=pkg.root, parent=pkg)) |
40 |
else: |
41 |
self._unsatisfied_deps_for_display.append( |
42 |
@@ -5497,7 +5496,7 @@ |
43 |
# was dropped via --skipfirst. It makes the |
44 |
# resume list invalid, so convert it to a |
45 |
# UnsatisfiedResumeDep exception. |
46 |
- raise self.UnsatisfiedResumeDep( |
47 |
+ raise self.UnsatisfiedResumeDep(self, |
48 |
masked_tasks + self._unsatisfied_deps) |
49 |
self._serialized_tasks_cache = None |
50 |
try: |
51 |
@@ -5574,6 +5573,9 @@ |
52 |
can occur when a required package is dropped from the |
53 |
merge list via --skipfirst. |
54 |
""" |
55 |
+ def __init__(self, depgraph, value): |
56 |
+ portage.exception.PortageException.__init__(self, value) |
57 |
+ self.depgraph = depgraph |
58 |
|
59 |
class _internal_exception(portage.exception.PortageException): |
60 |
def __init__(self, value=""): |
61 |
@@ -8393,6 +8395,73 @@ |
62 |
else: |
63 |
print "Number removed: "+str(len(cleanlist)) |
64 |
|
65 |
+def resume_depgraph(settings, trees, mtimedb, myopts, myparams, spinner, |
66 |
+ skip_masked=False, skip_unsatisfied=False): |
67 |
+ """ |
68 |
+ Construct a depgraph for the given resume list. This will raise |
69 |
+ PackageNotFound or depgraph.UnsatisfiedResumeDep when necessary. |
70 |
+ @rtype: tuple |
71 |
+ @returns: (success, depgraph, dropped_tasks) |
72 |
+ """ |
73 |
+ mergelist = mtimedb["resume"]["mergelist"] |
74 |
+ dropped_tasks = set() |
75 |
+ while True: |
76 |
+ mydepgraph = depgraph(settings, trees, |
77 |
+ myopts, myparams, spinner) |
78 |
+ try: |
79 |
+ success = mydepgraph.loadResumeCommand(mtimedb["resume"], |
80 |
+ skip_masked=skip_masked) |
81 |
+ except depgraph.UnsatisfiedResumeDep, e: |
82 |
+ if not skip_unsatisfied: |
83 |
+ raise |
84 |
+ |
85 |
+ graph = mydepgraph.digraph |
86 |
+ unsatisfied_parents = dict((dep.parent, dep.parent) \ |
87 |
+ for dep in e.value) |
88 |
+ traversed_nodes = set() |
89 |
+ unsatisfied_stack = list(unsatisfied_parents) |
90 |
+ while unsatisfied_stack: |
91 |
+ pkg = unsatisfied_stack.pop() |
92 |
+ if pkg in traversed_nodes: |
93 |
+ continue |
94 |
+ traversed_nodes.add(pkg) |
95 |
+ |
96 |
+ # If this package was pulled in by a parent |
97 |
+ # package scheduled for merge, removing this |
98 |
+ # package may cause the the parent package's |
99 |
+ # dependency to become unsatisfied. |
100 |
+ for parent_node in graph.parent_nodes(pkg): |
101 |
+ if not isinstance(parent_node, Package) \ |
102 |
+ or parent_node.operation != "merge": |
103 |
+ continue |
104 |
+ unsatisfied = \ |
105 |
+ graph.child_nodes(parent_node, |
106 |
+ ignore_priority=DepPriority.SOFT) |
107 |
+ if pkg in unsatisfied: |
108 |
+ unsatisfied_parents[parent_node] = parent_node |
109 |
+ unsatisfied_stack.append(parent_node) |
110 |
+ |
111 |
+ pruned_mergelist = [x for x in mergelist \ |
112 |
+ if isinstance(x, list) and \ |
113 |
+ tuple(x) not in unsatisfied_parents] |
114 |
+ |
115 |
+ # It shouldn't happen, but if the size of mergelist |
116 |
+ # does not decrease for some reason then the loop |
117 |
+ # will be infinite. Therefore, if that case ever |
118 |
+ # occurs for some reason, raise the exception to |
119 |
+ # break out of the loop. |
120 |
+ if not pruned_mergelist or \ |
121 |
+ len(pruned_mergelist) == len(mergelist): |
122 |
+ raise |
123 |
+ mergelist[:] = pruned_mergelist |
124 |
+ dropped_tasks.update(unsatisfied_parents) |
125 |
+ del e, graph, traversed_nodes, \ |
126 |
+ unsatisfied_parents, unsatisfied_stack |
127 |
+ continue |
128 |
+ else: |
129 |
+ break |
130 |
+ return (success, mydepgraph, dropped_tasks) |
131 |
+ |
132 |
def action_build(settings, trees, mtimedb, |
133 |
myopts, myaction, myfiles, spinner): |
134 |
|
135 |
@@ -8516,66 +8585,18 @@ |
136 |
del mergelist[i] |
137 |
break |
138 |
|
139 |
- dropped_tasks = set() |
140 |
- |
141 |
+ skip_masked = "--skipfirst" in myopts |
142 |
+ skip_unsatisfied = "--skipfirst" in myopts |
143 |
success = False |
144 |
+ mydepgraph = None |
145 |
try: |
146 |
- while True: |
147 |
- mydepgraph = depgraph(settings, trees, |
148 |
- myopts, myparams, spinner) |
149 |
- try: |
150 |
- success = mydepgraph.loadResumeCommand(mtimedb["resume"]) |
151 |
- except depgraph.UnsatisfiedResumeDep, e: |
152 |
- if "--skipfirst" not in myopts: |
153 |
- raise |
154 |
- |
155 |
- graph = mydepgraph.digraph |
156 |
- unsatisfied_parents = dict((dep.parent, dep.parent) \ |
157 |
- for dep in e.value) |
158 |
- traversed_nodes = set() |
159 |
- unsatisfied_stack = list(unsatisfied_parents) |
160 |
- while unsatisfied_stack: |
161 |
- pkg = unsatisfied_stack.pop() |
162 |
- if pkg in traversed_nodes: |
163 |
- continue |
164 |
- traversed_nodes.add(pkg) |
165 |
- |
166 |
- # If this package was pulled in by a parent |
167 |
- # package scheduled for merge, removing this |
168 |
- # package may cause the the parent package's |
169 |
- # dependency to become unsatisfied. |
170 |
- for parent_node in graph.parent_nodes(pkg): |
171 |
- if not isinstance(parent_node, Package) \ |
172 |
- or parent_node.operation != "merge": |
173 |
- continue |
174 |
- unsatisfied = \ |
175 |
- graph.child_nodes(parent_node, |
176 |
- ignore_priority=DepPriority.SOFT) |
177 |
- if pkg in unsatisfied: |
178 |
- unsatisfied_parents[parent_node] = parent_node |
179 |
- unsatisfied_stack.append(parent_node) |
180 |
- |
181 |
- pruned_mergelist = [x for x in mergelist \ |
182 |
- if isinstance(x, list) and \ |
183 |
- tuple(x) not in unsatisfied_parents] |
184 |
- |
185 |
- # It shouldn't happen, but if the size of mergelist |
186 |
- # does not decrease for some reason then the loop |
187 |
- # will be infinite. Therefore, if that case ever |
188 |
- # occurs for some reason, raise the exception to |
189 |
- # break out of the loop. |
190 |
- if not pruned_mergelist or \ |
191 |
- len(pruned_mergelist) == len(mergelist): |
192 |
- raise |
193 |
- mergelist[:] = pruned_mergelist |
194 |
- dropped_tasks.update(unsatisfied_parents) |
195 |
- del e, graph, traversed_nodes, \ |
196 |
- unsatisfied_parents, unsatisfied_stack |
197 |
- continue |
198 |
- else: |
199 |
- break |
200 |
+ success, mydepgraph, dropped_tasks = resume_depgraph( |
201 |
+ settings, trees, mtimedb, myopts, myparams, spinner, |
202 |
+ skip_masked=skip_masked, skip_unsatisfied=skip_unsatisfied) |
203 |
except (portage.exception.PackageNotFound, |
204 |
depgraph.UnsatisfiedResumeDep), e: |
205 |
+ if isinstance(e, depgraph.UnsatisfiedResumeDep): |
206 |
+ mydepgraph = e.depgraph |
207 |
if show_spinner: |
208 |
print |
209 |
from textwrap import wrap |
210 |
@@ -8644,7 +8665,8 @@ |
211 |
portage.writemsg("\n", noiselevel=-1) |
212 |
del dropped_tasks |
213 |
else: |
214 |
- mydepgraph.display_problems() |
215 |
+ if mydepgraph is not None: |
216 |
+ mydepgraph.display_problems() |
217 |
if not (ask or pretend): |
218 |
# delete the current list and also the backup |
219 |
# since it's probably stale too. |
220 |
|
221 |
-- |
222 |
gentoo-commits@l.g.o mailing list |