2
# This file is part of Checkbox.
4
# Copyright 2008 Canonical Ltd.
6
# Checkbox is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation, either version 3 of the License, or
9
# (at your option) any later version.
11
# Checkbox is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with Checkbox. If not, see <http://www.gnu.org/licenses/>.
21
from checkbox.lib.iterator import IteratorExclude
23
from checkbox.job import JobIterator
24
from checkbox.properties import List, Path, String
25
from checkbox.plugin import Plugin
27
from gettext import gettext as _
30
class SuitesPrompt(Plugin):
32
# Plugin default for running suite types
33
plugin_default = String(default="external")
35
# Plugin priorities for running suites
36
plugin_priorities = List(String(), default_factory=lambda:"internal")
38
# Space separated list of directories where suite files are stored.
39
directories = List(Path(),
40
default_factory=lambda:"%(checkbox_share)s/suites")
42
# List of suites to blacklist
43
blacklist = List(String(), default_factory=lambda:"")
45
# List of suites to whitelist
46
whitelist = List(String(), default_factory=lambda:"")
48
def _suites_compare(self, a, b):
49
priorities = self.plugin_priorities
50
if a["plugin"] in priorities:
51
if b["plugin"] in priorities:
52
ia = priorities.index(a["plugin"])
53
ib = priorities.index(b["plugin"])
58
elif b["plugin"] in priorities:
61
return cmp(a["name"], b["name"])
63
def _suites_exclude(self, suite):
64
whitelist_patterns = [re.compile(r"^%s$" % r) for r in self.whitelist if r]
65
blacklist_patterns = [re.compile(r"^%s$" % r) for r in self.blacklist if r]
68
if whitelist_patterns:
69
if not [name for p in whitelist_patterns if p.match(name)]:
71
elif blacklist_patterns:
72
if [name for p in blacklist_patterns if p.match(name)]:
75
suites_ignore = self.persist.get("ignore", [])
76
if suite["description"] in suites_ignore:
81
def register(self, manager):
82
super(SuitesPrompt, self).register(manager)
88
("gather", self.gather),
89
("gather-persist", self.gather_persist),
90
("report-suite", self.report_suite),
91
("prompt-suite", self.prompt_suite),
92
("prompt-suites", self.prompt_suites)]:
93
self._manager.reactor.call_on(rt, rh)
95
self._manager.reactor.call_on("prompt-gather", self.prompt_gather, 100)
96
self._manager.reactor.call_on("report-(attachment|test)",
97
self.report_attachment_or_test, -100)
100
for directory in self.directories:
101
self._manager.reactor.fire("message-directory", directory)
103
def gather_persist(self, persist):
104
self.persist = persist.root_at("suites_prompt")
106
def report_attachment_or_test(self, element):
108
element.setdefault("suite", self._suite["name"])
110
def report_suite(self, suite):
112
if key not in self._suites:
113
suite.setdefault("plugin", self.plugin_default)
114
self._suites[key] = suite
115
self._iterator = JobIterator(self._suites.values(),
116
self._manager.registry, self._suites_compare)
117
self._iterator = IteratorExclude(self._iterator,
118
self._suites_exclude, self._suites_exclude)
120
for suite in self._iterator:
121
if suite == self._suite:
124
def prompt_gather(self, interface):
125
suites = self._suites.values()
127
suites_all = set([s["description"] for s in suites])
128
suites_ignore = set(self.persist.get("ignore", []))
129
suites_default = suites_all.difference(suites_ignore)
130
suites_default = set(interface.show_check(
131
_("Select the suites to test"),
132
sorted(suites_all), suites_default))
133
suites_ignore = suites_all.difference(suites_default)
134
self.persist.set("ignore", list(suites_ignore))
136
def prompt_suite(self, interface, suite):
137
self._manager.reactor.fire("prompt-%s" % suite["plugin"],
140
def prompt_suites(self, interface):
143
self._suite = self._iterator.go(interface.direction)
144
except StopIteration:
147
self._manager.reactor.fire("prompt-suite", interface, self._suite)
150
factory = SuitesPrompt