~roadmr/ubuntu/oneiric/checkbox/fix-662322-in-0.12.9

« back to all changes in this revision

Viewing changes to plugins/message_info.py

  • Committer: Bazaar Package Importer
  • Author(s): Marc Tardif, Gabor Keleman
  • Date: 2009-08-19 15:36:05 UTC
  • Revision ID: james.westby@ubuntu.com-20090819153605-weo6htup3yi6zn0t
Tags: 0.8~alpha4
* New upstream version:
  * Changed icon.
  * Added timeout property to lock_prompt plugin.
  * Added concept of attachments to tests.
  * Added support for backslahes in templates to wrap lines.
  * Added support blacklisting and whitelisting both tests and suites.
  * Introduced the concept of jobs for suites, tests and attachments.
  * Removed upstart event which is no longer needed.
  * Replaced architecture and category with requires in test definitions.
* Fixed pygst dependency (LP: #334442)
* Fixed configuration file updates during install (LP: #330596)
* Fixed and expanded translations (LP: #347038)
* Fixed ignored system proxy settings (LP: #345548)
* Fixed parsing blank lines in templates (LP: #393907)
* Fixed escaping of lists (LP: #394001)
* Fixed timeout in manual tests (LP: #377986)
* Fixed CLI interface dialog.
* Fixed support for FreeDesktop XDG base directory specification (LP: #363549)
* Added general and package specific apport hooks

[ Gabor Keleman ]
* Fixed untranslated strings in tests (LP: #374666)
* Fixed untranslated last screen (LP: #374646)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# This file is part of Checkbox.
 
3
#
 
4
# Copyright 2008 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
import re
 
20
import posixpath
 
21
from StringIO import StringIO
 
22
 
 
23
from checkbox.lib.path import path_expand_recursive
 
24
from checkbox.lib.template_i18n import TemplateI18n
 
25
 
 
26
from checkbox.job import Job, PASS
 
27
from checkbox.plugin import Plugin
 
28
from checkbox.arguments import coerce_arguments
 
29
from checkbox.properties import Float, Int, List, Map, String, Unicode
 
30
 
 
31
 
 
32
message_schema = Map({
 
33
    "plugin": String(),
 
34
    "name": String(),
 
35
    "status": String(required=False),
 
36
    "suite": String(required=False),
 
37
    "description": Unicode(required=False),
 
38
    "command": String(required=False),
 
39
    "depends": List(String(), required=False),
 
40
    "duration": Float(required=False),
 
41
    "environ": List(String(), required=False),
 
42
    "requires": List(String(), separator=r"\n", required=False),
 
43
    "timeout": Int(required=False),
 
44
    "user": String(required=False)})
 
45
 
 
46
 
 
47
class MessageInfo(Plugin):
 
48
 
 
49
    def register(self, manager):
 
50
        super(MessageInfo, self).register(manager)
 
51
 
 
52
        for (rt, rh) in [
 
53
             ("message", self.message),
 
54
             ("messages", self.messages),
 
55
             ("message-command", self.message_command),
 
56
             ("message-directory", self.message_directory),
 
57
             ("message-exec", self.message_exec),
 
58
             ("message-file", self.message_file),
 
59
             ("message-filename", self.message_filename),
 
60
             ("message-job", self.message_job),
 
61
             ("message-string", self.message_string)]:
 
62
            self._manager.reactor.call_on(rt, rh)
 
63
 
 
64
    @coerce_arguments(message=message_schema)
 
65
    def message(self, message):
 
66
        self._manager.reactor.fire("report-%s" % message["plugin"], message)
 
67
 
 
68
    def messages(self, messages):
 
69
        for message in messages:
 
70
            self._manager.reactor.fire("message", message)
 
71
 
 
72
    def message_command(self, command, environ=[], timeout=None):
 
73
        job = Job(command, environ, timeout)
 
74
        self._manager.reactor.fire("message-job", job)
 
75
 
 
76
    def message_directory(self, directory, blacklist=[], whitelist=[]):
 
77
        whitelist_patterns = [re.compile(r"^%s$" % r) for r in whitelist if r]
 
78
        blacklist_patterns = [re.compile(r"^%s$" % r) for r in blacklist if r]
 
79
 
 
80
        filenames = []
 
81
        for filename in path_expand_recursive(directory):
 
82
            name = posixpath.basename(filename)
 
83
            if name.startswith(".") or name.endswith("~"):
 
84
                continue
 
85
 
 
86
            if whitelist_patterns:
 
87
                if not [name for p in whitelist_patterns if p.match(name)]:
 
88
                    continue
 
89
            elif blacklist_patterns:
 
90
                if [name for p in blacklist_patterns if p.match(name)]:
 
91
                    continue
 
92
 
 
93
            self._manager.reactor.fire("message-filename", filename)
 
94
 
 
95
    def message_exec(self, message):
 
96
        self._manager.reactor.fire("message-command", message["command"],
 
97
            message.get("environ"), message.get("timeout"))
 
98
 
 
99
    def message_file(self, file, filename="<stream>"):
 
100
        template = TemplateI18n()
 
101
        messages = template.load_file(file, filename)
 
102
        for message in messages:
 
103
            long_ext = "_extended"
 
104
            for long_key in message.keys():
 
105
                if long_key.endswith(long_ext):
 
106
                    short_key = long_key.replace(long_ext, "")
 
107
                    message[short_key] = message.pop(long_key)
 
108
 
 
109
        self._manager.reactor.fire("messages", messages)
 
110
 
 
111
    def message_filename(self, filename):
 
112
        file = open(filename, "r")
 
113
        self._manager.reactor.fire("message-file", file, filename)
 
114
 
 
115
    def message_job(self, job):
 
116
        job.execute()
 
117
        if job.status == PASS:
 
118
            self._manager.reactor.fire("message-string", job.data)
 
119
 
 
120
    def message_string(self, string):
 
121
        file = StringIO(string)
 
122
        self._manager.reactor.fire("message-file", file)
 
123
 
 
124
 
 
125
factory = MessageInfo