NEWS: fix minor typo
[buildbot.git] / contrib / arch_buildbot.py
blob2b9ab822ff0252af92ce54232cc8467a5afc001c
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, commands, cStringIO
14 from buildbot.scripts import runner
16 # Just modify the appropriate values below and then put this file in two
17 # places: ~/.arch-params/hooks/ARCHIVE/=precommit/90buildbot.py and
18 # ~/.arch-params/hooks/ARCHIVE/=commit/10buildbot.py
20 master = "localhost:9989"
21 username = "myloginname"
23 # Remember that for this to work, your buildmaster's master.cfg needs to have
24 # a c['sources'] list which includes a pb.PBChangeSource instance.
26 os.chdir(os.getenv("ARCH_TREE_ROOT"))
27 filelist = ",,bb-files"
28 commentfile = ",,bb-comments"
30 if os.getenv("ARCH_HOOK_ACTION") == "precommit":
31 files = []
32 out = commands.getoutput("tla changes")
33 for line in cStringIO.StringIO(out).readlines():
34 if line[0] in "AMD": # add, modify, delete
35 files.append(line[3:])
36 if files:
37 f = open(filelist, "w")
38 f.write("".join(files))
39 f.close()
40 # comments
41 logfiles = [f for f in os.listdir(".") if f.startswith("++log.")]
42 if len(logfiles) > 1:
43 print ("Warning, multiple ++log.* files found, getting comments "
44 "from the first one")
45 if logfiles:
46 open(commentfile, "w").write(open(logfiles[0], "r").read())
48 elif os.getenv("ARCH_HOOK_ACTION") == "commit":
49 revision = os.getenv("ARCH_REVISION")
51 files = []
52 if os.path.exists(filelist):
53 f = open(filelist, "r")
54 for line in f.readlines():
55 files.append(line.rstrip())
56 if not files:
57 # buildbot insists upon having at least one modified file (otherwise
58 # the prefix-stripping mechanism will ignore the change)
59 files = ["dummy"]
61 if os.path.exists(commentfile):
62 comments = open(commentfile, "r").read()
63 else:
64 comments = "commit from arch"
66 c = {'master': master, 'username': username,
67 'revision': revision, 'comments': comments, 'files': files}
68 runner.sendchange(c, True)
70 if os.path.exists(filelist):
71 os.unlink(filelist)
72 if os.path.exists(commentfile):
73 os.unlink(commentfile)