testcase for #35, dependent schedulers lost on reconfig; reconfigure without changes...
[buildbot.git] / contrib / arch_buildbot.py
blob99b065c972e1f7a0f24d6cace9c642be577ce433
1 #! /usr/bin/python
3 # this script is meant to run as an Arch post-commit hook (and also as a
4 # pre-commit hook), using the "arch-meta-hook" framework. See
5 # http://wiki.gnuarch.org/NdimMetaHook for details. The pre-commit hook
6 # creates a list of files (and log comments), while the post-commit hook
7 # actually notifies the buildmaster.
9 # this script doesn't handle partial commits quite right: it will tell the
10 # buildmaster that everything changed, not just the filenames you give to
11 # 'tla commit'.
13 import os
14 import commands
15 import cStringIO
17 from buildbot.scripts import runner
19 # Just modify the appropriate values below and then put this file in two
20 # places: ~/.arch-params/hooks/ARCHIVE/=precommit/90buildbot.py and
21 # ~/.arch-params/hooks/ARCHIVE/=commit/10buildbot.py
23 master = "localhost:9989"
24 username = "myloginname"
26 # Remember that for this to work, your buildmaster's master.cfg needs to have
27 # a c['sources'] list which includes a pb.PBChangeSource instance.
29 os.chdir(os.getenv("ARCH_TREE_ROOT"))
30 filelist = ",,bb-files"
31 commentfile = ",,bb-comments"
33 if os.getenv("ARCH_HOOK_ACTION") == "precommit":
34 files = []
35 out = commands.getoutput("tla changes")
36 for line in cStringIO.StringIO(out).readlines():
37 if line[0] in "AMD": # add, modify, delete
38 files.append(line[3:])
39 if files:
40 f = open(filelist, "w")
41 f.write("".join(files))
42 f.close()
43 # comments
44 logfiles = [f for f in os.listdir(".") if f.startswith("++log.")]
45 if len(logfiles) > 1:
46 print ("Warning, multiple ++log.* files found, getting comments "
47 "from the first one")
48 if logfiles:
49 open(commentfile, "w").write(open(logfiles[0], "r").read())
51 elif os.getenv("ARCH_HOOK_ACTION") == "commit":
52 revision = os.getenv("ARCH_REVISION")
54 files = []
55 if os.path.exists(filelist):
56 f = open(filelist, "r")
57 for line in f.readlines():
58 files.append(line.rstrip())
59 if not files:
60 # buildbot insists upon having at least one modified file (otherwise
61 # the prefix-stripping mechanism will ignore the change)
62 files = ["dummy"]
64 if os.path.exists(commentfile):
65 comments = open(commentfile, "r").read()
66 else:
67 comments = "commit from arch"
69 c = {'master': master, 'username': username,
70 'revision': revision, 'comments': comments, 'files': files}
71 runner.sendchange(c, True)
73 if os.path.exists(filelist):
74 os.unlink(filelist)
75 if os.path.exists(commentfile):
76 os.unlink(commentfile)