1 |
commit: 100cd1471544a89e330625e4eaf6ba41aa5c3993 |
2 |
Author: Michał Górny <mgorny <AT> gentoo <DOT> org> |
3 |
AuthorDate: Tue Jan 3 11:57:44 2012 +0000 |
4 |
Commit: Michał Górny <mgorny <AT> gentoo <DOT> org> |
5 |
CommitDate: Tue Jan 3 11:58:47 2012 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/pms-test-suite.git;a=commit;h=100cd147 |
7 |
|
8 |
Add exception handling within main loop callbacks. |
9 |
|
10 |
--- |
11 |
pmstestsuite/cli.py | 170 +++++++++++++++++++++++++++++---------------------- |
12 |
1 files changed, 96 insertions(+), 74 deletions(-) |
13 |
|
14 |
diff --git a/pmstestsuite/cli.py b/pmstestsuite/cli.py |
15 |
index 73468d1..ac8dd2e 100644 |
16 |
--- a/pmstestsuite/cli.py |
17 |
+++ b/pmstestsuite/cli.py |
18 |
@@ -7,6 +7,7 @@ from __future__ import print_function |
19 |
import os, os.path, shlex |
20 |
import gobject |
21 |
|
22 |
+from traceback import format_exc |
23 |
from optparse import OptionParser |
24 |
|
25 |
from . import PV |
26 |
@@ -186,31 +187,35 @@ class PMSTestSuiteCLI(object): |
27 |
print('-> [%s] %s...' % (self.pm.name, text)) |
28 |
|
29 |
def tests_done(self): |
30 |
- self.pm.reload_config() |
31 |
- self._print_stage('Checking test results') |
32 |
- results = {} |
33 |
- for t in self.test_library: |
34 |
- tr = TestResult(t, self.pm) |
35 |
+ try: |
36 |
+ self.pm.reload_config() |
37 |
+ self._print_stage('Checking test results') |
38 |
+ results = {} |
39 |
+ for t in self.test_library: |
40 |
+ tr = TestResult(t, self.pm) |
41 |
|
42 |
- if tr: |
43 |
- outc = '.' |
44 |
- elif tr.exception: |
45 |
- outc = 'E' |
46 |
- raise tr.exception |
47 |
- else: |
48 |
- outc = 'F' |
49 |
- print(outc, end='') |
50 |
+ if tr: |
51 |
+ outc = '.' |
52 |
+ elif tr.exception: |
53 |
+ outc = 'E' |
54 |
+ raise tr.exception |
55 |
+ else: |
56 |
+ outc = 'F' |
57 |
+ print(outc, end='') |
58 |
|
59 |
- results[t] = tr |
60 |
- t.clean(self.pm) |
61 |
- self.results[self.pm] = results |
62 |
- print('') |
63 |
+ results[t] = tr |
64 |
+ t.clean(self.pm) |
65 |
+ self.results[self.pm] = results |
66 |
+ print('') |
67 |
|
68 |
- if self.pm.has_pending_actions: |
69 |
- self._print_stage('Unmerging test ebuilds') |
70 |
- self.pm.commit(self.prepare) |
71 |
- else: |
72 |
- self.prepare() |
73 |
+ if self.pm.has_pending_actions: |
74 |
+ self._print_stage('Unmerging test ebuilds') |
75 |
+ self.pm.commit(self.prepare) |
76 |
+ else: |
77 |
+ self.prepare() |
78 |
+ except Exception as e: |
79 |
+ self.exception = format_exc() |
80 |
+ self.loop.quit() |
81 |
|
82 |
def all_done(self): |
83 |
ret = self.output(self.results, verbose = self.verbose) |
84 |
@@ -225,73 +230,87 @@ class PMSTestSuiteCLI(object): |
85 |
self.pm.commit(self.tests_done) |
86 |
|
87 |
def pre_unmerge_done(self): |
88 |
- self.pm.reload_config() |
89 |
- for t in self.test_library: |
90 |
- t.clean(self.pm) |
91 |
- if self.pm.has_pending_actions: |
92 |
- print('Failed to unmerge the following test ebuilds:') |
93 |
- print(' '.join(self.pm.pkg_queue)) |
94 |
- print('Refusing to proceed.') |
95 |
- self.loop.quit() |
96 |
- return |
97 |
- self.start_pm() |
98 |
- |
99 |
- def prepare(self, first = False): |
100 |
try: |
101 |
- self.pm = next(self.pm_iter) |
102 |
- except StopIteration: |
103 |
- self.all_done() |
104 |
- else: |
105 |
- if not first: |
106 |
- self.pm.reload_config() |
107 |
+ self.pm.reload_config() |
108 |
for t in self.test_library: |
109 |
t.clean(self.pm) |
110 |
- |
111 |
if self.pm.has_pending_actions: |
112 |
- print('-> Unmerging already-merged test ebuilds...') |
113 |
- self.pm.commit(self.pre_unmerge_done) |
114 |
+ print('Failed to unmerge the following test ebuilds:') |
115 |
+ print(' '.join(self.pm.pkg_queue)) |
116 |
+ print('Refusing to proceed.') |
117 |
+ self.loop.quit() |
118 |
+ return |
119 |
+ self.start_pm() |
120 |
+ except Exception as e: |
121 |
+ self.exception = format_exc() |
122 |
+ self.loop.quit() |
123 |
+ |
124 |
+ def prepare(self, first = False): |
125 |
+ try: |
126 |
+ try: |
127 |
+ self.pm = next(self.pm_iter) |
128 |
+ except StopIteration: |
129 |
+ self.all_done() |
130 |
else: |
131 |
- self.start_pm() |
132 |
+ if not first: |
133 |
+ self.pm.reload_config() |
134 |
+ for t in self.test_library: |
135 |
+ t.clean(self.pm) |
136 |
+ |
137 |
+ if self.pm.has_pending_actions: |
138 |
+ print('-> Unmerging already-merged test ebuilds...') |
139 |
+ self.pm.commit(self.pre_unmerge_done) |
140 |
+ else: |
141 |
+ self.start_pm() |
142 |
+ except Exception as e: |
143 |
+ self.exception = format_exc() |
144 |
+ self.loop.quit() |
145 |
|
146 |
def generate_and_start(self): |
147 |
- print('-> Generating ebuilds...') |
148 |
- files = {} |
149 |
- for t in self.test_library: |
150 |
- files.update(t.get_output_files()) |
151 |
- if len(self.test_library) == 0: |
152 |
- print('No tests found (?!), refusing to proceed.') |
153 |
- return 1 |
154 |
+ try: |
155 |
+ print('-> Generating ebuilds...') |
156 |
+ files = {} |
157 |
+ for t in self.test_library: |
158 |
+ files.update(t.get_output_files()) |
159 |
+ if len(self.test_library) == 0: |
160 |
+ print('No tests found (?!), refusing to proceed.') |
161 |
+ return 1 |
162 |
|
163 |
- files.update(get_common_eclass_files()) |
164 |
- files.update(self.test_library.get_common_files()) |
165 |
+ files.update(get_common_eclass_files()) |
166 |
+ files.update(self.test_library.get_common_files()) |
167 |
|
168 |
- self.repository.write_files(files) |
169 |
- if self.update_manifests: |
170 |
- needs_manifests = False |
171 |
- for pm in self.pms: |
172 |
- needs_manifests |= pm.requires_manifests |
173 |
- try: |
174 |
- self.repository.remanifest(files, pm) |
175 |
- except NotImplementedError: |
176 |
- pass |
177 |
+ self.repository.write_files(files) |
178 |
+ if self.update_manifests: |
179 |
+ needs_manifests = False |
180 |
+ for pm in self.pms: |
181 |
+ needs_manifests |= pm.requires_manifests |
182 |
+ try: |
183 |
+ self.repository.remanifest(files, pm) |
184 |
+ except NotImplementedError: |
185 |
+ pass |
186 |
+ else: |
187 |
+ break |
188 |
else: |
189 |
- break |
190 |
- else: |
191 |
- if needs_manifests: |
192 |
- print('No PM was able to do the Manifests, failing.') |
193 |
- return 1 |
194 |
- |
195 |
- if self.create_repo_only: |
196 |
- return 0 |
197 |
- |
198 |
- self.pm_iter = iter(self.pms) |
199 |
- self.results = {} |
200 |
- self.prepare(first = True) |
201 |
+ if needs_manifests: |
202 |
+ print('No PM was able to do the Manifests, failing.') |
203 |
+ return 1 |
204 |
+ |
205 |
+ if self.create_repo_only: |
206 |
+ return 0 |
207 |
+ |
208 |
+ self.pm_iter = iter(self.pms) |
209 |
+ self.results = {} |
210 |
+ self.prepare(first = True) |
211 |
+ except Exception as e: |
212 |
+ self.exception = format_exc() |
213 |
+ self.loop.quit() |
214 |
|
215 |
return False |
216 |
|
217 |
+ |
218 |
def main(self, argv): |
219 |
self._start(*argv) |
220 |
+ self.exception = None |
221 |
|
222 |
try: |
223 |
gobject.idle_add(self.generate_and_start) |
224 |
@@ -303,4 +322,7 @@ class PMSTestSuiteCLI(object): |
225 |
# Ensure to terminate the spawned D-Bus. |
226 |
self.dbus_hdlr.terminate() |
227 |
|
228 |
+ if self.exception is not None: |
229 |
+ return self.exception |
230 |
+ |
231 |
return self.ret |