tags:

views:

678

answers:

3

Hello.

Subversion 1.6 introduce something that is called 'Ctypes Python Binding', but it is not documented. Is it any information available what this bindings are and how to use it? For example, i have a fresh windows XP and want to control SVN repository using subversiion 1.6 and this mysterious python bindings. What exactly i need to download/install/compile in order to do something like

import svn from almighty_ctype_subversion_bindings
svn.get( "\\rep\\project" )

And how is this connected to pysvn project? Is this a same technology, or different technologies?

A: 

The whole point of ctypes is that you shouldn't need to have to compile anything anywhere. That said, the readme for the bindings mentions some dependencies and a build step.

The bindings can be found in the Subversion source distribution at least, in subversion/bindings/ctypes-python/, with a distutils setup.py.

They seem to be a successor / alternative of sorts to pysvn.

Sii
And is it any way to redistribute this binding to end user? For example, if i want my python application on Jon's WinXP computer - will it be enough for him to install python and subversion? Or he needs to install some "csvn sybversion ctypes python bindings package" ?
Eye of Hell
Sorry, no idea, my office machine is the Windows one. Pysvn, however, has working Windows binaries available that I found fairly easy to use - there's an interface that mirrors working with the command-line client. So you could try that.
Sii
Not so much a successor to pySvn, but a successor to the previous official Python bindings. The previous official Python bindings were very closely aligned to the C API, and not especially "pythonic". I don't know what the status is with the new bindings.pySvn is an independent effort to make a Python SVN library that is more "pythonic", and is quite different from the C API. I found it much easier to use.
Craig McQueen
pySvn need to be installed by end user as a library. Are new ctypes bindings require only svn install or do they require any additional steps?
Eye of Hell
A: 

I looked into the python binding for subversion, but in the end I found it to be simpler to just invoke svn.exe like this:

(stdout, stderr, err) = execute('svn export "%s" "%s"' \
   % (exportURL, workingCopyFolder))

where execute is a function like this:

def execute(cmd):
    import subprocess
    proc = subprocess.Popen(\
          cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    (stdout, stderr) = proc.communicate()
    return (stdout, stderr, proc.returncode)

The output of svn.exe is designed to be easily parsed if necessary. There is even a --xml output option.

Wim Coenen
It's easier to parse the output of svn than use the bindings, but it can be tens or hundreds of times slower for some operations because there's no way to amortize the overhead of connecting and authenticating.
joeforker
the other problem with this is security. invoking a shell with text inputted by a user is a way for user to inject nasty stuff like: "; rm -rf *;"
sean riley
Interesting points, but fortunately these are not relevant in my own use of python+svn, i.e. an automated build script. I suspect this is the most common reason to script svn.
Wim Coenen
+1 because it's an alternative at least worth considering.
Craig McQueen
+1  A: 

You need the Subversion source distribution, Python (>= 2.5), and ctypesgen.

Instructions for building the ctypes bindings are here.

You will end up with a package called csvn, examples of it's use are here.

James Emerton
As far as I can tell ctypes needs to be built separately (not included in the main distribution), and also requires linux. The build requires the Apache Portable Runtime, and in particular requires a config file for this which cannot be built using standard tools on Windows. I'm using pySvn instead, which has a Windows installer and seems to work well.
Simon D