On Mon, 2009-12-14 at 14:54 +0100, Dr J A Gow wrote: > On Sun, 2009-12-13 at 18:51 +0000, Mark Ellis wrote: > > On Sat, 2009-12-12 at 18:27 +0100, Mark Ellis wrote: > > > On Thu, 2009-12-10 at 01:25 +0100, Dr J A Gow wrote: > > > > On Wed, 2009-12-02 at 22:01 +0000, Mark Ellis wrote: > > > > > > > > > > > > > > John, you had any luck with this ? I've just started to take a look at > > > > > it, and they seem to have changed a few things don't they ... > > > > > > > > > > Mark > > > > > > > > > > > > > Just checked it again: I _still_ can't get Opensync SVN python-module to > > > > build. > > > > > > > > John. > > > > > > > > > > Well, I've had a good old hack at this, I can get it into a buildable > > > state, but I'm in no doubt that it won't actually work. It seems to have > > > python objects as userdata coming out of nowhere by functions that have > > > been removed from the public api !!! > > > > > > Just out of interest, has anyone asked the opensync guys if they are > > > going to maintain this ? > > > > > > > Ok, had a revelation. > > > > Attached is a patch to the 0.36 python plugin (the last release) which I > > hope will make it work for 0.39, and presumably trunk. It may not apply > > completely cleanly to trunk, but I can't seem to check that out at the > > moment. > > > > I can't test it properly myself at the moment, but am reasonably > > confident, and thought I'd throw it out there for you guys to play > > with ! > > > > > Thanks for this Mark. I was trying to avoid getting to embroiled in > Opensync innards so this is much appreciated. I will test as soon as I > can, probably will fix it up for trunk as I am running Opensync trunk at > the moment. Fingers crossed! If it works I will prioritize the Opensync > 0.4x fixes in sync-engine. >
Ditto on the innards :) Managed to get trunk, and regenerated the patch to build against it. Not much success with testing however, due to some apparently dodgy code in the opensync python wrapper, with C style comments and other whatnot. I know absolutely nothing about swig ... Mark
diff -Nurp python-module.orig/CMakeLists.txt python-module/CMakeLists.txt
--- python-module.orig/CMakeLists.txt 2008-08-18 19:21:34.000000000 +0100
+++ python-module/CMakeLists.txt 2009-12-14 21:47:32.264536712 +0000
@@ -1,12 +1,18 @@
PROJECT( libopensync-plugin-python C )
-SET( VERSION "0.38" )
+SET( VERSION "0.40" )
SET( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules" )
+CMAKE_MINIMUM_REQUIRED( VERSION 2.4.4 )
+
+IF(COMMAND cmake_policy)
+ cmake_policy(SET CMP0003 NEW)
+ENDIF(COMMAND cmake_policy)
+
INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} )
-SET( OPENSYNC_MIN_VERSION "0.37" )
+SET( OPENSYNC_MIN_VERSION "0.40" )
FIND_PACKAGE( OpenSync REQUIRED )
FIND_PACKAGE( PythonLibs REQUIRED )
diff -Nurp python-module.orig/src/CMakeLists.txt python-module/src/CMakeLists.txt
--- python-module.orig/src/CMakeLists.txt 2007-12-11 13:58:08.000000000 +0000
+++ python-module/src/CMakeLists.txt 2009-12-14 21:39:56.657533879 +0000
@@ -1,6 +1,9 @@
LINK_DIRECTORIES( ${OPENSYNC_LIBRARY_DIRS} ${GLIB2_LIBRARY_DIRS} )
INCLUDE_DIRECTORIES( ${OPENSYNC_INCLUDE_DIRS} ${GLIB2_INCLUDE_DIRS} ${PYTHON_INCLUDE_PATH} )
+IF(COMMAND cmake_policy)
+ cmake_policy(SET CMP0005 OLD)
+ENDIF(COMMAND cmake_policy)
ADD_DEFINITIONS( -DOPENSYNC_PYTHONPLG_DIR="\\\"${OPENSYNC_PYTHONPLG_DIR}\\\"" )
# python plugin module source
diff -Nurp python-module.orig/src/python_module.c python-module/src/python_module.c
--- python-module.orig/src/python_module.c 2009-03-29 23:42:10.000000000 +0100
+++ python-module/src/python_module.c 2009-12-14 21:25:38.648536920 +0000
@@ -159,7 +159,7 @@ error:
* - function(info, context)
* - function(info, context, change)
*/
-static osync_bool pm_call_module_method(MemberData *data, char *name, OSyncPluginInfo *info, OSyncContext *ctx, OSyncChange *chg)
+static osync_bool pm_call_module_method(OSyncObjTypeSink *sink, OSyncPluginInfo *info, OSyncContext *ctx, void *userdata, char *name, OSyncChange *chg)
{
osync_trace(TRACE_ENTRY, "%s(%s, %p, %p, %p)", __func__, name, info, ctx, chg);
PyObject *ret = NULL;
@@ -168,21 +168,24 @@ static osync_bool pm_call_module_method(
PyGILState_STATE pystate = PyGILState_Ensure();
- PyObject *pyinfo = pm_make_info(data->osync_module, info, &error);
+ PyObject *osync_module = NULL;
+ if (!(osync_module = pm_load_opensync(&error)))
+ goto error;
+
+ PyObject *pyinfo = pm_make_info(osync_module, info, &error);
if (!pyinfo)
goto error;
- PyObject *pycontext = pm_make_context(data->osync_module, ctx, &error);
+ PyObject *pycontext = pm_make_context(osync_module, ctx, &error);
if (!pycontext) {
Py_DECREF(pyinfo);
goto error;
}
- OSyncObjTypeSink *sink = osync_plugin_info_get_sink(info);
- PyObject *sink_pyobject = osync_objtype_sink_get_userdata(sink);
+ PyObject *sink_pyobject = userdata;
if (chg) {
- PyObject *pychange = pm_make_change(data->osync_module, chg, &error);
+ PyObject *pychange = pm_make_change(osync_module, chg, &error);
if (!pychange) {
Py_DECREF(pyinfo);
Py_DECREF(pycontext);
@@ -201,6 +204,7 @@ static osync_bool pm_call_module_method(
if (ret) {
Py_DECREF(pycontext);
Py_DECREF(ret);
+ Py_XDECREF(osync_module);
PyGILState_Release(pystate);
osync_context_report_success(ctx);
osync_trace(TRACE_EXIT, "%s", __func__);
@@ -212,7 +216,7 @@ static osync_bool pm_call_module_method(
PyErr_Fetch(&pytype, &pyvalue, &pytraceback);
PyObject *osyncerror = NULL;
- osyncerror = PyObject_GetAttrString(data->osync_module, "Error");
+ osyncerror = PyObject_GetAttrString(osync_module, "Error");
if (!osyncerror) {
PYERR_CLEAR();
osync_error_set(&error, OSYNC_ERROR_GENERIC, "Failed to get OSyncError class object");
@@ -256,6 +260,7 @@ out:
Py_XDECREF(osyncerror);
error:
+ Py_XDECREF(osync_module);
PyGILState_Release(pystate);
if (report_error)
osync_context_report_osyncerror(ctx, error);
@@ -263,51 +268,46 @@ error:
return FALSE;
}
-static void pm_connect(void *data, OSyncPluginInfo *info, OSyncContext *ctx)
+static void pm_connect(OSyncObjTypeSink *sink, OSyncPluginInfo *info, OSyncContext *ctx, void *userdata)
{
- pm_call_module_method(data, "connect", info, ctx, NULL);
+ pm_call_module_method(sink, info, ctx, userdata, "connect", NULL);
}
-static void pm_disconnect(void *data, OSyncPluginInfo *info, OSyncContext *ctx)
+static void pm_disconnect(OSyncObjTypeSink *sink, OSyncPluginInfo *info, OSyncContext *ctx, void *userdata)
{
- pm_call_module_method(data, "disconnect", info, ctx, NULL);
+ pm_call_module_method(sink, info, ctx, userdata, "disconnect", NULL);
}
-static void pm_get_changes(void *data, OSyncPluginInfo *info, OSyncContext *ctx)
+static void pm_get_changes(OSyncObjTypeSink *sink, OSyncPluginInfo *info, OSyncContext *ctx, osync_bool slow_sync, void *userdata)
{
- pm_call_module_method(data, "get_changes", info, ctx, NULL);
+ pm_call_module_method(sink, info, ctx, userdata, "get_changes", NULL);
}
-static void pm_commit(void *data, OSyncPluginInfo *info, OSyncContext *ctx, OSyncChange *change)
+static void pm_commit(OSyncObjTypeSink *sink, OSyncPluginInfo *info, OSyncContext *ctx, OSyncChange *change, void *userdata)
{
- pm_call_module_method(data, "commit", info, ctx, change);
+ pm_call_module_method(sink, info, ctx, userdata, "commit", change);
}
-static void pm_committed_all(void *data, OSyncPluginInfo *info, OSyncContext *ctx)
+static void pm_committed_all(OSyncObjTypeSink *sink, OSyncPluginInfo *info, OSyncContext *ctx, void *userdata)
{
- pm_call_module_method(data, "committed_all", info, ctx, NULL);
+ pm_call_module_method(sink, info, ctx, userdata, "committed_all", NULL);
}
-static osync_bool pm_read(void *data, OSyncPluginInfo *info, OSyncContext *ctx, OSyncChange *change)
+static void pm_read(OSyncObjTypeSink *sink, OSyncPluginInfo *info, OSyncContext *ctx, OSyncChange *change, void *userdata)
{
- return pm_call_module_method(data, "read", info, ctx, change);
+ pm_call_module_method(sink, info, ctx, userdata, "read", change);
+}
+
+static void pm_sync_done(OSyncObjTypeSink *sink, OSyncPluginInfo *info, OSyncContext *ctx, void *userdata)
+{
+ pm_call_module_method(sink, info, ctx, userdata, "sync_done", NULL);
}
-static void pm_sync_done(void *data, OSyncPluginInfo *info, OSyncContext *ctx)
+static void pm_connect_done(OSyncObjTypeSink *sink, OSyncPluginInfo *info, OSyncContext *ctx, osync_bool slow_sync, void *userdata)
{
- pm_call_module_method(data, "sync_done", info, ctx, NULL);
+ pm_call_module_method(sink, info, ctx, userdata, "sync_done", NULL);
}
-static OSyncObjTypeSinkFunctions pm_sink_functions = {
- .connect = pm_connect,
- .disconnect = pm_disconnect,
- .get_changes = pm_get_changes,
- .commit = pm_commit,
- .committed_all = pm_committed_all,
- .read = pm_read,
- .batch_commit = NULL, /* not (yet) supported for python plugins */
- .sync_done = pm_sync_done
-};
/** Calls the method initialize function
*
@@ -319,6 +319,8 @@ static void *pm_initialize(OSyncPlugin *
osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, plugin, info, error);
MemberData *data = g_malloc0(sizeof(MemberData));
char *modulename;
+ OSyncList *s, *sinks = NULL;
+ OSyncObjTypeSink *sink = NULL;
if (!(modulename = osync_plugin_get_data(plugin)))
return NULL;
@@ -352,14 +354,22 @@ static void *pm_initialize(OSyncPlugin *
Py_DECREF(ret);
/* loop through all objtype sinks, set up function pointers */
- int n, max = osync_plugin_info_num_objtypes(info);
- for (n = 0; n < max; n++) {
- OSyncObjTypeSink *sink = osync_plugin_info_nth_objtype(info, n);
- PyObject *sinkobj = osync_objtype_sink_get_userdata(sink);
- osync_objtype_sink_set_functions(sink, pm_sink_functions, sinkobj);
- Py_INCREF(sinkobj);
- data->sinks = g_slist_prepend(data->sinks, sinkobj);
+
+ sinks = osync_plugin_info_get_objtype_sinks(info);
+ for (s = sinks; s; s = s->next) {
+ sink = (OSyncObjTypeSink *)s;
+
+ osync_objtype_sink_set_connect_func(sink, pm_connect);
+ osync_objtype_sink_set_disconnect_func(sink, pm_disconnect);
+ osync_objtype_sink_set_get_changes_func(sink, pm_get_changes);
+ osync_objtype_sink_set_commit_func(sink, pm_commit);
+ osync_objtype_sink_set_committed_all_func(sink, pm_committed_all);
+ osync_objtype_sink_set_read_func(sink, pm_read);
+ osync_objtype_sink_set_sync_done_func(sink, pm_sync_done);
+ osync_objtype_sink_set_connect_done_func(sink, pm_connect_done);
+
}
+ osync_list_free(sinks);
PyGILState_Release(pystate);
osync_trace(TRACE_EXIT, "%s", __func__);
@@ -374,7 +384,7 @@ error:
return NULL;
}
-static osync_bool pm_discover(void *data_in, OSyncPluginInfo *info, OSyncError **error)
+static osync_bool pm_discover(OSyncPluginInfo *info, void *data_in, OSyncError **error)
{
osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, data_in, info, error);
@@ -474,7 +484,10 @@ static osync_bool register_plugin(OSyncP
osync_plugin_set_discover(plugin, pm_discover);
osync_plugin_set_finalize(plugin, pm_finalize);
osync_plugin_set_data(plugin, g_strdup(modulename));
- osync_plugin_env_register_plugin(env, plugin);
+
+ if (!osync_plugin_env_register_plugin(env, plugin, error))
+ return FALSE;
+
osync_plugin_unref(plugin);
osync_trace(TRACE_EXIT, "%s", __func__);
@@ -597,7 +610,7 @@ osync_bool get_sync_info(OSyncPluginEnv
PyEval_ReleaseLock();
} else if (!PyEval_ThreadsInitialized()) {
/* Python has been initialised, but threads are not. */
- osync_error_set(error, OSYNC_ERROR_GENERIC, "The Python interpreter in this process has been initialised without threading support.");
+ osync_error_set(error, OSYNC_ERROR_GENERIC, "The Python interpreter in this process has been initialised without threading support.");
osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error));
return FALSE;
}
signature.asc
Description: This is a digitally signed message part
------------------------------------------------------------------------------ Return on Information: Google Enterprise Search pays you back Get the facts. http://p.sf.net/sfu/google-dev2dev
_______________________________________________ SynCE-Devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/synce-devel
