pygobject r990 - in trunk: . gio tests



Author: paulp
Date: Sun Jan  4 22:01:20 2009
New Revision: 990
URL: http://svn.gnome.org/viewvc/pygobject?rev=990&view=rev

Log:
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.


Modified:
   trunk/ChangeLog
   trunk/gio/gfile.override
   trunk/gio/gio.defs
   trunk/tests/test_gio.py

Modified: trunk/gio/gfile.override
==============================================================================
--- trunk/gio/gfile.override	(original)
+++ trunk/gio/gfile.override	Sun Jan  4 22:01:20 2009
@@ -579,6 +579,92 @@
     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,
+                                   &notify->callback,
+				   &py_flags,
+                                   &io_priority,
+                                   &notify->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,

Modified: trunk/gio/gio.defs
==============================================================================
--- trunk/gio/gio.defs	(original)
+++ trunk/gio/gio.defs	Sun Jan  4 22:01:20 2009
@@ -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"

Modified: trunk/tests/test_gio.py
==============================================================================
--- trunk/tests/test_gio.py	(original)
+++ trunk/tests/test_gio.py	Sun Jan  4 22:01:20 2009
@@ -295,6 +295,31 @@
         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')



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]