Subversion from Python

Generally, it’s preferable to bind to libraries rather than executables when given the option. In my case, I needed SVN access from Python and couldn’t, at that time, find a confidence-inspiring library to work with. So, I wrote svn.

It turns out that there is a Subversion-sponsored Python project. It looks to be SWIG-based.

This comes from the python-svn Apt package under Ubuntu.

The Programmer’s Guide has the following examples, among others:

cat:

import pysvn
client = pysvn.Client()
file_content = client.cat('file.txt')

ls:

import pysvn
client = pysvn.Client()
entry_list = client.ls('.')

info:

import pysvn
client = pysvn.Client()
entry = client.info('.')

Finding the Mime-Type of a File in Subversion

I’m not a fan of Subversion but it exists in my life nonetheless. To that end, sometimes you may need to write tools against it. Sometimes these tools may need to differentiate between binary and text entries. Since SVN needs to know, at the very least, whether a file is text or binary (because most version-control systems depend on taking deltas of text-files), it’s reasonable to think that you can read this information from SVN.

This information may be stored as a property on each entry. Note that though there appears to be no guarantee that this information is available, I consider it to be reasonable to expect that a binary file will always have a non-empty mime-type.

The mime-type of an image:

$ svn propget svn:mime-type image.png
application/octet-stream
$ echo $?
0

The mime-type of a plain-text file:

$ svn proplist config.xml
$ echo $?
0

Notice that you’ll get a successful return (0) whether that property is or is not defined.

You can also read the property off remote files in the same fashion:

$ svn propget svn:mime-type https://subversion.host/image.png
application/octet-stream

Make Subversion Tags in Record Time

I, like most developers nowadays, despise Subversion. This is in no small part due to how much of a manual effort it is to properly tag your software. I still do it, but it makes me seeth with rage.

The svncl tool streamlines this. You simply give it the working-directory and the URL of the tags path within the repository, and it gives you a bulleted list of commit-messages that have occurred between the last tag and the current HEAD.

For example:

$ svncl . https://svnserver.com/tags/project
- Setup fix.
- Removed obsolete references to collections package.
- Updates are now stored in S3.
- Added parallel S3 downloading.