On Sun, Aug 24, 2008 at 6:25 PM, Lawrence Stewart <lstewart_at_room52.net> wrote:
> Lawrence Stewart wrote:
>> Lawrence Stewart wrote:
>>> Hi all,
>>> I'm playing with the Python SWIG bindings for SVN 1.5.1 and have run into
>>> a brick wall. I want to update a working copy from a python script, and have
>>> a python function callback executed for each item updated. The python code
>>> below hopefully illustrates what I'm trying to do.
>>> def update_callback(notify, pool):
>>> print "in callback"
>>> def update(wc, rev):
>>> ctx = svn.client.svn_client_create_context()
>>> ctx.notify_func2 = update_callback
>>> r = svn.core.svn_opt_revision_t()
>>> r.kind = svn.core.svn_opt_revision_head
>>> result_rev = svn.client.svn_client_update(wc, r, True, ctx)
>>> print "result_rev: %d" % result_rev
>>> The update function does work and my working copy does get updated the
>>> HEAD, but my callback is never executed.
>>> I'm basing this code on the statement in
>>> http://svn.collab.net/svn-doxygen/group__Update.html that says if
>>> ctx->notify_func2 is not NULL it will be called for each item updated. This
>>> of course may not work or be applicable in Python land... someone please
>>> tell me if this is the case.
>>> I've tried countless variations of the above code and changing parameters
>>> to the callback, changing the way the callback is assigned to the context
>>> object (I tried following the way it was done in the client.py unit test
>>> file for a different callback type that is used) etc. etc. without success.
>>> I suspect my problem is that I just don't grok the translation that SWIG
>>> is doing from the C API up into Python and therein lies the problem.
>>> Any help in understanding what I'm doing wrong or how I can achieve
>>> something equivalent would be greatly appreciated.
>> Quick follow up... I just stumbled across this thread that describes what
>> I'm trying to do.
>> It provided the missing clue I needed to make this work.
>> Apologies for the noise.
> Ok, so I can now get the callback to fire, but the arguments passed to it
> look like random pointer junk and python coredumps somewhere within the
> svn.client.svn_client_update3() call after having executed the update and a
> few callbacks. Here's the new code:
> def update_callback(path, action, kind, mime_type, content_state,
> prop_state, revision):
> print "callback\taction: %d\trev: %u" % (action,revision)
> def update(wc, rev):
> ctx = svn.client.svn_client_ctx_t()
> #ctx.notify_func = svn.client.svn_swig_py_notify_func
> #ctx.notify_baton = update_callback
> ctx.notify_func2 = svn.client.svn_swig_py_notify_func
> ctx.notify_baton2 = update_callback
> r = svn.core.svn_opt_revision_t()
> r.kind = svn.core.svn_opt_revision_head
> result_revs = svn.client.svn_client_update3([wc], r,
> svn.core.svn_depth_infinity, False, True, True, ctx)
> for result_rev in result_revs:
> print "result_rev: %d" % result_rev
> print "done"
> except svn.core.SubversionException, e:
> sys.stderr.write("Error (%d): %s\n" % (e.apr_err, e.message))
> except Exception, e:
> print "Unknown exception"
> print e
> I've also added some debug printfs to the underlying C functions
> svn_swig_py_notify_func() and svn_swig_py_notify_func2() in swigutil_py.c to
> check which function is being called and if the arguments coming into the C
> function are the same as what is being reported by python.
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 *
wc = csvn.wc.WC("wc")
if obj.action == svn_wc_notify_update_update:
print "U", obj.path
elif obj.action == svn_wc_notify_update_completed:
print "Completed", obj.path
The above example works on my machine, and outputs the following:
The ctypes python bindings are available at
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
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 00:57:11 CEST