This repository has been archived by the owner on Jun 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
queued_command.py
67 lines (53 loc) · 2.26 KB
/
queued_command.py
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
import os
from twisted.python import log as twlog
from buildbot.status import base
from buildbot.util import json
class QueuedCommandHandler(base.StatusReceiverMultiService):
"""
Runs a command when a build finishes
"""
compare_attrs = ['command', 'categories', 'builders']
def __init__(self, command, queuedir, categories=None, builders=None):
base.StatusReceiverMultiService.__init__(self)
self.command = command
self.queuedir = queuedir
self.categories = categories
self.builders = builders
# you should either limit on builders or categories, not both
if self.builders != None and self.categories != None:
twlog.err("Please specify only builders to ignore or categories to include")
raise ValueError("Please specify only builders or categories")
self.watched = []
def startService(self):
base.StatusReceiverMultiService.startService(self)
self.master_status = self.parent.getStatus()
self.master_status.subscribe(self)
def stopService(self):
self.master_status.unsubscribe(self)
for w in self.watched:
w.unsubscribe(self)
base.StatusReceiverMultiService.stopService(self)
def builderAdded(self, name, builder):
# only subscribe to builders we are interested in
if self.categories != None and builder.category not in self.categories:
return None
self.watched.append(builder)
return self # subscribe to this builder
def buildStarted(self, builderName, build):
pass
def buildFinished(self, builderName, build, results):
builder = build.getBuilder()
if self.builders is not None and builderName not in self.builders:
return # ignore this build
if self.categories is not None and \
builder.category not in self.categories:
return # ignore this build
if isinstance(self.command, str):
cmd = [self.command]
else:
cmd = self.command[:]
cmd = build.getProperties().render(cmd)
cmd.extend([
os.path.join(self.master_status.basedir, builder.basedir),
str(build.number)])
self.queuedir.add(json.dumps(cmd))