pygobject r901 - in trunk: . gio tests



Author: gianmt
Date: Tue Jul 29 21:51:43 2008
New Revision: 901
URL: http://svn.gnome.org/viewvc/pygobject?rev=901&view=rev

Log:
Wrap new object gio.FileAttributeInfo, g_file_set_attribute and g_file_query_settable_attributes methods.

Added:
   trunk/gio/gfileattribute.override
Modified:
   trunk/ChangeLog
   trunk/gio/Makefile.am
   trunk/gio/gfile.override
   trunk/gio/gio.defs
   trunk/gio/gio.override
   trunk/tests/test_gio.py

Modified: trunk/gio/Makefile.am
==============================================================================
--- trunk/gio/Makefile.am	(original)
+++ trunk/gio/Makefile.am	Tue Jul 29 21:51:43 2008
@@ -39,6 +39,7 @@
 	gappinfo.override		\
 	gapplaunchcontext.override 	\
 	gfile.override			\
+	gfileattribute.override		\
 	gfileenumerator.override	\
 	gfileinfo.override		\
 	ginputstream.override 		\

Modified: trunk/gio/gfile.override
==============================================================================
--- trunk/gio/gfile.override	(original)
+++ trunk/gio/gfile.override	Tue Jul 29 21:51:43 2008
@@ -29,7 +29,7 @@
 {
     PyObject *ret;
     PyGILState_STATE state;
-    
+
     state = pyg_gil_state_ensure();
 
     if (notify->data)
@@ -38,7 +38,7 @@
 				  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 @@
 					     "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 @@
   PyGObject *pycancellable = NULL;
   GCancellable *cancellable;
   PyGIONotify *notify;
-  
+
   notify = g_slice_new0(PyGIONotify);
 
   if (!PyArg_ParseTupleAndKeywords(args, kwargs,
@@ -157,16 +157,16 @@
     }
   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 @@
     gsize lenght;
     GError *error = NULL;
     gboolean ret;
-    
+
     if (!PyArg_ParseTupleAndKeywords(args, kwargs,
                                      "|O:File.load_contents",
                                       kwlist,
@@ -193,7 +193,7 @@
 
     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 @@
         return Py_BuildValue("(sks)", contents, lenght, etag_out);
     else {
         Py_INCREF(Py_None);
-        return Py_None;      
+        return Py_None;
     }
 }
 %%
@@ -218,16 +218,16 @@
     GCancellable *cancellable;
     PyGObject *pycancellable = NULL;
     PyGIONotify *notify;
-  
+
     notify = g_slice_new0(PyGIONotify);
-    
+
     if (!PyArg_ParseTupleAndKeywords(args, kwargs,
                                      "O|OO:File.load_contents_async",
                                       kwlist,
                                       &notify->callback,
                                       &pycancellable,
                                       &notify->data))
-            
+
     {
       g_slice_free(PyGIONotify, notify);
       return NULL;
@@ -257,7 +257,7 @@
     gsize lenght;
     GError *error = NULL;
     gboolean ret;
-    
+
     if (!PyArg_ParseTupleAndKeywords(args, kwargs,
                                      "O!:File.load_contents_finish",
                                       kwlist,
@@ -276,7 +276,7 @@
         return Py_BuildValue("(sks)", contents, lenght, etag_out);
     else {
         Py_INCREF(Py_None);
-        return Py_None;      
+        return Py_None;
     }
 }
 %%
@@ -318,14 +318,14 @@
     }
     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 @@
 				    (GCancellable *) cancellable,
 				    (GAsyncReadyCallback)async_result_callback_marshal,
 				    notify);
-    
+
     Py_INCREF(Py_None);
     return Py_None;
 }
@@ -352,9 +352,9 @@
     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 @@
 				     &py_flags,
 				     &py_cancellable,
 				     &notify->data))
-            
+
     {
       g_slice_free(PyGIONotify, notify);
       return NULL;
@@ -378,7 +378,7 @@
     }
     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 @@
     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 @@
 				     &py_flags,
 				     &py_cancellable,
 				     &notify->data))
-            
+
     {
       g_slice_free(PyGIONotify, notify);
       return NULL;
@@ -434,7 +434,7 @@
     }
     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 @@
     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 @@
 				     &py_flags,
 				     &py_cancellable,
 				     &notify->data))
-            
+
     {
       g_slice_free(PyGIONotify, notify);
       return NULL;
@@ -492,7 +492,7 @@
     }
     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 @@
     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 @@
 				     &py_flags,
 				     &py_cancellable,
 				     &notify->data))
-            
+
     {
       g_slice_free(PyGIONotify, notify);
       return NULL;
@@ -559,7 +559,7 @@
 	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 @@
 
     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 @@
 /* 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** */

Added: trunk/gio/gfileattribute.override
==============================================================================
--- (empty file)
+++ trunk/gio/gfileattribute.override	Tue Jul 29 21:51:43 2008
@@ -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();
+}

Modified: trunk/gio/gio.defs
==============================================================================
--- trunk/gio/gio.defs	(original)
+++ trunk/gio/gio.defs	Tue Jul 29 21:51:43 2008
@@ -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")

Modified: trunk/gio/gio.override
==============================================================================
--- trunk/gio/gio.override	(original)
+++ trunk/gio/gio.override	Tue Jul 29 21:51:43 2008
@@ -82,6 +82,7 @@
   gappinfo.override
   gapplaunchcontext.override
   gfile.override
+  gfileattribute.override
   gfileenumerator.override
   gfileinfo.override
   ginputstream.override

Modified: trunk/tests/test_gio.py
==============================================================================
--- trunk/tests/test_gio.py	(original)
+++ trunk/tests/test_gio.py	Tue Jul 29 21:51:43 2008
@@ -159,6 +159,30 @@
         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 @@
     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]