diff options
-rw-r--r-- | gio/gfileinfo.override | 33 | ||||
-rw-r--r-- | 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): |