From 7193a0e14e488ef07f723a0b9f490a03fe291650 Mon Sep 17 00:00:00 2001 From: Gian Mario Tagliaretti Date: Sat, 4 Apr 2009 16:13:17 +0000 Subject: Wrap new GFile methods. 2009-04-04 Gian Mario Tagliaretti * gio/gfile.override: (_wrap_g_file_set_attributes_async) (_wrap_g_file_set_attributes_finish) Wrap new GFile methods. * tests/test_gio.py: Test the above methods. svn path=/trunk/; revision=1053 --- ChangeLog | 8 +++++ gio/gfile.override | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- tests/test_gio.py | 18 +++++++++++ 3 files changed, 118 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9e8ce3c..5a999c6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2009-04-04 Gian Mario Tagliaretti + + * gio/gfile.override: + (_wrap_g_file_set_attributes_async) + (_wrap_g_file_set_attributes_finish) Wrap new GFile methods. + + * tests/test_gio.py: Test the above methods. + 2009-03-31 Gian Mario Tagliaretti * gio/gfile.override: diff --git a/gio/gfile.override b/gio/gfile.override index 29ce187..406d62a 100644 --- a/gio/gfile.override +++ b/gio/gfile.override @@ -1422,10 +1422,99 @@ _wrap_g_file_query_filesystem_info_async(PyGObject *self, PyObject *args, PyObje pygio_notify_free(notify); return NULL; } +%% +override g_file_set_attributes_async kwargs +static PyObject * +_wrap_g_file_set_attributes_async(PyGObject *self, + PyObject *args, + PyObject *kwargs) +{ + static char *kwlist[] = { "info", "callback", "flags", + "io_priority", "cancellable", "user_data", NULL }; + PyGObject *info; + PyGIONotify *notify; + GFileQueryInfoFlags flags = G_FILE_QUERY_INFO_NONE; + int io_priority = G_PRIORITY_DEFAULT; + GCancellable *cancellable = NULL; + PyGObject *py_cancellable = NULL; + + notify = pygio_notify_new(); + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "O!O|OiOO:GFile.set_attributes_async", + kwlist, + &PyGFileInfo_Type, + &info, + ¬ify->callback, + &flags, + &io_priority, + &py_cancellable, + ¬ify->data)) + goto error; + + if (!pygio_notify_callback_is_valid(notify)) + goto error; + + + if (!pygio_check_cancellable(py_cancellable, &cancellable)) + goto error; + + pygio_notify_reference_callback(notify); + + g_file_set_attributes_async(G_FILE(self->obj), + G_FILE_INFO(info->obj), + flags, + io_priority, + (GCancellable *) cancellable, + (GAsyncReadyCallback)async_result_callback_marshal, + notify); + + Py_INCREF(Py_None); + return Py_None; + + error: + pygio_notify_free(notify); + return NULL; +} + +%% +override g_file_set_attributes_finish kwargs +static PyObject * +_wrap_g_file_set_attributes_finish(PyGObject *self, + PyObject *args, + PyObject *kwargs) +{ + static char *kwlist[] = { "result", NULL }; + PyGObject *res; + GFileInfo *info = NULL; + GError *error = NULL; + gboolean ret; + PyObject *py_ret; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "O!:File.set_attributes_finish", + kwlist, + &PyGAsyncResult_Type, + &res)) + return NULL; + + ret = g_file_set_attributes_finish(G_FILE(self->obj), + G_ASYNC_RESULT(res->obj), &info, + &error); + + if (pyg_error_check(&error)) + return NULL; + + if (ret) { + py_ret = pygobject_new((GObject *)info); + } else { + py_ret = Py_None; + Py_INCREF(py_ret); + } + + return py_ret; +} -/* GFile.set_attributes_async */ /* GFile.set_display_name_async */ /* GFile.load_partial_contents_async: No ArgType for GFileReadMoreCallback */ -/* GFile.move: No ArgType for GFileProgressCallback */ -/* GFile.set_attributes_finish: No ArgType for GFileInfo** */ /* GFile.load_partial_contents_finish: No ArgType for char** */ diff --git a/tests/test_gio.py b/tests/test_gio.py index e308a2a..6c6faa5 100644 --- a/tests/test_gio.py +++ b/tests/test_gio.py @@ -404,6 +404,24 @@ class TestFile(unittest.TestCase): 10, gio.FILE_QUERY_INFO_NONE) self.assertEqual(ret, True) + def testSetAttributesAsync(self): + def callback(gfile, result): + try: + info = gfile.set_attributes_finish(result) + usec = info.get_attribute_uint32("time::modified-usec") + self.assertEqual(usec, 10) + finally: + loop.quit() + + info = gio.FileInfo() + info.set_attribute_uint32("time::modified-usec", 10) + + canc = gio.Cancellable() + self.file.set_attributes_async(info, callback) + + loop = glib.MainLoop() + loop.run() + def testReplaceContents(self): self.file.replace_contents("testing replace_contents") cont, leng, etag = self.file.load_contents() -- cgit