[pygobject] Wrap gio.FileInfo.set_modification_time and add a test



commit 9ac372ad0bcfdec4bb1c96bc152246542a59a9b1
Author: Gian Mario Tagliaretti <gianmt gnome org>
Date:   Mon Dec 28 21:37:49 2009 +0100

    Wrap gio.FileInfo.set_modification_time and add a test

 gio/gfileinfo.override |   33 ++++++++++++++++++++++++++++++++-
 tests/test_gio.py      |    7 ++++++-
 2 files changed, 38 insertions(+), 2 deletions(-)
---
diff --git a/gio/gfileinfo.override b/gio/gfileinfo.override
index 7643bf7..730e91b 100644
--- a/gio/gfileinfo.override
+++ b/gio/gfileinfo.override
@@ -84,7 +84,38 @@ _wrap_g_file_info_get_modification_time(PyGObject *self, PyObject *unused)
     g_file_info_get_modification_time(G_FILE_INFO(self->obj), &timeval);
     return pyglib_float_from_timeval(timeval);
 }
+%%
+override g_file_info_set_modification_time kwargs
+static PyObject *
+_wrap_g_file_info_set_modification_time(PyGObject *self, 
+                                        PyObject  *args, 
+                                        PyObject  *kwargs)
+{
+    char *kwlist[] = { "mtime", NULL};
+    double py_mtime = 0.0;
+    GTimeVal ttime, *mtime;
+    
+    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+                                     "d:gio.FileInfo.set_modification_time",
+                                     kwlist, &py_mtime))
+        return NULL;
+
+    if (py_mtime > 0.0) {
+	ttime.tv_sec = (glong) py_mtime;
+	ttime.tv_usec = (glong)((py_mtime - ttime.tv_sec) * G_USEC_PER_SEC);
+        mtime = &ttime;
+    } else if (py_mtime == 0.0) {
+	mtime = NULL;
+    } else {
+        PyErr_SetString(PyExc_ValueError, "mtime must be >= 0.0");
+        return NULL;
+    }
+    
+    g_file_info_set_modification_time(G_FILE_INFO(self->obj), mtime);
+    
+    Py_INCREF(Py_None);
+    return Py_None;
+}
 
 /* GFileInfo.get_attribute_data: No ArgType for GFileAttributeType* */
 /* GFileInfo.set_attribute: No ArgType for gpointer */
-/* GFileInfo.set_modification_time: No ArgType for GTimeVal* */
diff --git a/tests/test_gio.py b/tests/test_gio.py
index 1578d58..fd2edba 100644
--- a/tests/test_gio.py
+++ b/tests/test_gio.py
@@ -945,10 +945,15 @@ class TestFileInfo(unittest.TestCase):
         self.failUnless(attributes)
         self.failUnless('standard::name' in attributes)
 
-    def testModificationTime(self):
+    def testGetModificationTime(self):
         mtime = self.fileinfo.get_modification_time()
         self.assertEqual(type(mtime), float)
 
+    def testSetModificationTime(self):
+        self.fileinfo.set_modification_time(1000)
+        mtime = self.fileinfo.get_modification_time()
+        self.assertEqual(mtime, 1000)
+
 
 class TestAppInfo(unittest.TestCase):
     def setUp(self):



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]