Code
# Copyright 2009 Corey Trager
# Distributed under the terms of the GNU General Public License
Import sys
Import subprocess
Import re
Import urllib
Import OS
######################################## ###############################
#
# See SVN documentation for how to install a hook script.
#
######################################## ###############################
######################################## ###############################
#
#!!! Start of stuff you need to change
#
######################################## ################################
# Bugtracker. Net username and password. The username needs to match
# A setting in Web. config.
Btnet_username = "wxy"
Btnet_password = "wxy"
# The Path to the svn executable
# The following line cannot be in the official template format. It took me a whole night
Svn_path = "C :\\ Program Files \ collabnet \ Subversion server \ svn.exe"
# The URL needs to be reachable from the machine where this script is
# Running. (I have a virtual directory named "btnet"). Don't
# Use IIS Windows security on svn_hook.aspx.
Btnet_url = "http: // 10.129.250.99/bugtracker/svn_hook.aspx"
# The repository URL. bugtracker. NET web pages will use this URL
# Interact with this repository. If you need a username and password
# To access this repo, you configure that in Web. config. See
# Web. config for more info.
This_repository_url = "http: // 10.129.250.99: 81/SVN/teachermanager"
Bdebug = true
######################################## ###############################
#
#!!! End of stuff you need to change
#
######################################## ###############################
######################################## ###############################
# For debugging, display info and keep a log
######################################## ###############################
Def debug_out (s ):
If (bdebug ):
F = open (OS. Environ ["Temp"]) + '\ btnet_svn_hook_log.txt', 'A ')
F. Write (s)
F. Write ('\ n ')
F. Close
Print s
Repo = SYS. argv [1]
REV = SYS. argv [2]
Debug_out (repo)
Debug_out (REV)
######################################## ###############################
#
# This is where this script keeps track of previusly processed
# Revisions. If you delete this file, this script will send log info
# For all revisions to bugtracker. net. You might want to do that
# Reload the svn_revisions and svn_affected_paths tables.
#
######################################## ###############################
Prev_revision_file = repo + "\ hooks \ btnet_prev_revision.txt"
Debug_out (prev_revision_file)
######################################## ###############################
# Get the log info from SVN
# If we 've already fetched info in the past, just fetch the info
# Since the last revision
######################################## ###############################
# Get the previous revision
Try:
Most_recent_revision_file = open (prev_revision_file, "R ")
Prev_revision = most_recent_revision_file.read (40)
Most_recent_revision_file.close ()
Except t:
Prev_revision = ""
Debug_out ("prev_revision ")
Debug_out (prev_revision)
# Just since previusly processed Revision
File_url = "file: //" + Repo. Replace ("\\","/")
Subcommand = "log -- verbose -- XML"
If prev_revision! = "":
Cmd = svn_path + subcommand + "-R" + prev_revision + ":" + REV + file_url
Else:
Cmd = svn_path + subcommand + file_url
Debug_out (CMD)
Process = subprocess. popen (CMD, stdout = subprocess. Pipe, stderr = subprocess. Pipe)
Debug_out ("log stdout :")
Log_string = process. stdout. Read ()
Debug_out (log_string)
Debug_out ("stderr :")
Debug_out (process. stderr. Read ())
# Remember that we already processed this revision
Most_recent_revision_file = open (prev_revision_file, "W ")
Most_recent_revision_file.write (REV)
Most_recent_revision_file.close ()
# Get the first revision in the log string and save it to the file.
######################################## ###############################
# Send an HTTP request to bugtracker. net, the svn_hook.aspx page.
######################################## ###############################
Params = urllib. urlencode ({
'Svn _ log': log_string,
'Repo': this_repository_url,
'Username': btnet_username,
'Password': btnet_password })
Response = urllib. urlopen (btnet_url, Params)
Data = response. Read ()
Debug_out (data)