diff options
author | Mads Chr. Olesen <gnome-bugzilla@shiyee.dk> | 2009-01-04 22:01:20 +0000 |
---|---|---|
committer | Paul Pogonyshev <paulp@src.gnome.org> | 2009-01-04 22:01:20 +0000 |
commit | d5971581b6aa5ee2d9d0fbbec12f43dd53f4b2db (patch) | |
tree | 78bd5148d5a76c1e346cbbe3d333e77aea14ae7c | |
parent | 9359060516f5dfea236fbf147815e48d54dac18a (diff) | |
download | pygobject-d5971581b6aa5ee2d9d0fbbec12f43dd53f4b2db.tar.gz pygobject-d5971581b6aa5ee2d9d0fbbec12f43dd53f4b2db.tar.xz pygobject-d5971581b6aa5ee2d9d0fbbec12f43dd53f4b2db.zip |
Define methods.
2009-01-04 Mads Chr. Olesen <gnome-bugzilla@shiyee.dk>
* gio/gio.defs (gio.File.copy_async, gio.File.copy_finish): Define
methods.
* gio/gfile.override (_wrap_g_file_copy_async): New function.
* tests/test_gio.py (TestFile.test_copy_async): Test the methods.
svn path=/trunk/; revision=990
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | gio/gfile.override | 86 | ||||
-rw-r--r-- | gio/gio.defs | 37 | ||||
-rw-r--r-- | tests/test_gio.py | 25 |
4 files changed, 157 insertions, 0 deletions
@@ -1,3 +1,12 @@ +2009-01-04 Mads Chr. Olesen <gnome-bugzilla@shiyee.dk> + + * gio/gio.defs (gio.File.copy_async, gio.File.copy_finish): Define + methods. + + * gio/gfile.override (_wrap_g_file_copy_async): New function. + + * tests/test_gio.py (TestFile.test_copy_async): Test the methods. + 2009-01-04 Przemysław Grzegorczyk <pgrzegorczyk@gmail.com> Bug 563714 – GNOME Goal: Clean up GLib and GTK+ includes diff --git a/gio/gfile.override b/gio/gfile.override index deb43e8..f484b08 100644 --- a/gio/gfile.override +++ b/gio/gfile.override @@ -579,6 +579,92 @@ _wrap_g_file_copy(PyGObject *self, return PyBool_FromLong(ret); } %% +override g_file_copy_async kwargs +static PyObject * +_wrap_g_file_copy_async(PyGObject *self, + PyObject *args, + PyObject *kwargs) +{ + static char *kwlist[] = { "destination", "callback", "flags", "io_priority", + "user_data", "cancellable", "progress_callback", + "progress_callback_data", NULL }; + PyGIONotify *notify, *progress_callback; + PyObject *py_flags = NULL; + PyGObject *destination = NULL; + PyGObject *py_cancellable = NULL; + GFileCopyFlags flags = G_FILE_COPY_NONE; + int io_priority = G_PRIORITY_DEFAULT; + PyGObject *pycancellable = NULL; + GCancellable *cancellable; + GFileProgressCallback callback = NULL; + + notify = g_slice_new0(PyGIONotify); + progress_callback = g_slice_new0(PyGIONotify); + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "O!O|OiOOOO:File.copy_async", + kwlist, + &PyGFile_Type, + &destination, + ¬ify->callback, + &py_flags, + &io_priority, + ¬ify->data, + &pycancellable, + &progress_callback->callback, + &progress_callback->data + )) + { + g_slice_free(PyGIONotify, notify); + g_slice_free(PyGIONotify, progress_callback); + return NULL; + } + + if (!pygio_check_cancellable(py_cancellable, &cancellable)) + return NULL; + if (progress_callback->callback != NULL) + { + if (!PyCallable_Check(progress_callback->callback)) + { + PyErr_SetString(PyExc_TypeError, "progress_callback argument not callable"); + g_slice_free(PyGIONotify, notify); + g_slice_free(PyGIONotify, progress_callback); + return NULL; + } + callback = (GFileProgressCallback)file_progress_callback_marshal; + Py_INCREF(progress_callback->callback); + Py_XINCREF(progress_callback->data); + } + if (!PyCallable_Check(notify->callback)) + { + PyErr_SetString(PyExc_TypeError, "callback argument not callable"); + Py_DECREF(progress_callback->callback); + Py_XDECREF(progress_callback->data); + g_slice_free(PyGIONotify, notify); + g_slice_free(PyGIONotify, progress_callback); + return NULL; + } + Py_INCREF(notify->callback); + Py_XINCREF(notify->data); + + + if (!pygio_check_cancellable(pycancellable, &cancellable)) + return NULL; + + g_file_copy_async(G_FILE(self->obj), + G_FILE(destination->obj), + flags, + io_priority, + cancellable, + callback, + progress_callback, + (GAsyncReadyCallback)async_result_callback_marshal, + notify); + + Py_INCREF(Py_None); + return Py_None; +} +%% override g_file_move kwargs static PyObject * _wrap_g_file_move(PyGObject *self, diff --git a/gio/gio.defs b/gio/gio.defs index ce4ee5a..3c84048 100644 --- a/gio/gio.defs +++ b/gio/gio.defs @@ -1788,6 +1788,43 @@ ) ) +(define-method copy_async + (of-object "GFile") + (docstring + "F.copy_async(destination, callback, [flags, io_priority, user_data, cancellable, progress_callback])\n" + "-> start copy\n" + "\n" + "For more details, see gio.File.copy() which is the synchronous\n" + "version of this call. Asynchronously copies file.\n" + "When the operation is finished, callback will be called.\n" + "You can then call g_file_copy_finish() to get the result of the\n" + "operation.\n" + ) + (c-name "g_file_copy_async") + (return-type "none") + (parameters + '("GFile*" "destination") + '("GFileCopyFlags" "flags" (default "G_FILE_COPY_NONE")) + '("int" "io_priority" (default "G_PRIORITY_DEFAULT")) + '("GCancellable*" "cancellable" (null-ok) (default "NULL")) + '("GFileProgressCallback" "progress_callback") + '("gpointer" "progress_callback_data") + '("GAsyncReadyCallback" "callback") + '("gpointer" "user_data") + ) +) + +(define-method copy_finish + (of-object "GFile") + (c-name "g_file_copy_finish") + (return-type "gboolean") + (parameters + '("GAsyncResult*" "res") + '("GError**" "error") + ) +) + + (define-method move (docstring "F.move(destination, [callback, flags, cancellable, user_data])\n" diff --git a/tests/test_gio.py b/tests/test_gio.py index c4e9125..10ef6ac 100644 --- a/tests/test_gio.py +++ b/tests/test_gio.py @@ -295,6 +295,31 @@ class TestFile(unittest.TestCase): finally: os.unlink("copy.txt") + def test_copy_async(self): + if os.path.exists('copy.txt'): + os.unlink("copy.txt") + + source = gio.File('file.txt') + destination = gio.File('copy.txt') + + def copied(source_, result): + self.assert_(source_ is source) + self.failUnless(source_.copy_finish(result)) + + def progress(current, total): + self.assert_(isinstance(current, long)) + self.assert_(isinstance(total, long)) + self.assert_(0 <= current <= total) + + try: + source.copy_async(destination, copied, progress_callback = progress) + + self.failUnless(os.path.exists('copy.txt')) + self.assertEqual(open('file.txt').read(), + open('copy.txt').read()) + finally: + os.unlink("copy.txt") + # See bug 546591. def test_copy_progress(self): source = gio.File('file.txt') |