summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGian Mario Tagliaretti <gianmt@src.gnome.org>2008-08-03 20:11:13 +0000
committerGian Mario Tagliaretti <gianmt@src.gnome.org>2008-08-03 20:11:13 +0000
commit9d36ba462c82a52ef41a9e1a3d3e849d8430a129 (patch)
tree1a45e4ee87524834fce0608791a1f635a7d76df9
parentcc630ab67b9483f9c3c71ffa2ecffee7d61bed8c (diff)
downloadpygobject-9d36ba462c82a52ef41a9e1a3d3e849d8430a129.tar.gz
pygobject-9d36ba462c82a52ef41a9e1a3d3e849d8430a129.tar.xz
pygobject-9d36ba462c82a52ef41a9e1a3d3e849d8430a129.zip
Wrap GFile.replace_async and query_info_async with docs and test.
svn path=/trunk/; revision=923
-rw-r--r--ChangeLog9
-rw-r--r--gio/gfile.override97
-rw-r--r--gio/gio.defs20
-rw-r--r--tests/test_gio.py57
4 files changed, 181 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 8522a24..6909e12 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2008-08-03 Gian Mario Tagliaretti <gianmt@gnome.org>
+
+ Bug 546046 – Wrap GFile.replace_async and query_info_async
+
+ * tests/test_gio.py:
+ * gio/gfile.override:
+ * gio/gio.defs:
+ Wrap GFile.replace_async and query_info_async with docs and test.
+
2008-08-03 Paul Pogonyshev <pogonyshev@gmx.net>
* glib/pyglib.h:
diff --git a/gio/gfile.override b/gio/gfile.override
index fb8d41c..19d8681 100644
--- a/gio/gfile.override
+++ b/gio/gfile.override
@@ -869,11 +869,104 @@ _wrap_g_file_create_async(PyGObject *self, PyObject *args, PyObject *kwargs)
Py_INCREF(Py_None);
return Py_None;
}
+%%
+override g_file_replace_async kwargs
+static PyObject *
+_wrap_g_file_replace_async(PyGObject *self, PyObject *args, PyObject *kwargs)
+{
+ static char *kwlist[] = { "callback", "etag", "make_backup", "flags",
+ "io_priority", "cancellable", "user_data", NULL };
+ GCancellable *cancellable;
+ PyGObject *pycancellable = NULL;
+ GFileCreateFlags flags = G_FILE_CREATE_NONE;
+ PyObject *py_flags = NULL;
+ int io_priority = G_PRIORITY_DEFAULT;
+ char *etag = NULL;
+ gboolean make_backup = TRUE;
+ PyObject *py_backup = Py_True;
+ PyGIONotify *notify;
+
+ notify = g_slice_new0(PyGIONotify);
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+ "O|zOOiOO:File.replace_async",
+ kwlist,
+ &notify->callback,
+ &etag, &py_backup,
+ &flags, &io_priority,
+ &pycancellable,
+ &notify->data))
+ {
+ g_slice_free(PyGIONotify, notify);
+ return NULL;
+ }
+
+ make_backup = PyObject_IsTrue(py_backup) ? TRUE : FALSE;
+
+ if (py_flags && pyg_flags_get_value(G_TYPE_FILE_CREATE_FLAGS,
+ py_flags, (gpointer)&flags))
+ return NULL;
+
+ if (!pygio_check_cancellable(pycancellable, &cancellable))
+ return NULL;
+
+ g_file_replace_async(G_FILE(self->obj), etag, make_backup, flags,
+ io_priority, cancellable,
+ (GAsyncReadyCallback)async_result_callback_marshal,
+ notify);
+
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+%%
+override g_file_query_info_async kwargs
+static PyObject *
+_wrap_g_file_query_info_async(PyGObject *self, PyObject *args, PyObject *kwargs)
+{
+ static char *kwlist[] = { "callback", "attributes", "flags",
+ "io_priority", "cancellable", "user_data", NULL };
+ GCancellable *cancellable;
+ PyGObject *pycancellable = NULL;
+ GFileQueryInfoFlags flags = G_FILE_QUERY_INFO_NONE;
+ PyObject *py_flags = NULL;
+ int io_priority = G_PRIORITY_DEFAULT;
+ char *attributes;
+ PyGIONotify *notify;
+
+ notify = g_slice_new0(PyGIONotify);
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+ "Os|OiOO:File.query_info_async",
+ kwlist,
+ &notify->callback,
+ &attributes,
+ &flags, &io_priority,
+ &pycancellable,
+ &notify->data))
+
+ {
+ g_slice_free(PyGIONotify, notify);
+ return NULL;
+ }
+
+ if (py_flags && pyg_flags_get_value(G_TYPE_FILE_CREATE_FLAGS,
+ py_flags, (gpointer)&flags))
+ return NULL;
+
+ if (!pygio_check_cancellable(pycancellable, &cancellable))
+ return NULL;
+
+ g_file_query_info_async(G_FILE(self->obj), attributes, flags,
+ io_priority, cancellable,
+ (GAsyncReadyCallback)async_result_callback_marshal,
+ notify);
+
+ Py_INCREF(Py_None);
+ return Py_None;
+}
/* GFile.eject_mountable */
/* GFile.find_enclosing_mount_async */
-/* GFile.query_info_async */
-/* GFile.replace_async */
/* GFile.replace_contents_async */
/* GFile.set_attributes_async */
/* GFile.set_display_name_async */
diff --git a/gio/gio.defs b/gio/gio.defs
index d0e6f2a..0f4b904 100644
--- a/gio/gio.defs
+++ b/gio/gio.defs
@@ -1453,6 +1453,16 @@
)
(define-method replace_async
+ (docstring
+ "F.replace_async(callback [etag, [make_backup, [flags, [io_priority, [cancellable, [user_data]]]]]]) -> file replace\n"
+ "\n"
+ "Asynchronously overwrites the file, replacing the contents, possibly\n"
+ "creating a backup copy of the file first.\n"
+ "For more details, see F.replace() which is the synchronous\n"
+ "version of this call.\n"
+ "When the operation is finished, callback will be called. You can\n"
+ "then call F.replace_finish() to get the result of the operation."
+ )
(of-object "GFile")
(c-name "g_file_replace_async")
(return-type "none")
@@ -1499,6 +1509,16 @@
)
(define-method query_info_async
+ (docstring
+ "F.query_info_async(callback, attributes, [flags, [io_priority, [cancellable, [user_data]]]]) -> query attributes\n\n"
+ "Asynchronously gets the requested information about specified file.\n"
+ "The result is a GFileInfo object that contains key-value attributes\n"
+ "(such as type or size for the file).\n"
+ "For more details, see F.query_info() which is the synchronous\n"
+ "version of this call. \n"
+ "When the operation is finished, callback will be called. You can\n"
+ "then call F.query_info_finish() to get the result of the operation.\n"
+ )
(of-object "GFile")
(c-name "g_file_query_info_async")
(return-type "none")
diff --git a/tests/test_gio.py b/tests/test_gio.py
index d96d9aa..c321076 100644
--- a/tests/test_gio.py
+++ b/tests/test_gio.py
@@ -111,6 +111,49 @@ class TestFile(unittest.TestCase):
loop = glib.MainLoop()
loop.run()
+ def testReplaceAsync(self):
+ self._f.write("testing")
+ self._f.close()
+
+ def callback(file, result):
+ try:
+ stream = file.replace_finish(result)
+ self.failUnless(isinstance(stream, gio.OutputStream))
+ stream.write("some new string")
+ stream.close()
+ cont, leng, etag = file.load_contents()
+ self.assertEqual(cont, "some new string")
+ finally:
+ loop.quit()
+
+
+ self.file.replace_async(callback, None, True, gio.FILE_CREATE_NONE,
+ glib.PRIORITY_HIGH)
+
+ loop = glib.MainLoop()
+ loop.run()
+
+ def testReplaceAsyncNoargs(self):
+ self._f.write("testing")
+ self._f.close()
+
+ def callback(file, result):
+ try:
+ stream = file.replace_finish(result)
+ self.failUnless(isinstance(stream, gio.OutputStream))
+ stream.write("some new string")
+ stream.close()
+ cont, leng, etag = file.load_contents()
+ self.assertEqual(cont, "some new string")
+ finally:
+ loop.quit()
+
+
+ self.file.replace_async(callback)
+
+ loop = glib.MainLoop()
+ loop.run()
+
def testReadAsyncError(self):
self.assertRaises(TypeError, self.file.read_async)
self.assertRaises(TypeError, self.file.read_async, "foo", "bar")
@@ -169,6 +212,20 @@ class TestFile(unittest.TestCase):
loop = glib.MainLoop()
loop.run()
+ def testQueryInfoAsync(self):
+ def callback(file, result):
+ try:
+ info = file.query_info_finish(result)
+ self.failUnless(isinstance(info, gio.FileInfo))
+ self.failUnless(info.get_name(), "file.txt")
+ finally:
+ loop.quit()
+
+ self.file.query_info_async(callback, "standard")
+
+ loop = glib.MainLoop()
+ loop.run()
+
def testMountMountable(self):
gfile = gio.File('localtest:')
def unmount_done(mount, result):