~jocave/checkbox/hybrid-amd-gpu-mods

« back to all changes in this revision

Viewing changes to checkbox-old/plugins/resource_info.py

  • Committer: Zygmunt Krynicki
  • Date: 2013-05-29 07:50:30 UTC
  • mto: This revision was merged to the branch mainline in revision 2153.
  • Revision ID: zygmunt.krynicki@canonical.com-20130529075030-ngwz245hs2u3y6us
checkbox: move current checkbox code into checkbox-old

This patch cleans up the top-level directory of the project into dedicated
sub-project directories. One for checkbox-old (the current checkbox and all the
associated stuff), one for plainbox and another for checkbox-ng.

There are some associated changes, such as updating the 'source' mode of
checkbox provider in plainbox, and fixing paths in various test scripts that we
have.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# This file is part of Checkbox.
 
3
#
 
4
# Copyright 2009 Canonical Ltd.
 
5
#
 
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.
 
10
#
 
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.
 
15
#
 
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/>.
 
18
#
 
19
from checkbox.job import UNSUPPORTED
 
20
from checkbox.plugin import Plugin
 
21
from checkbox.resource import ResourceMap
 
22
 
 
23
 
 
24
class ResourceInfo(Plugin):
 
25
 
 
26
    def register(self, manager):
 
27
        super(ResourceInfo, self).register(manager)
 
28
 
 
29
        self.resources = ResourceMap()
 
30
 
 
31
        self._manager.reactor.call_on("report-resource", self.report_resource)
 
32
        self._manager.reactor.call_on("prompt-job", self.prompt_job, -10)
 
33
 
 
34
    def prompt_job(self, interface, job):
 
35
        mask = []
 
36
        values = []
 
37
        failed_requirements = []
 
38
 
 
39
        for require in job.get("requires", []):
 
40
            new_values = self.resources.eval(require)
 
41
            mask.append(bool(new_values))
 
42
 
 
43
            if not bool(new_values):
 
44
                failed_requirements.append(require)
 
45
 
 
46
            if new_values is not None:
 
47
                values.extend(new_values)
 
48
 
 
49
        if all(mask):
 
50
            job["resources"] = values
 
51
 
 
52
        else:
 
53
            job["status"] = UNSUPPORTED
 
54
 
 
55
            data = "Job requirement%s not met:" % (
 
56
                's' if len(failed_requirements) > 1 else '')
 
57
            
 
58
            for failed_require in failed_requirements:
 
59
                data += " '" + failed_require + "'"
 
60
                
 
61
            job["data"] = data
 
62
            self._manager.reactor.stop()
 
63
 
 
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)
 
69
 
 
70
            # Don't report other messages
 
71
            self._manager.reactor.stop()
 
72
 
 
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)
 
76
 
 
77
 
 
78
factory = ResourceInfo