[1578] | 1 | #!/usr/bin/python |
---|
| 2 | # ------------------------------------------------------------------------------ |
---|
| 3 | # NAME |
---|
| 4 | # post-revprop-change.py |
---|
| 5 | # |
---|
| 6 | # SYNOPSIS |
---|
| 7 | # post-revprop-change.py REPOS REV USER PROPNAME ACTION <&0 |
---|
| 8 | # |
---|
| 9 | # DESCRIPTION |
---|
| 10 | # This script updates the Trac SQLite database with the new revision log |
---|
| 11 | # following a change in svn:log. The old property value is passed via STDIN. |
---|
| 12 | # |
---|
| 13 | # COPYRIGHT |
---|
| 14 | # (C) Crown copyright Met Office. All rights reserved. |
---|
| 15 | # For further details please refer to the file COPYRIGHT.txt |
---|
| 16 | # which you should have received as part of this distribution. |
---|
| 17 | # ------------------------------------------------------------------------------ |
---|
| 18 | |
---|
| 19 | # Standard modules |
---|
| 20 | import commands |
---|
| 21 | import os.path |
---|
| 22 | import sqlite |
---|
| 23 | import sys |
---|
| 24 | |
---|
| 25 | def main (): |
---|
| 26 | '''Main program''' |
---|
| 27 | |
---|
| 28 | # Get command line arguments |
---|
| 29 | (repos, rev, user, propname, action) = sys.argv [1:6] |
---|
| 30 | |
---|
| 31 | # Handle only log message change |
---|
| 32 | if not (propname == 'svn:log' and action == 'M'): |
---|
| 33 | return |
---|
| 34 | |
---|
| 35 | # Get new message with "svnlook" |
---|
| 36 | message = commands.getoutput ('svnlook log -r ' + rev + ' ' + repos) |
---|
| 37 | if not message: |
---|
| 38 | return |
---|
| 39 | |
---|
| 40 | # Name of the project |
---|
| 41 | project = os.path.basename (repos) |
---|
| 42 | project = project.replace ('_svn', '') |
---|
| 43 | |
---|
| 44 | # Path to project Trac system |
---|
| 45 | trac = os.path.join (os.path.expanduser ('~fcm'), 'trac', 'live', project) |
---|
| 46 | trac_db = os.path.join (trac, 'db', 'trac.db') |
---|
| 47 | |
---|
| 48 | # Update Trac database |
---|
| 49 | db = sqlite.connect (trac_db) |
---|
| 50 | cursor = db.cursor () |
---|
| 51 | cursor.execute ( |
---|
| 52 | "UPDATE revision SET message = %s WHERE rev == %s", message, rev |
---|
| 53 | ) |
---|
| 54 | |
---|
| 55 | try: |
---|
| 56 | db.commit () |
---|
| 57 | |
---|
| 58 | except: |
---|
| 59 | raise 'Failed to update log of revision ' + rev + ' in ' + trac_db + '.' |
---|
| 60 | |
---|
| 61 | else: |
---|
| 62 | print 'Updated log of revision ' + rev + ' in ' + trac_db + '.' |
---|
| 63 | |
---|
| 64 | return |
---|
| 65 | |
---|
| 66 | # ------------------------------------------------------------------------------ |
---|
| 67 | |
---|
| 68 | if __name__ == '__main__' : |
---|
| 69 | main () |
---|