-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
pb.py
132 lines (111 loc) · 5.48 KB
/
pb.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
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
# This file is part of Buildbot. Buildbot 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, version 2.
#
# This program 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
# this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright Buildbot Team Members
from twisted.python import log
from twisted.internet import defer
from buildbot.pbutil import NewCredPerspective
from buildbot.changes import base, changes
class ChangePerspective(NewCredPerspective):
def __init__(self, changemaster, prefix):
self.changemaster = changemaster
self.prefix = prefix
def attached(self, mind):
return self
def detached(self, mind):
pass
def perspective_addChange(self, changedict):
log.msg("perspective_addChange called")
pathnames = []
for path in changedict['files']:
if self.prefix:
if not path.startswith(self.prefix):
# this file does not start with the prefix, so ignore it
continue
path = path[len(self.prefix):]
pathnames.append(path)
if pathnames:
change = changes.Change(who=changedict['who'],
files=pathnames,
comments=changedict['comments'],
branch=changedict.get('branch'),
revision=changedict.get('revision'),
revlink=changedict.get('revlink', ''),
category=changedict.get('category'),
when=changedict.get('when'),
properties=changedict.get('properties', {}),
repository=changedict.get('repository', '') or '',
project=changedict.get('project', '') or '',
)
self.changemaster.addChange(change)
class PBChangeSource(base.ChangeSource):
compare_attrs = ["user", "passwd", "port", "prefix", "port"]
def __init__(self, user="change", passwd="changepw", port=None,
prefix=None, sep=None):
"""I listen on a TCP port for Changes from 'buildbot sendchange'.
I am a ChangeSource which will accept Changes from a remote source. I
share a TCP listening port with the buildslaves.
The 'buildbot sendchange' command, the contrib/svn_buildbot.py tool,
and the contrib/bzr_buildbot.py tool know how to send changes to me.
@type prefix: string (or None)
@param prefix: if set, I will ignore any filenames that do not start
with this string. Moreover I will remove this string
from all filenames before creating the Change object
and delivering it to the Schedulers. This is useful
for changes coming from version control systems that
represent branches as parent directories within the
repository (like SVN and Perforce). Use a prefix of
'trunk/' or 'project/branches/foobranch/' to only
follow one branch and to get correct tree-relative
filenames.
@param sep: DEPRECATED (with an axe). sep= was removed in
buildbot-0.7.4 . Instead of using it, you should use
prefix= with a trailing directory separator. This
docstring (and the better-than-nothing error message
which occurs when you use it) will be removed in 0.7.5 .
@param port: strport to use, or None to use the master's slavePortnum
"""
# sep= was removed in 0.7.4 . This more-helpful-than-nothing error
# message will be removed in 0.7.5 .
assert sep is None, "prefix= is now a complete string, do not use sep="
self.user = user
self.passwd = passwd
self.port = port
self.prefix = prefix
self.registration = None
def describe(self):
# TODO: when the dispatcher is fixed, report the specific port
#d = "PB listener on port %d" % self.port
d = "PBChangeSource listener on all-purpose slaveport"
if self.prefix is not None:
d += " (prefix '%s')" % self.prefix
return d
def startService(self):
base.ChangeSource.startService(self)
master = self.parent.parent
port = self.port
if not port:
port = master.slavePortnum
self.registration = master.pbmanager.register(
port, self.user, self.passwd,
self.getPerspective)
def stopService(self):
d = defer.maybeDeferred(base.ChangeSource.stopService, self)
def unreg(_):
if self.registration:
return self.registration.unregister()
d.addCallback(unreg)
return d
def getPerspective(self, mind, username):
assert username == self.user
return ChangePerspective(self.parent, self.prefix)