diff options
Diffstat (limited to 'pmstestsuite/cli.py')
-rw-r--r-- | pmstestsuite/cli.py | 57 |
1 files changed, 33 insertions, 24 deletions
diff --git a/pmstestsuite/cli.py b/pmstestsuite/cli.py index 3efd658..73468d1 100644 --- a/pmstestsuite/cli.py +++ b/pmstestsuite/cli.py @@ -1,5 +1,5 @@ # vim:fileencoding=utf-8 -# (c) 2011 Michał Górny <mgorny@gentoo.org> +# (c) 2011-2012 Michał Górny <mgorny@gentoo.org> # Released under the terms of the 2-clause BSD license. from __future__ import print_function @@ -156,26 +156,31 @@ class PMSTestSuiteCLI(object): except (EnvironmentError, KeyError, ValueError) as e: opt.error('Repository open failed: %s' % e) - dbus_hdlr = DBusHandler() + dbus_uid = pm.config.userpriv_uid if pm.config.userpriv_enabled \ + else None + self.dbus_hdlr = DBusHandler(uid = dbus_uid) try: - self.test_library = load_library(opts.library_name, - thorough = opts.thorough, undefined = opts.undefined, - dbus_hdlr = dbus_hdlr) - except (ImportError, TypeError) as e: - opt.error('Test library load failed: %s' % e) - - for pm in self.pms: - pm.package_limit = opts.limit_pkgs - self.create_repo_only = opts.create_repo_only - self.update_manifests = not opts.no_manifests - self.verbose = opts.verbose - - limit_tests = set() - for t in opts.tests: - limit_tests.update(t.split()) - if limit_tests: - self.test_library.limit_tests(limit_tests) + try: + self.test_library = load_library(opts.library_name, + thorough = opts.thorough, undefined = opts.undefined, + dbus_hdlr = self.dbus_hdlr) + except (ImportError, TypeError) as e: + opt.error('Test library load failed: %s' % e) + + for pm in self.pms: + pm.package_limit = opts.limit_pkgs + self.create_repo_only = opts.create_repo_only + self.update_manifests = not opts.no_manifests + self.verbose = opts.verbose + + limit_tests = set() + for t in opts.tests: + limit_tests.update(t.split()) + if limit_tests: + self.test_library.limit_tests(limit_tests) + except Exception: + dbus_hdlr.terminate() def _print_stage(self, text): print('-> [%s] %s...' % (self.pm.name, text)) @@ -288,10 +293,14 @@ class PMSTestSuiteCLI(object): def main(self, argv): self._start(*argv) - gobject.idle_add(self.generate_and_start) - - self.ret = 1 - self.loop = gobject.MainLoop() - self.loop.run() + try: + gobject.idle_add(self.generate_and_start) + + self.ret = 1 + self.loop = gobject.MainLoop() + self.loop.run() + finally: + # Ensure to terminate the spawned D-Bus. + self.dbus_hdlr.terminate() return self.ret |