[Sourcebo-commits] jlbec commits r81 - trunk

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Fri Nov 11 21:18:30 CST 2005


Author: jlbec
Date: 2005-11-11 21:18:29 -0600 (Fri, 11 Nov 2005)
New Revision: 81

Added:
   trunk/sb_buildbot
Log:
add sb_buildbot

Added: trunk/sb_buildbot
===================================================================
--- trunk/sb_buildbot	2003-09-02 16:13:54 UTC (rev 80)
+++ trunk/sb_buildbot	2005-11-12 03:18:29 UTC (rev 81)
@@ -0,0 +1,146 @@
+#!/usr/bin/env python2.3
+
+#
+# This requires python >=2.2 for the 'email' module
+#
+
+# Get Subversion commit_email.pl messages from Sourcebo into your mail
+# filtering and pass a single message on standard input to this script
+# like so:
+'''
+# Set up PYTHONPATH if needed
+. ~/.environment
+
+/path/to/sb_buildbot localhost:9987
+'''
+
+import email, email.Iterators, sys, os
+
+
+def get_repository(msg, info):
+    # Check that this is, indeed, a commit message.
+    # This trusts Sender is <reponame>-commits-bounces at repo.com.  You
+    # _are_ using Sourcebo and commit-email.pl, right?
+    try:
+        ind = msg['Sender'].index('-commits-bounces@')
+    except ValueError:
+        sys.exit(0);
+
+    info['repository'] = msg['Sender'][:ind]
+
+def get_field(iter, info, field_name, field_string):
+    if info.has_key(field_name):
+        return
+
+    for s in iter:
+        if s.startswith(field_string):
+            info[field_name] = s[len(field_string):].rstrip('\n')
+            break
+
+# We do both at the same time, because the Log is the end of file list
+def get_files_and_log(iter, info):
+    in_files = ''
+    files_set = ("Modified:\n", "Removed:\n", "Added:\n")
+    log_set = ("Log:\n",)
+    info['files'] = []
+    info['log'] = ['Repository: %(repository)s\n' % info, '\n']
+
+    for s in iter:
+        if s in files_set:
+            in_files = s
+            continue
+        if s in log_set:
+            in_files = s
+            continue
+
+        if in_files in files_set:
+            info['files'].append('%s' % s.lstrip().rstrip('\n'))
+        elif in_files in log_set:
+            # Detecting the start of the diff really sucks
+            for state in files_set:
+                state = state.rstrip('\n')
+                if s.startswith(state):
+                    return
+            info['log'].append(s)
+
+def detect_branch(info):
+    info['branch'] = ''
+    for f in info['files']:
+        if f.startswith('trunk/'):
+            info['branch'] = 'trunk'
+        elif f.startswith('branches/'):    
+            index = f.find('/', len('branches/'))
+            info['branch'] = f[0:index]
+        elif f.startswith('tags/'):
+            index = f.find('/', len('tags/'))
+            info['branch'] = f[0:index]
+        elif f.find('/') > -1:
+            index = f.find('/')
+            info['branch'] = f[0:index]
+
+        if info['branch']:
+            break
+
+
+def run_buildbot(info):
+    cmd = ['buildbot', 'sendchange']
+    cmd.append('--master=%(master)s' % info)
+    cmd.extend(['-u', info['author']])
+    cmd.extend(['-b', info['branch']])
+    cmd.extend(['-n', info['revision']])
+    cmd.extend(['-F', '-'])
+    cmd.extend(info['files'])
+
+    (logpipe, logouterr) = os.popen4(cmd, 'w')
+    logpipe.writelines(info['log'])
+    logpipe.close()
+
+    sys.stdout.write(logouterr.read())
+    logouterr.close()
+
+def usage(error):
+    prog = 'sb_buildbot'
+
+    if error:
+        sys.stderr.write('%s: %s\n' % (prog, error))
+    sys.stderr.write('Usage: %s <master>:<port>\n' % prog)
+    sys.exit(1)
+
+def main(argv):
+    if not len(argv):
+        usage('Master not specified')
+    try:
+        argv[1].index(':')
+    except ValueError:
+        usage('Master port not specifed')
+
+    info = {'master': argv[1]}
+
+    msg = email.message_from_file(sys.stdin)
+
+    # We don't handle mime, TYVM
+    if msg.is_multipart():
+        sys.exit(0);
+
+    get_repository(msg, info)
+
+    iter = email.Iterators.body_line_iterator(msg)
+
+    get_field(iter, info, 'author', 'Author: ')
+    get_field(iter, info, 'date', 'Date: ')
+    get_field(iter, info, 'revision', 'New Revision: ')
+
+    get_files_and_log(iter, info)
+    detect_branch(info)
+
+    # Did we get an extra newline on the log due to diff detection?
+    if info['log'][-1] == '\n':
+        info['log'].pop()
+
+    run_buildbot(info)
+    
+
+
+if __name__ == '__main__':
+    main(sys.argv)
+


Property changes on: trunk/sb_buildbot
___________________________________________________________________
Name: svn:executable
   + *



More information about the Sourcebo-commits mailing list