(refs #35) fix dependent scheduler re-checking: make calculation of upstream lazier
[buildbot.git] / buildbot / changes / pb.py
blobf72115967403d124a67315d36d5b7a2955d57323
1 # -*- test-case-name: buildbot.test.test_changes -*-
3 from twisted.python import log
5 from buildbot.pbutil import NewCredPerspective
6 from buildbot.changes import base, changes
8 class ChangePerspective(NewCredPerspective):
10 def __init__(self, changemaster, prefix):
11 self.changemaster = changemaster
12 self.prefix = prefix
14 def attached(self, mind):
15 return self
16 def detached(self, mind):
17 pass
19 def perspective_addChange(self, changedict):
20 log.msg("perspective_addChange called")
21 pathnames = []
22 prefixpaths = None
23 for path in changedict['files']:
24 if self.prefix:
25 if not path.startswith(self.prefix):
26 # this file does not start with the prefix, so ignore it
27 continue
28 path = path[len(self.prefix):]
29 pathnames.append(path)
31 if pathnames:
32 change = changes.Change(changedict['who'],
33 pathnames,
34 changedict['comments'],
35 branch=changedict.get('branch'),
36 revision=changedict.get('revision'),
37 category=changedict.get('category'),
38 when=changedict.get('when'),
40 self.changemaster.addChange(change)
42 class PBChangeSource(base.ChangeSource):
43 compare_attrs = ["user", "passwd", "port", "prefix"]
45 def __init__(self, user="change", passwd="changepw", port=None,
46 prefix=None, sep=None):
47 """I listen on a TCP port for Changes from 'buildbot sendchange'.
49 I am a ChangeSource which will accept Changes from a remote source. I
50 share a TCP listening port with the buildslaves.
52 The 'buildbot sendchange' command, the contrib/svn_buildbot.py tool,
53 and the contrib/bzr_buildbot.py tool know how to send changes to me.
55 @type prefix: string (or None)
56 @param prefix: if set, I will ignore any filenames that do not start
57 with this string. Moreover I will remove this string
58 from all filenames before creating the Change object
59 and delivering it to the Schedulers. This is useful
60 for changes coming from version control systems that
61 represent branches as parent directories within the
62 repository (like SVN and Perforce). Use a prefix of
63 'trunk/' or 'project/branches/foobranch/' to only
64 follow one branch and to get correct tree-relative
65 filenames.
67 @param sep: DEPRECATED (with an axe). sep= was removed in
68 buildbot-0.7.4 . Instead of using it, you should use
69 prefix= with a trailing directory separator. This
70 docstring (and the better-than-nothing error message
71 which occurs when you use it) will be removed in 0.7.5 .
72 """
74 # sep= was removed in 0.7.4 . This more-helpful-than-nothing error
75 # message will be removed in 0.7.5 .
76 assert sep is None, "prefix= is now a complete string, do not use sep="
77 # TODO: current limitations
78 assert user == "change"
79 assert passwd == "changepw"
80 assert port == None
81 self.user = user
82 self.passwd = passwd
83 self.port = port
84 self.prefix = prefix
86 def describe(self):
87 # TODO: when the dispatcher is fixed, report the specific port
88 #d = "PB listener on port %d" % self.port
89 d = "PBChangeSource listener on all-purpose slaveport"
90 if self.prefix is not None:
91 d += " (prefix '%s')" % self.prefix
92 return d
94 def startService(self):
95 base.ChangeSource.startService(self)
96 # our parent is the ChangeMaster object
97 # find the master's Dispatch object and register our username
98 # TODO: the passwd should be registered here too
99 master = self.parent.parent
100 master.dispatcher.register(self.user, self)
102 def stopService(self):
103 base.ChangeSource.stopService(self)
104 # unregister our username
105 master = self.parent.parent
106 master.dispatcher.unregister(self.user)
108 def getPerspective(self):
109 return ChangePerspective(self.parent, self.prefix)