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
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":
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:])
40 f
= open(filelist
, "w")
41 f
.write("".join(files
))
44 logfiles
= [f
for f
in os
.listdir(".") if f
.startswith("++log.")]
46 print ("Warning, multiple ++log.* files found, getting comments "
49 open(commentfile
, "w").write(open(logfiles
[0], "r").read())
51 elif os
.getenv("ARCH_HOOK_ACTION") == "commit":
52 revision
= os
.getenv("ARCH_REVISION")
55 if os
.path
.exists(filelist
):
56 f
= open(filelist
, "r")
57 for line
in f
.readlines():
58 files
.append(line
.rstrip())
60 # buildbot insists upon having at least one modified file (otherwise
61 # the prefix-stripping mechanism will ignore the change)
64 if os
.path
.exists(commentfile
):
65 comments
= open(commentfile
, "r").read()
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
):
75 if os
.path
.exists(commentfile
):
76 os
.unlink(commentfile
)