test_p4poller.py: update test to match ignore-failures change in #135
[buildbot.git] / contrib / fakechange.py
blobbc19f9e601776b61043451fc64164230d4e2a699
1 #! /usr/bin/python
3 """
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
10 pushing.
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
19 source tree.
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).
31 """
33 import sys
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
40 def done(*args):
41 reactor.stop()
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')
48 def makeFilename():
49 d = random.choice(dirs)
50 if d in ('src', 'tests'):
51 f = random.choice(sources)
52 else:
53 f = random.choice(docs)
54 return os.path.join(d, f)
57 def send_change(remote):
58 who = random.choice(users)
59 if len(sys.argv) > 1:
60 files = sys.argv[1:]
61 else:
62 files = [makeFilename()]
63 comments = commands.getoutput("fortune")
64 change = {'who': who, 'files': files, 'comments': comments}
65 d = remote.callRemote('addChange', change)
66 d.addCallback(done)
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)
76 reactor.run()