2
# This file is part of Checkbox.
4
# Copyright 2009 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/>.
19
from checkbox.job import UNSUPPORTED
20
from checkbox.plugin import Plugin
21
from checkbox.resource import ResourceMap
24
class ResourceInfo(Plugin):
26
def register(self, manager):
27
super(ResourceInfo, self).register(manager)
29
self.resources = ResourceMap()
31
self._manager.reactor.call_on("report-resource", self.report_resource)
32
self._manager.reactor.call_on("prompt-job", self.prompt_job, -10)
34
def prompt_job(self, interface, job):
37
failed_requirements = []
39
for require in job.get("requires", []):
40
new_values = self.resources.eval(require)
41
mask.append(bool(new_values))
43
if not bool(new_values):
44
failed_requirements.append(require)
46
if new_values is not None:
47
values.extend(new_values)
50
job["resources"] = values
53
job["status"] = UNSUPPORTED
55
data = "Job requirement%s not met:" % (
56
's' if len(failed_requirements) > 1 else '')
58
for failed_require in failed_requirements:
59
data += " '" + failed_require + "'"
62
self._manager.reactor.stop()
64
def report_resource(self, resource):
65
# Register temporary handler for report-messages events
66
def report_messages(messages):
67
self.resources[resource["name"]] = messages
68
self._manager.reactor.fire("report-%s" % resource["name"], messages)
70
# Don't report other messages
71
self._manager.reactor.stop()
73
event_id = self._manager.reactor.call_on("report-messages", report_messages, -100)
74
self._manager.reactor.fire("message-exec", resource)
75
self._manager.reactor.cancel_call(event_id)
78
factory = ResourceInfo