4 This is an example of how to use the remote ChangeMaster interface, which is
5 a port that allows a remote program to inject Changes into the buildmaster.
7 The buildmaster can either pull changes in from external sources (see
8 buildbot.changes.changes.ChangeMaster.addSource for an example), or those
9 changes can be pushed in from outside. This script shows how to do the
12 Changes are just dictionaries with three keys:
14 'who': a simple string with a username. Responsibility for this change will
15 be assigned to the named user (if something goes wrong with the build, they
16 will be blamed for it).
18 'files': a list of strings, each with a filename relative to the top of the
21 'comments': a (multiline) string with checkin comments.
23 Each call to .addChange injects a single Change object: each Change
24 represents multiple files, all changed by the same person, and all with the
25 same checkin comments.
27 The port that this script connects to is the same 'slavePort' that the
28 buildslaves and other debug tools use. The ChangeMaster service will only be
29 available on that port if 'change' is in the list of services passed to
30 buildbot.master.makeApp (this service is turned ON by default).
34 from twisted
.spread
import pb
35 from twisted
.cred
import credentials
36 from twisted
.internet
import reactor
37 from twisted
.python
import log
38 import commands
, random
, os
.path
43 users
= ('zaphod', 'arthur', 'trillian', 'marvin', 'sbfast')
44 dirs
= ('src', 'doc', 'tests')
45 sources
= ('foo.c', 'bar.c', 'baz.c', 'Makefile')
46 docs
= ('Makefile', 'index.html', 'manual.texinfo')
49 d
= random
.choice(dirs
)
50 if d
in ('src', 'tests'):
51 f
= random
.choice(sources
)
53 f
= random
.choice(docs
)
54 return os
.path
.join(d
, f
)
57 def send_change(remote
):
58 who
= random
.choice(users
)
62 files
= [makeFilename()]
63 comments
= commands
.getoutput("fortune")
64 change
= {'who': who
, 'files': files
, 'comments': comments
}
65 d
= remote
.callRemote('addChange', change
)
67 print "%s: %s" % (who
, " ".join(files
))
70 f
= pb
.PBClientFactory()
71 d
= f
.login(credentials
.UsernamePassword("change", "changepw"))
72 reactor
.connectTCP("localhost", 8007, f
)
73 err
= lambda f
: (log
.err(), reactor
.stop())
74 d
.addCallback(send_change
).addErrback(err
)