diff options
author | Gian Mario Tagliaretti <gianmt@src.gnome.org> | 2008-07-29 21:51:43 +0000 |
---|---|---|
committer | Gian Mario Tagliaretti <gianmt@src.gnome.org> | 2008-07-29 21:51:43 +0000 |
commit | 35bf67dec117effae2512c0715d0dea15425d23f (patch) | |
tree | 749571c894c945cf7018fca2562c26dc78d10f8e | |
parent | a831d7702e12e014f7396ee0348159c5361083d2 (diff) | |
download | pygobject-35bf67dec117effae2512c0715d0dea15425d23f.tar.gz pygobject-35bf67dec117effae2512c0715d0dea15425d23f.tar.xz pygobject-35bf67dec117effae2512c0715d0dea15425d23f.zip |
Wrap new object gio.FileAttributeInfo, g_file_set_attribute and g_file_query_settable_attributes methods.
svn path=/trunk/; revision=901
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | gio/Makefile.am | 1 | ||||
-rw-r--r-- | gio/gfile.override | 158 | ||||
-rw-r--r-- | gio/gfileattribute.override | 153 | ||||
-rw-r--r-- | gio/gio.defs | 19 | ||||
-rw-r--r-- | gio/gio.override | 1 | ||||
-rw-r--r-- | tests/test_gio.py | 25 |
7 files changed, 331 insertions, 37 deletions
@@ -1,5 +1,16 @@ 2008-07-29 Gian Mario Tagliaretti <gianmt@gnome.org> + * tests/test_gio.py: + * gio/gfileattribute.override: + * gio/gio.override: + * gio/gio.defs: + * gio/gfile.override: + * gio/Makefile.am: Wrap new object gio.FileAttributeInfo, + g_file_set_attribute and g_file_query_settable_attributes methods. + + +2008-07-29 Gian Mario Tagliaretti <gianmt@gnome.org> + * gio/unix-types.defs: Wrap gio.unix.DesktopAppInfo * gio/gappinfo.override: diff --git a/gio/Makefile.am b/gio/Makefile.am index 6016380..4c57b41 100644 --- a/gio/Makefile.am +++ b/gio/Makefile.am @@ -39,6 +39,7 @@ GIO_OVERRIDES = \ gappinfo.override \ gapplaunchcontext.override \ gfile.override \ + gfileattribute.override \ gfileenumerator.override \ gfileinfo.override \ ginputstream.override \ diff --git a/gio/gfile.override b/gio/gfile.override index 88ae571..b5ecfc8 100644 --- a/gio/gfile.override +++ b/gio/gfile.override @@ -29,7 +29,7 @@ file_progress_callback_marshal(goffset current_num_bytes, { PyObject *ret; PyGILState_STATE state; - + state = pyg_gil_state_ensure(); if (notify->data) @@ -38,7 +38,7 @@ file_progress_callback_marshal(goffset current_num_bytes, total_num_bytes, notify->data); else - ret = PyObject_CallFunction(notify->callback, "(kk)", + ret = PyObject_CallFunction(notify->callback, "(kk)", current_num_bytes, total_num_bytes); @@ -101,7 +101,7 @@ _wrap__file_init(PyGObject *self, PyObject *args, PyObject *kwargs) "s:gio.File", kwlist, &arg)) return NULL; file = g_file_new_for_uri(arg); - } else { + } else { PyErr_Format(PyExc_TypeError, "gio.File() got an unexpected keyword argument '%s'", "unknown"); @@ -134,7 +134,7 @@ _wrap_g_file_read_async(PyGObject *self, PyGObject *pycancellable = NULL; GCancellable *cancellable; PyGIONotify *notify; - + notify = g_slice_new0(PyGIONotify); if (!PyArg_ParseTupleAndKeywords(args, kwargs, @@ -157,16 +157,16 @@ _wrap_g_file_read_async(PyGObject *self, } Py_INCREF(notify->callback); Py_XINCREF(notify->data); - + if (!pygio_check_cancellable(pycancellable, &cancellable)) return NULL; - + g_file_read_async(G_FILE(self->obj), io_priority, cancellable, (GAsyncReadyCallback)async_result_callback_marshal, notify); - + Py_INCREF(Py_None); return Py_None; } @@ -184,7 +184,7 @@ _wrap_g_file_load_contents(PyGObject *self, gsize lenght; GError *error = NULL; gboolean ret; - + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O:File.load_contents", kwlist, @@ -193,7 +193,7 @@ _wrap_g_file_load_contents(PyGObject *self, if (!pygio_check_cancellable(pycancellable, &cancellable)) return NULL; - + ret = g_file_load_contents(G_FILE(self->obj), cancellable, &contents, &lenght, &etag_out, &error); @@ -204,7 +204,7 @@ _wrap_g_file_load_contents(PyGObject *self, return Py_BuildValue("(sks)", contents, lenght, etag_out); else { Py_INCREF(Py_None); - return Py_None; + return Py_None; } } %% @@ -218,16 +218,16 @@ _wrap_g_file_load_contents_async(PyGObject *self, GCancellable *cancellable; PyGObject *pycancellable = NULL; PyGIONotify *notify; - + notify = g_slice_new0(PyGIONotify); - + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|OO:File.load_contents_async", kwlist, ¬ify->callback, &pycancellable, ¬ify->data)) - + { g_slice_free(PyGIONotify, notify); return NULL; @@ -257,7 +257,7 @@ _wrap_g_file_load_contents_finish(PyGObject *self, gsize lenght; GError *error = NULL; gboolean ret; - + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!:File.load_contents_finish", kwlist, @@ -276,7 +276,7 @@ _wrap_g_file_load_contents_finish(PyGObject *self, return Py_BuildValue("(sks)", contents, lenght, etag_out); else { Py_INCREF(Py_None); - return Py_None; + return Py_None; } } %% @@ -318,14 +318,14 @@ _wrap_g_file_enumerate_children_async(PyGObject *self, PyObject *args, PyObject } 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, @@ -333,7 +333,7 @@ _wrap_g_file_enumerate_children_async(PyGObject *self, PyObject *args, PyObject (GCancellable *) cancellable, (GAsyncReadyCallback)async_result_callback_marshal, notify); - + Py_INCREF(Py_None); return Py_None; } @@ -352,9 +352,9 @@ _wrap_g_file_mount_mountable(PyGObject *self, PyGObject *py_cancellable = NULL; GMountMountFlags flags = G_MOUNT_MOUNT_NONE; GCancellable *cancellable; - + notify = g_slice_new0(PyGIONotify); - + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!O|OOO:File.mount_mountable", kwlist, @@ -364,7 +364,7 @@ _wrap_g_file_mount_mountable(PyGObject *self, &py_flags, &py_cancellable, ¬ify->data)) - + { g_slice_free(PyGIONotify, notify); return NULL; @@ -378,7 +378,7 @@ _wrap_g_file_mount_mountable(PyGObject *self, } 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; @@ -410,9 +410,9 @@ _wrap_g_file_unmount_mountable(PyGObject *self, PyGObject *py_cancellable = NULL; GMountMountFlags flags = G_MOUNT_MOUNT_NONE; GCancellable *cancellable; - + notify = g_slice_new0(PyGIONotify); - + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|OOO:File.unmount_mountable", kwlist, @@ -420,7 +420,7 @@ _wrap_g_file_unmount_mountable(PyGObject *self, &py_flags, &py_cancellable, ¬ify->data)) - + { g_slice_free(PyGIONotify, notify); return NULL; @@ -434,7 +434,7 @@ _wrap_g_file_unmount_mountable(PyGObject *self, } 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; @@ -466,9 +466,9 @@ _wrap_g_file_mount_enclosing_volume(PyGObject *self, PyGObject *py_cancellable = NULL; GMountMountFlags flags = G_MOUNT_MOUNT_NONE; GCancellable *cancellable; - + notify = g_slice_new0(PyGIONotify); - + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!O|OOO:File.mount_enclosing_volume", kwlist, @@ -478,7 +478,7 @@ _wrap_g_file_mount_enclosing_volume(PyGObject *self, &py_flags, &py_cancellable, ¬ify->data)) - + { g_slice_free(PyGIONotify, notify); return NULL; @@ -492,7 +492,7 @@ _wrap_g_file_mount_enclosing_volume(PyGObject *self, } 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; @@ -529,9 +529,9 @@ _wrap_g_file_copy(PyGObject *self, int ret; GError *error = NULL; GFileProgressCallback callback = NULL; - + notify = g_slice_new0(PyGIONotify); - + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!|OOOO:File.unmount_mountable", kwlist, @@ -541,7 +541,7 @@ _wrap_g_file_copy(PyGObject *self, &py_flags, &py_cancellable, ¬ify->data)) - + { g_slice_free(PyGIONotify, notify); return NULL; @@ -559,7 +559,7 @@ _wrap_g_file_copy(PyGObject *self, Py_INCREF(notify->callback); } Py_XINCREF(notify->data); - + if (py_flags && pyg_flags_get_value(G_TYPE_FILE_COPY_FLAGS, py_flags, (gpointer)&flags)) return NULL; @@ -580,6 +580,94 @@ _wrap_g_file_copy(PyGObject *self, return PyBool_FromLong(ret); } +%% +override g_file_set_attribute kwargs +static PyObject * +_wrap_g_file_set_attribute(PyGObject *self, PyObject *args, PyObject *kwargs) +{ + static char *kwlist[] = { "attribute", "type", "value_p", + "flags", "cancellable", NULL }; + GFileQueryInfoFlags flags = G_FILE_QUERY_INFO_NONE; + int ret; + GCancellable *cancellable = NULL; + GError *error = NULL; + char *attribute; + PyObject *py_type = NULL, *py_flags = NULL, *value_p; + PyGObject *pycancellable = NULL; + GFileAttributeType type; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs,"sOO|OO:GFile.set_attribute", + kwlist, &attribute, &py_type, &value_p, + &py_flags, &pycancellable)) + return NULL; + + if (pyg_enum_get_value(G_TYPE_FILE_ATTRIBUTE_TYPE, py_type, + (gpointer)&type)) + return NULL; + + if (py_flags && pyg_flags_get_value(G_TYPE_FILE_QUERY_INFO_FLAGS, py_flags, + (gpointer)&flags)) + return NULL; + + if (!pygio_check_cancellable(pycancellable, &cancellable)) + return NULL; + + ret = g_file_set_attribute(G_FILE(self->obj), attribute, type, + (gpointer)value_p, flags, (GCancellable *) + cancellable, &error); + + if (pyg_error_check(&error)) + return NULL; + + return PyBool_FromLong(ret); +} +%% +override g_file_query_settable_attributes kwargs +static PyObject * +_wrap_g_file_query_settable_attributes(PyGObject *self, + PyObject *args, + PyObject *kwargs) +{ + static char *kwlist[] = { "cancellable", NULL }; + PyGObject *pycancellable = NULL; + GCancellable *cancellable = NULL; + GFileAttributeInfoList *ret; + GError *error = NULL; + gint i, n_infos; + GFileAttributeInfo *infos; + PyObject *py_ret; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "|O:GFile.query_settable_attributes", + kwlist, &pycancellable)) + return NULL; + + if (!pygio_check_cancellable(pycancellable, &cancellable)) + return NULL; + + ret = g_file_query_settable_attributes(G_FILE(self->obj), + (GCancellable *) cancellable, + &error); + if (pyg_error_check(&error)) + return NULL; + + n_infos = ret->n_infos; + infos = ret->infos; + + if (n_infos > 0) { + py_ret = PyList_New(n_infos); + for (i = 0; i < n_infos; i++) { + PyList_SetItem(py_ret, i, pyg_file_attribute_info_new(&infos[i])); + } + g_file_attribute_info_list_unref(ret); + return py_ret; + + } else { + Py_INCREF(Py_None); + return Py_None; + } +} + /* GFile.append_to_async */ /* GFile.create_async */ /* GFile.eject_mountable */ @@ -591,9 +679,7 @@ _wrap_g_file_copy(PyGObject *self, /* GFile.set_display_name_async */ /* GFile.load_partial_contents_async: No ArgType for GFileReadMoreCallback */ /* GFile.move: No ArgType for GFileProgressCallback */ -/* GFile.query_settable_attributes: No ArgType for GFileAttributeInfoList* */ /* GFile.query_writable_namespaces: No ArgType for GFileAttributeInfoList* */ -/* GFile.set_attribute: No ArgType for gpointer */ /* GFile.set_attributes_finish: No ArgType for GFileInfo** */ /* GFile.load_partial_contents_finish: No ArgType for char** */ /* GFile.replace_contents: No ArgType for char** */ diff --git a/gio/gfileattribute.override b/gio/gfileattribute.override new file mode 100644 index 0000000..a25d7cd --- /dev/null +++ b/gio/gfileattribute.override @@ -0,0 +1,153 @@ +/* -*- Mode: C; c-basic-offset: 4 -*- + * pygobject - Python bindings for GObject + * Copyright (C) 2008 Gian Mario Tagliaretti + * + * gfileattribute.override: module overrides for GFileAttribute* + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + */ +%% +headers + +extern PyTypeObject PyGFileAttributeInfo_Type; + +typedef struct { + PyObject_HEAD + const GFileAttributeInfo *info; +} PyGFileAttributeInfo; + +static PyObject * +pygio_file_attribute_info_tp_new(PyTypeObject *type) +{ + PyGFileAttributeInfo *self; + GFileAttributeInfo *info = NULL; + + self = (PyGFileAttributeInfo *) PyObject_NEW(PyGFileAttributeInfo, + &PyGFileAttributeInfo_Type); + self->info = info; + return (PyObject *) self; +} + +static PyMethodDef pyg_file_attribute_info_methods[] = { + { NULL, 0, 0 } +}; + +static PyObject * +pyg_file_attribute_info__get_name(PyObject *self, void *closure) +{ + const gchar *ret; + + ret = ((PyGFileAttributeInfo*)self)->info->name; + if (ret) + return PyString_FromString(ret); + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject * +pyg_file_attribute_info__get_type(PyObject *self, void *closure) +{ + gint ret; + + ret = ((PyGFileAttributeInfo*)self)->info->type; + return pyg_enum_from_gtype(G_TYPE_FILE_ATTRIBUTE_TYPE, ret); +} + +static PyObject * +pyg_file_attribute_info__get_flags(PyObject *self, void *closure) +{ + guint ret; + + ret = ((PyGFileAttributeInfo*)self)->info->flags; + return pyg_flags_from_gtype(G_TYPE_FILE_ATTRIBUTE_INFO_FLAGS, ret); +} + +static const PyGetSetDef pyg_file_attribute_info_getsets[] = { + { "name", (getter)pyg_file_attribute_info__get_name, (setter)0 }, + { "type", (getter)pyg_file_attribute_info__get_type, (setter)0 }, + { "flags", (getter)pyg_file_attribute_info__get_flags, (setter)0 }, + { NULL, (getter)0, (setter)0 }, +}; + +PyTypeObject PyGFileAttributeInfo_Type = { + PyObject_HEAD_INIT(NULL) + 0, /* ob_size */ + "gio.FileAttributeInfo", /* tp_name */ + sizeof(PyGFileAttributeInfo), /* tp_basicsize */ + 0, /* tp_itemsize */ + /* methods */ + (destructor)0, /* tp_dealloc */ + (printfunc)0, /* tp_print */ + (getattrfunc)0, /* tp_getattr */ + (setattrfunc)0, /* tp_setattr */ + (cmpfunc)0, /* tp_compare */ + (reprfunc)0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + (hashfunc)0, /* tp_hash */ + (ternaryfunc)0, /* tp_call */ + (reprfunc)0, /* tp_str */ + (getattrofunc)0, /* tp_getattro */ + (setattrofunc)0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT, /* tp_flags */ + "Holds information about an attribute", /* Documentation string */ + (traverseproc)0, /* tp_traverse */ + (inquiry)0, /* tp_clear */ + (richcmpfunc)0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + (getiterfunc)0, /* tp_iter */ + (iternextfunc)0, /* tp_iternext */ + (struct PyMethodDef*)pyg_file_attribute_info_methods, /* tp_methods */ + 0, /* tp_members */ + (struct PyGetSetDef*)pyg_file_attribute_info_getsets, /* tp_getset */ + (PyTypeObject *)0, /* tp_base */ + (PyObject *)0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)0, /* tp_init */ + 0, /* tp_alloc */ + (newfunc)pygio_file_attribute_info_tp_new, /* tp_new */ + 0, /* tp_free */ + (inquiry)0, /* tp_is_gc */ + (PyObject *)0, /* tp_bases */ +}; + +PyObject* +pyg_file_attribute_info_new(const GFileAttributeInfo *info) +{ + PyGFileAttributeInfo *self; + + self = (PyGFileAttributeInfo *)PyObject_NEW(PyGFileAttributeInfo, + &PyGFileAttributeInfo_Type); + if (G_UNLIKELY(self == NULL)) + return NULL; + if (info) + self->info = info; + return (PyObject *)self; +} + +%% +init +if (PyType_Ready(&PyGFileAttributeInfo_Type) < 0) { + g_return_if_reached(); +} +if (PyDict_SetItemString(d, "FileAttributeInfo", + (PyObject *)&PyGFileAttributeInfo_Type) < 0) { + g_return_if_reached(); +} diff --git a/gio/gio.defs b/gio/gio.defs index c234978..791caff 100644 --- a/gio/gio.defs +++ b/gio/gio.defs @@ -1758,6 +1758,17 @@ ) (define-method query_settable_attributes + (docstring + "F.query_settable_attributes([cancellable]) -> list\n\n" + "Obtain the list of settable attributes for the file.\n" + "Returns the type and full attribute name of all the attributes that\n" + "can be set on this file. This doesn't mean setting it will always\n" + "succeed though, you might get an access failure, or some specific\n" + "file may not support a specific attribute.\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\n" + "was cancelled, the error gio.IO_ERROR_CANCELLED will be returned." + ) (of-object "GFile") (c-name "g_file_query_settable_attributes") (return-type "GFileAttributeInfoList*") @@ -1778,6 +1789,14 @@ ) (define-method set_attribute + (docstring + "F.set_attribute(attribute, type, value_p [,flags [,cancellable ]])->bool\n" + "\n" + "Sets an attribute in the file with attribute name attribute to value_p.\n" + "If cancellable is not None, then the operation can be cancelled by\n" + "triggering the cancellable object from another thread. If the operation\n" + "was cancelled, the error gio.IO_ERROR_CANCELLED will be returned." + ) (of-object "GFile") (c-name "g_file_set_attribute") (return-type "gboolean") diff --git a/gio/gio.override b/gio/gio.override index 66a44df..9146ba3 100644 --- a/gio/gio.override +++ b/gio/gio.override @@ -82,6 +82,7 @@ include gappinfo.override gapplaunchcontext.override gfile.override + gfileattribute.override gfileenumerator.override gfileinfo.override ginputstream.override diff --git a/tests/test_gio.py b/tests/test_gio.py index 92ffb47..4acb387 100644 --- a/tests/test_gio.py +++ b/tests/test_gio.py @@ -159,6 +159,30 @@ class TestFile(unittest.TestCase): finally: os.unlink("copy.txt") + def testInfoList(self): + infolist = self.file.query_settable_attributes() + for info in infolist: + if info.name == "time::modified": + self.assertEqual(info.type, gio.FILE_ATTRIBUTE_TYPE_UINT64) + self.assertEqual(info.name, "time::modified") + self.assertEqual(info.flags, + gio.FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED) + + def testSetAttribute(self): + self._f.write("testing attributes") + self._f.seek(0) + infolist = self.file.query_settable_attributes() + + self.assertNotEqual(len(infolist), 0) + + for info in infolist: + if info.name == "time::modified-usec": + ret = self.file.set_attribute("time::modified-usec", + gio.FILE_ATTRIBUTE_TYPE_UINT32, + 10, gio.FILE_QUERY_INFO_NONE) + self.assertEqual(ret, True) + + class TestGFileEnumerator(unittest.TestCase): def setUp(self): self.file = gio.File(".") @@ -419,4 +443,3 @@ class TestAppInfo(unittest.TestCase): def testSimple(self): self.assertEquals(self.appinfo.get_description(), "Custom definition for does-not-exist") - |