diff options
author | Michał Górny <mgorny@gentoo.org> | 2012-01-03 12:57:44 +0100 |
---|---|---|
committer | Michał Górny <mgorny@gentoo.org> | 2012-01-03 12:58:47 +0100 |
commit | 100cd1471544a89e330625e4eaf6ba41aa5c3993 (patch) | |
tree | ab9c6bfcedd8ef9adf0222f4ab80881da01b0af3 /pmstestsuite | |
parent | Use subprocess to spawn D-Bus. (diff) | |
download | pms-test-suite-100cd1471544a89e330625e4eaf6ba41aa5c3993.tar.gz pms-test-suite-100cd1471544a89e330625e4eaf6ba41aa5c3993.tar.bz2 pms-test-suite-100cd1471544a89e330625e4eaf6ba41aa5c3993.zip |
Add exception handling within main loop callbacks.
Diffstat (limited to 'pmstestsuite')
-rw-r--r-- | pmstestsuite/cli.py | 170 |
1 files changed, 96 insertions, 74 deletions
diff --git a/pmstestsuite/cli.py b/pmstestsuite/cli.py index 73468d1..ac8dd2e 100644 --- a/pmstestsuite/cli.py +++ b/pmstestsuite/cli.py @@ -7,6 +7,7 @@ from __future__ import print_function import os, os.path, shlex import gobject +from traceback import format_exc from optparse import OptionParser from . import PV @@ -186,31 +187,35 @@ class PMSTestSuiteCLI(object): print('-> [%s] %s...' % (self.pm.name, text)) def tests_done(self): - self.pm.reload_config() - self._print_stage('Checking test results') - results = {} - for t in self.test_library: - tr = TestResult(t, self.pm) + try: + self.pm.reload_config() + self._print_stage('Checking test results') + results = {} + for t in self.test_library: + tr = TestResult(t, self.pm) - if tr: - outc = '.' - elif tr.exception: - outc = 'E' - raise tr.exception - else: - outc = 'F' - print(outc, end='') + if tr: + outc = '.' + elif tr.exception: + outc = 'E' + raise tr.exception + else: + outc = 'F' + print(outc, end='') - results[t] = tr - t.clean(self.pm) - self.results[self.pm] = results - print('') + results[t] = tr + t.clean(self.pm) + self.results[self.pm] = results + print('') - if self.pm.has_pending_actions: - self._print_stage('Unmerging test ebuilds') - self.pm.commit(self.prepare) - else: - self.prepare() + if self.pm.has_pending_actions: + self._print_stage('Unmerging test ebuilds') + self.pm.commit(self.prepare) + else: + self.prepare() + except Exception as e: + self.exception = format_exc() + self.loop.quit() def all_done(self): ret = self.output(self.results, verbose = self.verbose) @@ -225,73 +230,87 @@ class PMSTestSuiteCLI(object): self.pm.commit(self.tests_done) def pre_unmerge_done(self): - self.pm.reload_config() - for t in self.test_library: - t.clean(self.pm) - if self.pm.has_pending_actions: - print('Failed to unmerge the following test ebuilds:') - print(' '.join(self.pm.pkg_queue)) - print('Refusing to proceed.') - self.loop.quit() - return - self.start_pm() - - def prepare(self, first = False): try: - self.pm = next(self.pm_iter) - except StopIteration: - self.all_done() - else: - if not first: - self.pm.reload_config() + self.pm.reload_config() for t in self.test_library: t.clean(self.pm) - if self.pm.has_pending_actions: - print('-> Unmerging already-merged test ebuilds...') - self.pm.commit(self.pre_unmerge_done) + print('Failed to unmerge the following test ebuilds:') + print(' '.join(self.pm.pkg_queue)) + print('Refusing to proceed.') + self.loop.quit() + return + self.start_pm() + except Exception as e: + self.exception = format_exc() + self.loop.quit() + + def prepare(self, first = False): + try: + try: + self.pm = next(self.pm_iter) + except StopIteration: + self.all_done() else: - self.start_pm() + if not first: + self.pm.reload_config() + for t in self.test_library: + t.clean(self.pm) + + if self.pm.has_pending_actions: + print('-> Unmerging already-merged test ebuilds...') + self.pm.commit(self.pre_unmerge_done) + else: + self.start_pm() + except Exception as e: + self.exception = format_exc() + self.loop.quit() def generate_and_start(self): - print('-> Generating ebuilds...') - files = {} - for t in self.test_library: - files.update(t.get_output_files()) - if len(self.test_library) == 0: - print('No tests found (?!), refusing to proceed.') - return 1 + try: + print('-> Generating ebuilds...') + files = {} + for t in self.test_library: + files.update(t.get_output_files()) + if len(self.test_library) == 0: + print('No tests found (?!), refusing to proceed.') + return 1 - files.update(get_common_eclass_files()) - files.update(self.test_library.get_common_files()) + files.update(get_common_eclass_files()) + files.update(self.test_library.get_common_files()) - self.repository.write_files(files) - if self.update_manifests: - needs_manifests = False - for pm in self.pms: - needs_manifests |= pm.requires_manifests - try: - self.repository.remanifest(files, pm) - except NotImplementedError: - pass + self.repository.write_files(files) + if self.update_manifests: + needs_manifests = False + for pm in self.pms: + needs_manifests |= pm.requires_manifests + try: + self.repository.remanifest(files, pm) + except NotImplementedError: + pass + else: + break else: - break - else: - if needs_manifests: - print('No PM was able to do the Manifests, failing.') - return 1 - - if self.create_repo_only: - return 0 - - self.pm_iter = iter(self.pms) - self.results = {} - self.prepare(first = True) + if needs_manifests: + print('No PM was able to do the Manifests, failing.') + return 1 + + if self.create_repo_only: + return 0 + + self.pm_iter = iter(self.pms) + self.results = {} + self.prepare(first = True) + except Exception as e: + self.exception = format_exc() + self.loop.quit() return False + def main(self, argv): self._start(*argv) + self.exception = None try: gobject.idle_add(self.generate_and_start) @@ -303,4 +322,7 @@ class PMSTestSuiteCLI(object): # Ensure to terminate the spawned D-Bus. self.dbus_hdlr.terminate() + if self.exception is not None: + return self.exception + return self.ret |