(closes #182) Add category support to Schedulers and Changes.
[buildbot.git] / buildbot / changes / pb.py
blob91a1a22e2ee1daa93b5376fe24a39633b26c5622
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'),
39 self.changemaster.addChange(change)
41 class PBChangeSource(base.ChangeSource):
42 compare_attrs = ["user", "passwd", "port", "prefix"]
44 def __init__(self, user="change", passwd="changepw", port=None,
45 prefix=None, sep=None):
46 """I listen on a TCP port for Changes from 'buildbot sendchange'.
48 I am a ChangeSource which will accept Changes from a remote source. I
49 share a TCP listening port with the buildslaves.
51 The 'buildbot sendchange' command, the contrib/svn_buildbot.py tool,
52 and the contrib/bzr_buildbot.py tool know how to send changes to me.
54 @type prefix: string (or None)
55 @param prefix: if set, I will ignore any filenames that do not start
56 with this string. Moreover I will remove this string
57 from all filenames before creating the Change object
58 and delivering it to the Schedulers. This is useful
59 for changes coming from version control systems that
60 represent branches as parent directories within the
61 repository (like SVN and Perforce). Use a prefix of
62 'trunk/' or 'project/branches/foobranch/' to only
63 follow one branch and to get correct tree-relative
64 filenames.
66 @param sep: DEPRECATED (with an axe). sep= was removed in
67 buildbot-0.7.4 . Instead of using it, you should use
68 prefix= with a trailing directory separator. This
69 docstring (and the better-than-nothing error message
70 which occurs when you use it) will be removed in 0.7.5 .
71 """
73 # sep= was removed in 0.7.4 . This more-helpful-than-nothing error
74 # message will be removed in 0.7.5 .
75 assert sep is None, "prefix= is now a complete string, do not use sep="
76 # TODO: current limitations
77 assert user == "change"
78 assert passwd == "changepw"
79 assert port == None
80 self.user = user
81 self.passwd = passwd
82 self.port = port
83 self.prefix = prefix
85 def describe(self):
86 # TODO: when the dispatcher is fixed, report the specific port
87 #d = "PB listener on port %d" % self.port
88 d = "PBChangeSource listener on all-purpose slaveport"
89 if self.prefix is not None:
90 d += " (prefix '%s')" % self.prefix
91 return d
93 def startService(self):
94 base.ChangeSource.startService(self)
95 # our parent is the ChangeMaster object
96 # find the master's Dispatch object and register our username
97 # TODO: the passwd should be registered here too
98 master = self.parent.parent
99 master.dispatcher.register(self.user, self)
101 def stopService(self):
102 base.ChangeSource.stopService(self)
103 # unregister our username
104 master = self.parent.parent
105 master.dispatcher.unregister(self.user)
107 def getPerspective(self):
108 return ChangePerspective(self.parent, self.prefix)