SVN and Mantis Bug Tracker Integration (Linux/Python)

Hello fellow developers,

As announced recently, I am now working on a new version of MPfm for the Linux and Mac OS X platforms. I have installed Ubuntu and MonoDevelop for developing the Linux version of MPfm.

Because of this, I am now moving my private Subversion server into a minimal Gentoo Linux box inside VirtualBox. I can now host the SVN server inside any OS I want. I was previously using VisualSVN on Windows.

Since I didn’t want to install Mono on the Gentoo box to re-use my previous .NET console application, I have chosen to write the new Subversion/Mantis integration script using Python3.

Here is the post-commit file I am using:



/usr/bin/python /var/svn/repos/MPfm/hooks/ "$REPOS" "$REV"

Here is the code for the Python3 script that posts the Subversion log to Mantis:

# SVN/Mantis Integration Script 0.1

import sys
import subprocess as sub
import urllib.request
import urllib.parse

def main():

  # Check arguments
  if(len(sys.argv) != 3):
    print("The script needs 2 arguments")

  repo = sys.argv[1]
  rev = sys.argv[2]

  # Get SVN change log
  args = ['svnlook', 'changed', '-r', rev, repo]
  p = sub.Popen(args,stdout=sub.PIPE,stderr=sub.PIPE)
  outputChanged, errorsChanged = p.communicate()
  strOutputChanged = str(outputChanged, encoding='utf8')

  # Get SVN author
  args = ['svnlook', 'author', '-r', rev, repo]
  p = sub.Popen(args,stdout=sub.PIPE,stderr=sub.PIPE)
  outputAuthor, errorsAuthor = p.communicate()
  strOutputAuthor = str(outputAuthor, encoding='utf8').replace("\n", "")

  # Get SVN comment
  args = ['svnlook', 'log', '-r', rev, repo]
  p = sub.Popen(args,stdout=sub.PIPE,stderr=sub.PIPE)
  outputLog, errorsLog = p.communicate()
  strOutputLog = str(outputLog, encoding='utf8')

  # Add comment to Mantis issue
  url = ""
  logContent = "The user <b>" + strOutputAuthor + "</b> has checked in files related to this issue (revision <b>" + rev + "</b>).<br /><br /><b>Comment:</b><br />" + strOutputLog + "<br /><br /><b>Files modified:</b><br />" + strOutputChanged
  logContent = logContent.replace("\\n", "<br />")
  post_data = {"user":"svn", "log":logContent}
  post_data_encoded = urllib.parse.urlencode(post_data)
  request_object = urllib.request.Request(url, post_data_encoded)
  response = urllib.request.urlopen(request_object)
  html_string =

if __name__ == "__main__":

Do not forget to make both files executable by typing:

sudo chmod o+x filename.ext

Note: To complete the integration, you will also need the modified checkin.php file for Mantis, which you can find in the previous article.

If you have any questions, do not hesitate to ask!


Tags: , , , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>