/usr/share/checkbox/plugins/jobs_info.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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | #
# This file is part of Checkbox.
#
# Copyright 2010 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 os, sys, re
import gettext
import logging
from checkbox.arguments import coerce_arguments
from checkbox.properties import Float, Int, List, Map, Path, String, Unicode
from checkbox.plugin import Plugin
job_schema = Map({
"plugin": String(),
"name": String(),
"type": String(required=False),
"status": String(required=False),
"suite": String(required=False),
"description": Unicode(required=False),
"purpose": Unicode(required=False),
"steps": Unicode(required=False),
"info": Unicode(required=False),
"verification": Unicode(required=False),
"command": String(required=False),
"depends": List(String(), required=False),
"duration": Float(required=False),
"environ": List(String(), required=False),
"requires": List(String(), separator=r"\n", required=False),
"resources": List(String(), required=False),
"timeout": Int(required=False),
"user": String(required=False),
"data": String(required=False)})
class JobsInfo(Plugin):
# Domain for internationalization
domain = String(default="checkbox")
# Space separated list of directories where job files are stored.
directories = List(Path(),
default_factory=lambda: "%(checkbox_share)s/jobs")
# List of jobs to blacklist
blacklist = List(String(), default_factory=lambda: "")
# Path to blacklist file
blacklist_file = Path(required=False)
# List of jobs to whitelist
whitelist = List(String(), default_factory=lambda: "")
# Path to whitelist file
whitelist_file = Path(required=False)
def register(self, manager):
super(JobsInfo, self).register(manager)
self.whitelist_patterns = self.get_patterns(self.whitelist, self.whitelist_file)
self.blacklist_patterns = self.get_patterns(self.blacklist, self.blacklist_file)
self._manager.reactor.call_on("gather", self.gather)
self._manager.reactor.call_on("report-job", self.report_job, -100)
def get_patterns(self, strings, filename=None):
if filename:
try:
file = open(filename)
except IOError, e:
error_message=(gettext.gettext("Failed to open file '%s': %s") %
(filename, e.strerror))
logging.critical(error_message)
sys.stderr.write("%s\n" % error_message)
sys.exit(os.EX_NOINPUT)
else:
strings.extend([l.strip() for l in file.readlines()])
return [re.compile(r"^%s$" % s) for s in strings
if s and not s.startswith("#")]
def gather(self):
# Register temporary handler for report-message events
messages = []
def report_message(message):
if self.whitelist_patterns:
name = message["name"]
if not [name for p in self.whitelist_patterns if p.match(name)]:
return
messages.append(message)
# Set domain and message event handler
old_domain = gettext.textdomain()
gettext.textdomain(self.domain)
event_id = self._manager.reactor.call_on("report-message", report_message, 100)
for directory in self.directories:
self._manager.reactor.fire("message-directory", directory)
# Apply whitelist ordering
def cmp_function(a, b):
a_name = a["name"]
b_name = b["name"]
for pattern in self.whitelist_patterns:
if pattern.match(a_name):
a_index = self.whitelist_patterns.index(pattern)
elif pattern.match(b_name):
b_index = self.whitelist_patterns.index(pattern)
return cmp(a_index, b_index)
if self.whitelist_patterns:
messages = sorted(messages, cmp=cmp_function)
for message in messages:
self._manager.reactor.fire("report-job", message)
# Unset domain and event handler
self._manager.reactor.cancel_call(event_id)
gettext.textdomain(old_domain)
@coerce_arguments(job=job_schema)
def report_job(self, job):
# Stop if job not in whitelist or in blacklist
name = job["name"]
if self.whitelist_patterns:
if not [name for p in self.whitelist_patterns if p.match(name)]:
self._manager.reactor.stop()
elif self.blacklist_patterns:
if [name for p in self.blacklist_patterns if p.match(name)]:
self._manager.reactor.stop()
factory = JobsInfo
|