/usr/share/checkbox/plugins/suites_prompt.py is in checkbox 0.13.7.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | #
# This file is part of Checkbox.
#
# Copyright 2008 Canonical Ltd.
#
# Checkbox is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Checkbox is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Checkbox. If not, see <http://www.gnu.org/licenses/>.
#
import copy
from checkbox.contrib.persist import Persist, MemoryBackend
from checkbox.job import UNINITIATED
from checkbox.lib.resolver import Resolver
from checkbox.plugin import Plugin
from checkbox.user_interface import PREV
from gettext import gettext as _
class SuitesPrompt(Plugin):
@property
def persist(self):
if self._persist is None:
self._persist = Persist(backend=MemoryBackend())
return self._persist.root_at("suites_prompt")
def register(self, manager):
super(SuitesPrompt, self).register(manager)
self._depends = {}
self._jobs = {}
self._statuses = {}
self._persist = None
self._recover = False
for (rt, rh) in [
("begin-persist", self.begin_persist),
("begin-recover", self.begin_recover),
("report-suite", self.report_suite)]:
self._manager.reactor.call_on(rt, rh)
for (rt, rh) in [
("prompt-gather", self.prompt_gather),
("report-suite", self.report_job),
("report-test", self.report_job)]:
self._manager.reactor.call_on(rt, rh, 100)
def begin_persist(self, persist):
self._persist = persist
def begin_recover(self, recover):
self._recover = recover
if not self._recover:
self.persist.remove("default")
def report_suite(self, suite):
suite.setdefault("type", "suite")
def report_job(self, job):
if job.get("type") == "suite":
attribute = "description"
else:
attribute = "name"
if attribute in job:
self._jobs[job["name"]] = job[attribute]
if "suite" in job:
self._depends[job["name"]] = [job["suite"]]
if job.get("type") == "test":
self._statuses[job["name"]] = job["status"]
def prompt_gather(self, interface):
# Resolve dependencies
resolver = Resolver()
for key in self._jobs.iterkeys():
depends = self._depends.get(key, [])
resolver.add(key, *depends)
# Build options
options = {}
for job in resolver.get_dependents():
suboptions = options
dependencies = resolver.get_dependencies(job)
for dependency in dependencies:
value = self._statuses.get(dependency, {})
suboptions = suboptions.setdefault(self._jobs[dependency], value)
# Build defaults
defaults = self.persist.get("default")
if defaults is None:
defaults = copy.deepcopy(options)
# Get results
defaults = interface.show_tree(_("Select the suites to test"),
options, defaults)
self.persist.set("default", defaults)
# Get tests to ignore
def get_ignore_jobs(options, results):
jobs = []
if isinstance(options,dict):
for k, v in options.iteritems():
if v == UNINITIATED and k not in results:
jobs.append(k)
else:
jobs.extend(get_ignore_jobs(options[k], results.get(k, {})))
return jobs
ignore_jobs = get_ignore_jobs(options, defaults)
self._manager.reactor.fire("ignore-jobs", ignore_jobs)
factory = SuitesPrompt
|