[Avida-SVN] r1286 - in extras: . svk svk/hooks
kaben at myxo.css.msu.edu
kaben at myxo.css.msu.edu
Tue Feb 13 06:03:44 PST 2007
Author: kaben
Date: 2007-02-13 09:03:44 -0500 (Tue, 13 Feb 2007)
New Revision: 1286
Added:
extras/svk/
extras/svk/hooks/
extras/svk/hooks/post-commit
extras/svk/hooks/svn_buildbot.py
Modified:
extras/
Log:
r1356 at stochastic: kaben | 2007-02-11 00:13:21 -0500
Added working "svk" commit hook to inform BuildBot of svk commit.
Property changes on: extras
___________________________________________________________________
Name: svk:merge
- 079b078a-dbed-46b9-b3da-37668d4295ca:/avida/local/extras:1355
+ 079b078a-dbed-46b9-b3da-37668d4295ca:/avida/local/extras:1356
Added: extras/svk/hooks/post-commit
===================================================================
--- extras/svk/hooks/post-commit 2007-02-13 14:03:42 UTC (rev 1285)
+++ extras/svk/hooks/post-commit 2007-02-13 14:03:44 UTC (rev 1286)
@@ -0,0 +1,54 @@
+#!/bin/sh
+
+# POST-COMMIT HOOK
+#
+# The post-commit hook is invoked after a commit. Subversion runs
+# this hook by invoking a program (script, executable, binary, etc.)
+# named 'post-commit' (for which this file is a template) with the
+# following ordered arguments:
+#
+# [1] REPOS-PATH (the path to this repository)
+# [2] REV (the number of the revision just committed)
+#
+# The default working directory for the invocation is undefined, so
+# the program should set one explicitly if it cares.
+#
+# Because the commit has already completed and cannot be undone,
+# the exit code of the hook program is ignored. The hook program
+# can use the 'svnlook' utility to help it examine the
+# newly-committed tree.
+#
+# On a Unix system, the normal procedure is to have 'post-commit'
+# invoke other programs to do the real work, though it may do the
+# work itself too.
+#
+# Note that 'post-commit' must be executable by the user(s) who will
+# invoke it (typically the user httpd runs as), and that user must
+# have filesystem-level permission to access the repository.
+#
+# On a Windows system, you should name the hook program
+# 'post-commit.bat' or 'post-commit.exe',
+# but the basic idea is the same.
+#
+# The hook program typically does not inherit the environment of
+# its parent process. For example, a common problem is for the
+# PATH environment variable to not be set to its usual value, so
+# that subprograms fail to launch unless invoked via absolute path.
+# If you're having unexpected problems with a hook program, the
+# culprit may be unusual (or missing) environment variables.
+#
+# Here is an example hook script, for a Unix /bin/sh interpreter.
+# For more examples and pre-written hooks, see those in
+# the Subversion repository at
+# http://svn.collab.net/repos/svn/trunk/tools/hook-scripts/ and
+# http://svn.collab.net/repos/svn/trunk/contrib/hook-scripts/
+
+
+REPOS="$1"
+REV="$2"
+
+#./commit-email.pl "$REPOS" "$REV" kaben.nanlohy at gmail.com
+touch ~kaben/blah
+PATH="/opt/local/bin" python ~kaben/.svk/local/hooks/svn_buildbot.py --repository "$REPOS" --revision "$REV" --bbserver localhost --bbport 9989
+
+#log-commit.py --repository "$REPOS" --revision "$REV"
Property changes on: extras/svk/hooks/post-commit
___________________________________________________________________
Name: svn:executable
+ *
Added: extras/svk/hooks/svn_buildbot.py
===================================================================
--- extras/svk/hooks/svn_buildbot.py 2007-02-13 14:03:42 UTC (rev 1285)
+++ extras/svk/hooks/svn_buildbot.py 2007-02-13 14:03:44 UTC (rev 1286)
@@ -0,0 +1,176 @@
+#!/usr/bin/env python2.3
+
+# this requires python >=2.3 for the 'sets' module.
+
+# The sets.py from python-2.3 appears to work fine under python2.2 . To
+# install this script on a host with only python2.2, copy
+# /usr/lib/python2.3/sets.py from a newer python into somewhere on your
+# PYTHONPATH, then edit the #! line above to invoke python2.2
+
+# python2.1 is right out
+
+# If you run this program as part of your SVN post-commit hooks, it will
+# deliver Change notices to a buildmaster that is running a PBChangeSource
+# instance.
+
+# edit your svn-repository/hooks/post-commit file, and add lines that look
+# like this:
+
+'''
+# set up PYTHONPATH to contain Twisted/buildbot perhaps, if not already
+# installed site-wide
+. ~/.environment
+
+/path/to/svn_buildbot.py --repository "$REPOS" --revision "$REV" --bbserver localhost --bbport 9989
+'''
+
+import commands, sys, os
+import re
+import sets
+
+# We have hackish "-d" handling here rather than in the Options
+# subclass below because a common error will be to not have twisted in
+# PYTHONPATH; we want to be able to print that error to the log if
+# debug mode is on, so we set it up before the imports.
+
+DEBUG = None
+
+if '-d' in sys.argv:
+ i = sys.argv.index('-d')
+ DEBUG = sys.argv[i+1]
+ del sys.argv[i]
+ del sys.argv[i]
+
+if DEBUG:
+ f = open(DEBUG, 'a')
+ sys.stderr = f
+ sys.stdout = f
+
+from twisted.internet import reactor
+from twisted.python import usage
+from twisted.spread import pb
+from twisted.cred import credentials
+
+class Options(usage.Options):
+ optParameters = [
+ ['repository', 'r', None,
+ "The repository that was changed."],
+ ['revision', 'v', None,
+ "The revision that we want to examine (default: latest)"],
+ ['bbserver', 's', 'localhost',
+ "The hostname of the server that buildbot is running on"],
+ ['bbport', 'p', 8007,
+ "The port that buildbot is listening on"],
+ ['include', 'f', None,
+ '''\
+Search the list of changed files for this regular expression, and if there is
+at least one match notify buildbot; otherwise buildbot will not do a build.
+You may provide more than one -f argument to try multiple
+patterns. If no filter is given, buildbot will always be notified.'''],
+ ['filter', 'f', None, "Same as --include. (Deprecated)"],
+ ['exclude', 'F', None,
+ '''\
+The inverse of --filter. Changed files matching this expression will never
+be considered for a build.
+You may provide more than one -F argument to try multiple
+patterns. Excludes override includes, that is, patterns that match both an
+include and an exclude will be excluded.'''],
+ ]
+
+ def __init__(self):
+ usage.Options.__init__(self)
+ self._includes = []
+ self._excludes = []
+ self['includes'] = None
+ self['excludes'] = None
+
+ def opt_include(self, arg):
+ self._includes.append('.*%s.*' % (arg,))
+ opt_filter = opt_include
+
+ def opt_exclude(self, arg):
+ self._excludes.append('.*%s.*' % (arg,))
+
+ def postOptions(self):
+ if self['repository'] is None:
+ raise usage.error("You must pass --repository")
+ if self._includes:
+ self['includes'] = '(%s)' % ('|'.join(self._includes),)
+ if self._excludes:
+ self['excludes'] = '(%s)' % ('|'.join(self._excludes),)
+
+
+def main(opts):
+ repo = opts['repository']
+ print "Repo:", repo
+ rev_arg = ''
+ if opts['revision']:
+ rev_arg = '-r %s' % (opts['revision'],)
+ changed = commands.getoutput('svnlook changed %s "%s"' % (rev_arg, repo)
+ ).split('\n')
+ changed = [x[1:].strip() for x in changed]
+ message = commands.getoutput('svnlook log %s "%s"' % (rev_arg, repo))
+ who = commands.getoutput('svnlook author %s "%s"' % (rev_arg, repo))
+ revision = opts.get('revision')
+ if revision is not None:
+ revision = int(revision)
+
+ # see if we even need to notify buildbot by looking at filters first
+ changestring = '\n'.join(changed)
+ fltpat = opts['includes']
+ if fltpat:
+ included = sets.Set(re.findall(fltpat, changestring))
+ else:
+ included = sets.Set(changed)
+
+ expat = opts['excludes']
+ if expat:
+ excluded = sets.Set(re.findall(expat, changestring))
+ else:
+ excluded = sets.Set([])
+ if len(included.difference(excluded)) == 0:
+ print changestring
+ print """\
+Buildbot was not interested, no changes matched any of these filters:\n %s
+or all the changes matched these exclusions:\n %s\
+""" % (fltpat, expat)
+ sys.exit(0)
+
+ pbcf = pb.PBClientFactory()
+ reactor.connectTCP(opts['bbserver'], int(opts['bbport']),
+ pbcf)
+
+ def gotPersp(persp):
+ print "who", repr(who)
+ print "what", repr(changed)
+ print "why", repr(message)
+ print "new revision", repr(revision)
+ return persp.callRemote('addChange', {'who': who,
+ 'files': changed,
+ 'comments': message,
+ 'revision': revision})
+
+ def quit(*why):
+ print "quitting! because", why
+ reactor.stop()
+
+
+ pbcf.login(credentials.UsernamePassword('change', 'changepw')
+ ).addCallback(gotPersp
+ ).addCallback(quit, "SUCCESS"
+ ).addErrback(quit, "FAILURE")
+
+ # timeout of 60 seconds
+ reactor.callLater(60, quit, "TIMEOUT")
+
+ reactor.run()
+
+if __name__ == '__main__':
+ opts = Options()
+ try:
+ opts.parseOptions()
+ except usage.error, ue:
+ print opts
+ print "%s: %s" % (sys.argv[0], ue)
+ sys.exit()
+ main(opts)
Property changes on: extras/svk/hooks/svn_buildbot.py
___________________________________________________________________
Name: svn:executable
+ *
More information about the Avida-cvs
mailing list