diff options
| author | Johan Dahlin <johan@src.gnome.org> | 2008-07-18 20:21:22 +0000 |
|---|---|---|
| committer | Johan Dahlin <johan@src.gnome.org> | 2008-07-18 20:21:22 +0000 |
| commit | 4287c2cc70b02930ed64e9cbec2a0c886ac5d3b7 (patch) | |
| tree | 2deb5a2d0b96e4d3e8635d3c9bc65903bad91114 | |
| parent | f0e9c1f49c718a34986cf74821f5ef809217c65c (diff) | |
| download | pygobject-4287c2cc70b02930ed64e9cbec2a0c886ac5d3b7.tar.gz pygobject-4287c2cc70b02930ed64e9cbec2a0c886ac5d3b7.tar.xz pygobject-4287c2cc70b02930ed64e9cbec2a0c886ac5d3b7.zip | |
Wrap gio.File.enumerate_children_async, add tests, docstring and an
* examples/gio/directory-async.py:
* gio/gfile.override:
* gio/gfileenumerator.override:
* gio/gio.defs:
* tests/test_gio.py:
Wrap gio.File.enumerate_children_async, add tests, docstring
and an example.
Also document gio.File.enumerate while we're at it.
svn path=/trunk/; revision=828
| -rw-r--r-- | ChangeLog | 11 | ||||
| -rw-r--r-- | examples/gio/directory-async.py | 14 | ||||
| -rw-r--r-- | gio/gfile.override | 66 | ||||
| -rw-r--r-- | gio/gfileenumerator.override | 7 | ||||
| -rw-r--r-- | gio/gio.defs | 33 | ||||
| -rw-r--r-- | tests/test_gio.py | 30 |
6 files changed, 150 insertions, 11 deletions
@@ -1,5 +1,16 @@ 2008-07-18 Johan Dahlin <johan@gnome.org> + * examples/gio/directory-async.py: + * gio/gfile.override: + * gio/gfileenumerator.override: + * gio/gio.defs: + * tests/test_gio.py: + Wrap gio.File.enumerate_children_async, add tests, docstring + and an example. + Also document gio.File.enumerate while we're at it. + +2008-07-18 Johan Dahlin <johan@gnome.org> + * gio/gfile.override: Use %zd instead of %d since it's a Py_ssize_t and not an int. diff --git a/examples/gio/directory-async.py b/examples/gio/directory-async.py new file mode 100644 index 0000000..30e22e3 --- /dev/null +++ b/examples/gio/directory-async.py @@ -0,0 +1,14 @@ +import gobject +import gio +import gtk + +def callback(gfile, result): + for file_info in gfile.enumerate_children_finish(result): + print file_info.get_name() + loop.quit() + +gfile = gio.File("/") +gfile.enumerate_children_async("standard::*", callback) + +loop = gobject.MainLoop() +loop.run() diff --git a/gio/gfile.override b/gio/gfile.override index 2d299ab..4a12e0d 100644 --- a/gio/gfile.override +++ b/gio/gfile.override @@ -200,9 +200,9 @@ _wrap_g_file_load_contents_async(PyGObject *self, return NULL; g_file_load_contents_async(G_FILE(self->obj), - cancellable, - (GAsyncReadyCallback)async_result_callback_marshal, - notify); + cancellable, + (GAsyncReadyCallback)async_result_callback_marshal, + notify); Py_INCREF(Py_None); return Py_None; @@ -242,9 +242,67 @@ _wrap_g_file_load_contents_finish(PyGObject *self, return Py_None; } } +%% +override g_file_enumerate_children_async kwargs +static PyObject * +_wrap_g_file_enumerate_children_async(PyGObject *self, PyObject *args, PyObject *kwargs) +{ + static char *kwlist[] = { "attributes", "flags", "callback", + "io_priority", "cancellable", "user_data", NULL }; + PyGAsyncRequestNotify *notify; + char *attributes; + PyObject *py_flags = NULL; + int io_priority = G_PRIORITY_DEFAULT; + GFileQueryInfoFlags flags = G_FILE_QUERY_INFO_NONE; + GCancellable *cancellable = NULL; + PyGObject *py_cancellable = NULL; + + notify = g_slice_new0(PyGAsyncRequestNotify); + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "sO|OiOO:GFile.enumerate_children_async", + kwlist, + &attributes, + ¬ify->callback, + &py_flags, + &io_priority, + &py_cancellable, + ¬ify->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_FILE_QUERY_INFO_FLAGS, + py_flags, (gpointer)&flags)) + return NULL; + + if (!pygio_check_cancellable(py_cancellable, &cancellable)) + return NULL; + + g_file_enumerate_children_async(G_FILE(self->obj), + attributes, + flags, + io_priority, + (GCancellable *) cancellable, + (GAsyncReadyCallback)async_result_callback_marshal, + notify); + + Py_INCREF(Py_None); + return Py_None; +} + /* GFile.append_to_async */ /* GFile.create_async */ -/* GFile.enumerate_children_async */ /* GFile.eject_mountable */ /* GFile.find_enclosing_mount_async */ /* GFile.mount_enclosing_volume */ diff --git a/gio/gfileenumerator.override b/gio/gfileenumerator.override index 0dc9b11..8263cdb 100644 --- a/gio/gfileenumerator.override +++ b/gio/gfileenumerator.override @@ -24,6 +24,7 @@ override-slot GFileEnumerator.tp_iter static PyObject* _wrap_g_file_enumerator_tp_iter(PyGObject *self) { + Py_INCREF (self); return (PyObject *) self; } %% @@ -34,12 +35,18 @@ _wrap_g_file_enumerator_tp_iternext(PyGObject *iter) GFileInfo *file_info; GError *error = NULL; + if (!iter->obj) { + PyErr_SetNone(PyExc_StopIteration); + return NULL; + } + file_info = g_file_enumerator_next_file(G_FILE_ENUMERATOR(iter->obj), NULL, &error); if (pyg_error_check(&error)) { return NULL; } + if (!file_info) { PyErr_SetNone(PyExc_StopIteration); return NULL; diff --git a/gio/gio.defs b/gio/gio.defs index 49fc12b..25b8aa9 100644 --- a/gio/gio.defs +++ b/gio/gio.defs @@ -1499,6 +1499,27 @@ ) (define-method enumerate_children + (docstring +"F.enumerate_children(attributes, [flags, cancellable]) -> enumerator\n" +"Gets the requested information about the files in a directory.\n" +"The result is a gio.FileEnumerator object that will give out gio.FileInfo\n" +"objects for all the files in the directory.\n" +"The attribute value is a string that specifies the file attributes that\n" +"should be gathered. It is not an error if it's not possible to read a \n" +"particular requested attribute from a file - it just won't be set.\n" +"attribute should be a comma-separated list of attribute or attribute\n" +"wildcards. The wildcard \"*\" means all attributes, and a wildcard like\n" +"\"standard::*\" means all attributes in the standard namespace.\n" +"An example attribute query be \"standard::*,owner::user\". The standard\n" +"attributes are available as defines, like gio.FILE_ATTRIBUTE_STANDARD_NAME.\n" +"\n" +"If cancellable is not None, then the operation can be cancelled by\n" +"triggering the cancellable object from another thread. If the operation was\n" +"cancelled, the error gio.ERROR_CANCELLED will be returned.\n" +"\n" +"If the file does not exist, the gio.ERROR_NOT_FOUND error will be returned.\n" +"If the file is not a directory, the gio.FILE_ERROR_NOTDIR error will\n" +"be returned. Other errors are possible too.") (of-object "GFile") (c-name "g_file_enumerate_children") (return-type "GFileEnumerator*") @@ -1511,6 +1532,18 @@ ) (define-method enumerate_children_async + (docstring +"F.enumerate_children_async(attributes, callback,\n" +" [flags, io_priority, cancellable, user_data])\n" +"Asynchronously gets the requested information about the files in a directory.\n" +"The result is a GFileEnumerator object that will give out GFileInfo objects\n" +"for all the files in the directory.\n" +"\n" +"For more details, see gio.File.enumerate_children() which is the synchronous\n" +"version of this call.\n" +"\n" +"When the operation is finished, callback will be called. You can then call\n" +"gio.File.enumerate_children_finish() to get the result of the operation.") (of-object "GFile") (c-name "g_file_enumerate_children_async") (return-type "none") diff --git a/tests/test_gio.py b/tests/test_gio.py index 7f33137..df82e36 100644 --- a/tests/test_gio.py +++ b/tests/test_gio.py @@ -61,7 +61,7 @@ class TestFile(unittest.TestCase): self.assertRaises(TypeError, gio.File, foo="bar") self.assertRaises(TypeError, gio.File, uri=1) self.assertRaises(TypeError, gio.File, path=1) - + def testLoadContents(self): self._f.write("testing load_contents") self._f.seek(0) @@ -70,11 +70,11 @@ class TestFile(unittest.TestCase): self.assertEqual(cont, "testing load_contents") self.assertEqual(leng, 21) self.assertNotEqual(etag, '') - + def testLoadContentsAsync(self): self._f.write("testing load_contents_async") self._f.seek(0) - + def callback(contents, result): try: cont, leng, etag = contents.load_contents_finish(result) @@ -83,10 +83,10 @@ class TestFile(unittest.TestCase): self.assertNotEqual(etag, '') finally: loop.quit() - + canc = gio.Cancellable() self.file.load_contents_async(callback, cancellable=canc) - + loop = gobject.MainLoop() loop.run() @@ -103,6 +103,22 @@ class TestGFileEnumerator(unittest.TestCase): else: raise AssertionError + def testEnumerateChildrenAsync(self): + def callback(gfile, result): + try: + for file_info in gfile.enumerate_children_finish(result): + if file_info.get_name() == 'test_gio.py': + break + else: + raise AssertionError + finally: + loop.quit() + + self.file.enumerate_children_async( + "standard::*", callback) + loop = gobject.MainLoop() + loop.run() + class TestInputStream(unittest.TestCase): def setUp(self): @@ -264,14 +280,14 @@ class TestVolumeMonitor(unittest.TestCase): self.failUnless(isinstance(mounts, list)) if not mounts: return - + self.failUnless(isinstance(mounts[0], gio.Mount)) # Bug 538601 icon = mounts[0].get_icon() if not icon: return self.failUnless(isinstance(icon, gio.Icon)) - + class TestThemedIcon(unittest.TestCase): def setUp(self): |
