pygobject r837 - in trunk: . gio tests



Author: johan
Date: Sat Jul 19 11:40:22 2008
New Revision: 837
URL: http://svn.gnome.org/viewvc/pygobject?rev=837&view=rev

Log:
2008-07-19  Johan Dahlin  <johan gnome org>

        * gio/gfile.override:
        * gio/gio.defs:
        * gio/gio.override:
        * tests/test_gio.py:
        Bind gio.Mount.unmount, gio.File.mount_mountable,
        gio.File.unmount_mountable and gio.File.mount_enclosing_volume.
        Add documents and tests.



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

Modified: trunk/gio/gfile.override
==============================================================================
--- trunk/gio/gfile.override	(original)
+++ trunk/gio/gfile.override	Sat Jul 19 11:40:22 2008
@@ -300,19 +300,189 @@
     Py_INCREF(Py_None);
     return Py_None;
 }
+%%
+override g_file_mount_mountable kwargs
+static PyObject *
+_wrap_g_file_mount_mountable(PyGObject *self,
+			     PyObject *args,
+			     PyObject *kwargs)
+{
+    static char *kwlist[] = { "callback", "flags", "mount_operation",
+			      "cancellable", "user_data", NULL };
+    PyGAsyncRequestNotify *notify;
+    PyObject *py_flags = NULL;
+    PyGObject *mount_operation;
+    PyGObject *py_cancellable = NULL;
+    GMountMountFlags flags = G_MOUNT_MOUNT_NONE;
+    GCancellable *cancellable;
+  
+    notify = g_slice_new0(PyGAsyncRequestNotify);
+    
+    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+                                     "O!O|OOO:File.mount_mountable",
+				     kwlist,
+				     &PyGMountOperation_Type,
+				     &mount_operation,
+				     &notify->callback,
+				     &py_flags,
+				     &py_cancellable,
+				     &notify->data))
+            
+    {
+      g_slice_free(PyGAsyncRequestNotify, notify);
+      return NULL;
+    }
+
+    if (!PyCallable_Check(notify->callback))
+    {
+	PyErr_SetString(PyExc_TypeError, "callback argument not callable");
+	g_slice_free(PyGAsyncRequestNotify, notify);
+	return NULL;
+    }
+    Py_INCREF(notify->callback);
+    Py_XINCREF(notify->data);
+  
+    if (py_flags && pyg_flags_get_value(G_TYPE_MOUNT_MOUNT_FLAGS,
+					py_flags, (gpointer)&flags))
+        return NULL;
+
+    if (!pygio_check_cancellable(py_cancellable, &cancellable))
+        return NULL;
+
+    g_file_mount_mountable(G_FILE(self->obj),
+			   flags,
+			   G_MOUNT_OPERATION(mount_operation->obj),
+			   cancellable,
+			   (GAsyncReadyCallback)async_result_callback_marshal,
+			   notify);
+
+    Py_INCREF(Py_None);
+    return Py_None;
+}
+%%
+override g_file_unmount_mountable kwargs
+static PyObject *
+_wrap_g_file_unmount_mountable(PyGObject *self,
+			     PyObject *args,
+			     PyObject *kwargs)
+{
+    static char *kwlist[] = { "callback", "flags",
+			      "cancellable", "user_data", NULL };
+    PyGAsyncRequestNotify *notify;
+    PyObject *py_flags = NULL;
+    PyGObject *py_cancellable = NULL;
+    GMountMountFlags flags = G_MOUNT_MOUNT_NONE;
+    GCancellable *cancellable;
+  
+    notify = g_slice_new0(PyGAsyncRequestNotify);
+    
+    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+                                     "O|OOO:File.unmount_mountable",
+				     kwlist,
+				     &notify->callback,
+				     &py_flags,
+				     &py_cancellable,
+				     &notify->data))
+            
+    {
+      g_slice_free(PyGAsyncRequestNotify, notify);
+      return NULL;
+    }
+
+    if (!PyCallable_Check(notify->callback))
+    {
+	PyErr_SetString(PyExc_TypeError, "callback argument not callable");
+	g_slice_free(PyGAsyncRequestNotify, notify);
+	return NULL;
+    }
+    Py_INCREF(notify->callback);
+    Py_XINCREF(notify->data);
+  
+    if (py_flags && pyg_flags_get_value(G_TYPE_MOUNT_MOUNT_FLAGS,
+					py_flags, (gpointer)&flags))
+        return NULL;
+
+    if (!pygio_check_cancellable(py_cancellable, &cancellable))
+        return NULL;
+
+    g_file_unmount_mountable(G_FILE(self->obj),
+			     flags,
+			     cancellable,
+			     (GAsyncReadyCallback)async_result_callback_marshal,
+			     notify);
+
+    Py_INCREF(Py_None);
+    return Py_None;
+}
+%%
+override g_file_mount_enclosing_volume kwargs
+static PyObject *
+_wrap_g_file_mount_enclosing_volume(PyGObject *self,
+				    PyObject *args,
+				    PyObject *kwargs)
+{
+    static char *kwlist[] = { "callback", "flags", "mount_operation",
+			      "cancellable", "user_data", NULL };
+    PyGAsyncRequestNotify *notify;
+    PyObject *py_flags = NULL;
+    PyGObject *mount_operation;
+    PyGObject *py_cancellable = NULL;
+    GMountMountFlags flags = G_MOUNT_MOUNT_NONE;
+    GCancellable *cancellable;
+  
+    notify = g_slice_new0(PyGAsyncRequestNotify);
+    
+    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+                                     "O!O|OOO:File.mount_enclosing_volume",
+				     kwlist,
+				     &PyGMountOperation_Type,
+				     &mount_operation,
+				     &notify->callback,
+				     &py_flags,
+				     &py_cancellable,
+				     &notify->data))
+            
+    {
+      g_slice_free(PyGAsyncRequestNotify, notify);
+      return NULL;
+    }
+
+    if (!PyCallable_Check(notify->callback))
+    {
+	PyErr_SetString(PyExc_TypeError, "callback argument not callable");
+	g_slice_free(PyGAsyncRequestNotify, notify);
+	return NULL;
+    }
+    Py_INCREF(notify->callback);
+    Py_XINCREF(notify->data);
+  
+    if (py_flags && pyg_flags_get_value(G_TYPE_MOUNT_MOUNT_FLAGS,
+					py_flags, (gpointer)&flags))
+        return NULL;
+
+    if (!pygio_check_cancellable(py_cancellable, &cancellable))
+        return NULL;
+
+    g_file_mount_enclosing_volume(G_FILE(self->obj),
+				  flags,
+				  G_MOUNT_OPERATION(mount_operation->obj),
+				  cancellable,
+				  (GAsyncReadyCallback)async_result_callback_marshal,
+				  notify);
+
+    Py_INCREF(Py_None);
+    return Py_None;
+}
 
 /* GFile.append_to_async */
 /* GFile.create_async */
 /* GFile.eject_mountable */
 /* GFile.find_enclosing_mount_async */
-/* GFile.mount_enclosing_volume */
-/* GFile.mount_mountable */
 /* GFile.query_info_async */
 /* GFile.replace_async */
 /* GFile.replace_contents_async */
 /* GFile.set_attributes_async */
 /* GFile.set_display_name_async */
-/* GFile.unmount_mountable */
 /* GFile.load_partial_contents_async: No ArgType for GFileReadMoreCallback */
 /* GFile.copy: No ArgType for GFileProgressCallback */
 /* GFile.move: No ArgType for GFileProgressCallback */

Modified: trunk/gio/gio.defs
==============================================================================
--- trunk/gio/gio.defs	(original)
+++ trunk/gio/gio.defs	Sat Jul 19 11:40:22 2008
@@ -1843,6 +1843,19 @@
 )
 
 (define-method mount_enclosing_volume
+  (docstring
+"F.mount_enclosing_volume(mount_operaetion, callback, cancellable, user_data])\n"
+"Starts a mount_operation, mounting the volume that contains\n"
+"the file location.\n"
+"\n"
+"When this operation has completed, callback will be called with\n"
+"user_user data, and the operation can be finalized with\n"
+"gio.File.mount_enclosing_volume_finish().\n"
+"\n"
+"If cancellable is not None, then the operation can be cancelled\n"
+"by triggering the cancellable object from another thread.\n"
+"If the operation was cancelled, the error gio.ERROR_CANCELLED\n"
+"will be returned.")
   (of-object "GFile")
   (c-name "g_file_mount_enclosing_volume")
   (return-type "none")
@@ -1865,6 +1878,18 @@
 )
 
 (define-method mount_mountable
+  (docstring 
+"F.mount_mountable(mount_operation, callback, [flags, cancellable, user_data])\n" 
+"Mounts a file of type gio.FILE_TYPE_MOUNTABLE. Using mount_operation,\n"
+"you can request callbacks when, for instance, passwords are needed\n"
+"during authentication.\n"
+"\n"
+"If cancellable is not None, then the operation can be cancelled by\n"
+" triggering the cancellable object from another thread. If the\n"
+"operation was cancelled, the error gio.ERROR_CANCELLED will be returned.\n"
+"\n"
+"When the operation is finished, callback will be called. You can then\n"
+"call g_file_mount_mountable_finish() to get the result of the operation.\n")
   (of-object "GFile")
   (c-name "g_file_mount_mountable")
   (return-type "none")
@@ -1887,6 +1912,17 @@
 )
 
 (define-method unmount_mountable
+  (docstring
+"F.unmount_mountable(callback, [flags, cancellable, user_data])\n"
+"Unmounts a file of type gio.FILE_TYPE_MOUNTABLE.\n"
+"\n"
+"If cancellable is not None, then the operation can be cancelled by\n"
+"triggering the cancellable object from another thread. If the\n"
+"operation was cancelled, the error gio.ERROR_CANCELLED will be returned.\n"
+"\n"
+"When the operation is finished, callback will be called. You can\n"
+"then call g_file_unmount_mountable_finish() to get the\n"
+"result of the operation.\n")
   (of-object "GFile")
   (c-name "g_file_unmount_mountable")
   (return-type "none")
@@ -3435,6 +3471,12 @@
 )
 
 (define-method unmount
+  (docstring
+"M.unmount(callback, [flags, cancellable, user_data])\n"
+"Unmounts a mount. This is an asynchronous operation, and is finished\n"
+"by calling gio.Mount.unmount_finish() with the mount and gio.AsyncResults\n"
+"data returned in the callback."
+)
   (of-object "GMount")
   (c-name "g_mount_unmount")
   (return-type "none")
@@ -3695,10 +3737,10 @@
 "S.write_async(buffer, callback [,io_priority] [,cancellable] [,user_data])\n"
 "\n"
 "Request an asynchronous write of count bytes from buffer into the stream.\n"
-" When the operation is finished callback will be called. You can then call \n"
+"When the operation is finished callback will be called. You can then call\n"
 "gio.OutputStream.write_finish() to get the result of the operation.\n"
 "On success, the number of bytes written will be passed to the callback.\n"
-"It is not an error if this is not the same as the requested size, as it can \n"
+"It is not an error if this is not the same as the requested size, as it can\n"
 "happen e.g. on a partial I/O error, but generally tries to write as many \n"
 "bytes as requested.\n"
 "For the synchronous, blocking version of this function, see "

Modified: trunk/gio/gio.override
==============================================================================
--- trunk/gio/gio.override	(original)
+++ trunk/gio/gio.override	Sat Jul 19 11:40:22 2008
@@ -213,3 +213,58 @@
 			     PyBool_FromLong(result_uncertain));
     return PyString_FromString(type);
 }
+%%
+override g_mount_unmount kwargs
+static PyObject *
+_wrap_g_mount_unmount(PyGObject *self,
+		      PyObject *args,
+		      PyObject *kwargs)
+{
+    static char *kwlist[] = { "callback", "flags",
+			      "cancellable", "user_data", NULL };
+    PyGAsyncRequestNotify *notify;
+    PyObject *py_flags = NULL;
+    PyGObject *py_cancellable = NULL;
+    GMountUnmountFlags flags = G_MOUNT_UNMOUNT_NONE;
+    GCancellable *cancellable;
+  
+    notify = g_slice_new0(PyGAsyncRequestNotify);
+    
+    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+                                     "O|OOO:GMount.unmount",
+				     kwlist,
+				     &notify->callback,
+				     &py_flags,
+				     &py_cancellable,
+				     &notify->data))
+            
+    {
+      g_slice_free(PyGAsyncRequestNotify, notify);
+      return NULL;
+    }
+
+    if (!PyCallable_Check(notify->callback))
+    {
+	PyErr_SetString(PyExc_TypeError, "callback argument not callable");
+	g_slice_free(PyGAsyncRequestNotify, notify);
+	return NULL;
+    }
+    Py_INCREF(notify->callback);
+    Py_XINCREF(notify->data);
+  
+    if (py_flags && pyg_flags_get_value(G_TYPE_MOUNT_UNMOUNT_FLAGS,
+					py_flags, (gpointer)&flags))
+        return NULL;
+
+    if (!pygio_check_cancellable(py_cancellable, &cancellable))
+        return NULL;
+
+    g_mount_unmount(G_MOUNT(self->obj),
+		    flags,
+		    cancellable,
+		    (GAsyncReadyCallback)async_result_callback_marshal,
+		    notify);
+
+    Py_INCREF(Py_None);
+    return Py_None;
+}

Modified: trunk/tests/test_gio.py
==============================================================================
--- trunk/tests/test_gio.py	(original)
+++ trunk/tests/test_gio.py	Sat Jul 19 11:40:22 2008
@@ -90,6 +90,41 @@
         loop = gobject.MainLoop()
         loop.run()
 
+    def testMountMountable(self):
+        gfile = gio.File('localtest:')
+        def unmount_done(mount, result):
+            try:
+                retval = mount.unmount_finish(result)
+                self.failUnless(retval)
+            finally:
+                loop.quit()
+
+        def mount_enclosing_volume_done(gfile, result):
+            try:
+                try:
+                    retval = gfile.mount_enclosing_volume_finish(result)
+                except gobject.GError, e:
+                    # If we run the tests too fast
+                    if (e.domain == gio.ERROR and
+                        e.code == gio.ERROR_ALREADY_MOUNTED):
+                        print ('WARNING: testfile is already mounted, '
+                               'skipping test')
+                        loop.quit()
+                        return
+                    raise
+                self.failUnless(retval)
+            finally:
+                mount = gfile.find_enclosing_mount()
+                mount.unmount(unmount_done)
+
+        mount_operation = gio.MountOperation()
+        gfile.mount_enclosing_volume(mount_operation,
+                                     mount_enclosing_volume_done)
+
+        loop = gobject.MainLoop()
+        loop.run()
+
+
 class TestGFileEnumerator(unittest.TestCase):
     def setUp(self):
         self.file = gio.File(".")
@@ -350,3 +385,4 @@
     def testSimple(self):
         self.assertEquals(self.appinfo.get_description(),
                           "Custom definition for does-not-exist")
+



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