[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: Help with Python SWIG bindings and callbacks

From: Lawrence Stewart <lstewart_at_room52.net>
Date: Tue, 26 Aug 2008 12:33:07 +1000

David James wrote:
> On Mon, Aug 25, 2008 at 7:02 PM, David James <james82_at_gmail.com> wrote:
>> On Mon, Aug 25, 2008 at 6:18 PM, Lawrence Stewart <lstewart_at_room52.net> wrote:
>>>> Have you considered trying out the new ctypes python bindings? I tried
>>>> converting your script to use the new ctypes python bindings, and it
>>>> seems to work fine. See the example below.
>>>>
>>>> from csvn.core import *
>>>> import csvn.wc
>>>> svn_cmdline_init("", csvn.core.stderr)
>>>> wc = csvn.wc.WC("wc")
>>>>
>>>> def notify_func(obj):
>>>> if obj.action == svn_wc_notify_update_update:
>>>> print "U", obj.path
>>>> elif obj.action == svn_wc_notify_update_completed:
>>>> print "Completed", obj.path
>>>>
>>>> wc.checkout("http://svn.collab.net/repos/svn/trunk/www/")
>>>> wc.update(revnum=32695)
>>>> wc.set_notify_func(notify_func)
>>>> wc.update(revnum=32696)
>>>>
>>>> The above example works on my machine, and outputs the following:
>>>> U wc/faq.ja.html
>>>> U wc
>>>> Completed wc
>>>>
>>>> The ctypes python bindings are available at
>>>> http://svn.collab.net/repos/svn/branches/ctypes-python-bindings/, and
>>>> should work fine with Subversion 1.5.x. Hopefully they will be
>>>> standard in Subversion 1.6.0, but we are still working on a few
>>>> finishing touches.
>>>
>>> No I haven't considered ctypes (wasn't even aware of it). Thanks for the
>>> pointer. Is there other documentation than the README in the top level
>>> branch dir that I should be referring to?
>>>
>>> Is it anticipated that the ctypes interface will usurp the SWIG code? I had
>>> kind of hoped to create a script that was backward compatible with vanilla
>>> SVN back to 1.4.x hence the use of the SWIG API and not something like
>>> PySVN, but I guess it's not disastrous if that's not the case.
>>>
>>> As a bit of background, I'm trying to create a script that allows me to
>>> mirror a portion of a remote repo into my own development repo as a vendor
>>> branch. The existing tools just don't seem to cut it for this use case and
>>> hacking the svn C code seemed a bit extreme to get something working
>>> relatively quickly. Given the trouble I'm having with the bindings perhaps I
>>> should have just dived straight into writing a small C app. I'm willing to
>>> be told otherwise if someone here has/knows such a tool in which case my
>>> need for python bindings disappears :)
>> Hi Lawrence,
>>
>> The ctypes python bindings should work with vanilla Subversion 1.4.x
>> or later. I haven't tried them recently with Subversion 1.4, but they
>> should work. If they don't still work with SVN 1.4, let me know.

Awesome!

>>
>> One really nice part about the ctypes python bindings is that you
>> don't need to recompile the bindings for it to work with a different
>> version of Subversion, or a different platform -- it's a pure python
>> binding.

Sounds too good to be true! If I'm understanding you correctly, the
ctypes python module does the necessary magic to tie the low level
python-svn API code to the underlying raw SVN C APIs without any SVN C
code glue? Then you just layer some additional Python classes on top and
that's it?

>>
>> If you like Python, the ctypes python bindings are probably the
>> easiest way to get started with the Subversion API. The low level APIs
>> in ctypes don't have documentation, but they don't need it, because
>> they are an exact mirror of the C APIs. All C APIs work verbatim
>> identical in the ctypes python bindings.

I certainly like the sound of it. I grok the svn C APIs just fine... it
was the SWIG translation code that was doing my head in. This ctypes
stuff sounds great (even if it is Python specific and therefore not
applicable to all languages).

>>
>> We also implemented some higher level python objects which make it
>> easier to do common tasks in the ctypes python bindings. I find these
>> quite helpful. You can learn the high level APIs by looking at the
>> test suite for the ctypes python bindings. If you want examples of how
>> to use the low level APIs, try taking a look at the implementation of
>> the low level APIs.

Yup cool.

>
> Oops. Typo here. I should have said, if you want examples of how to
> use the low level APIs as well, try taking a look at the
> implementation of the high level APIs, which make use of the low level
> APIs.

rgr.

Thanks for the insights!

Cheers,
Lawrence

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe_at_subversion.tigris.org
For additional commands, e-mail: dev-help_at_subversion.tigris.org
Received on 2008-08-26 04:33:44 CEST

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.