After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 547067 - add File.replace_contents, replace_contents_async, replace_contents_finish
add File.replace_contents, replace_contents_async, replace_contents_finish
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: gio
Git master
Other Linux
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2008-08-09 13:29 UTC by Jonathan Matthew
Modified: 2008-08-10 03:28 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
add File.replace_contents methods (9.31 KB, patch)
2008-08-09 13:30 UTC, Jonathan Matthew
committed Details | Review

Description Jonathan Matthew 2008-08-09 13:29:33 UTC
I think I'm going to use these methods, so I've written up the necessary override code for them.
Comment 1 Jonathan Matthew 2008-08-09 13:30:35 UTC
Created attachment 116230 [details] [review]
add File.replace_contents methods
Comment 2 Johan (not receiving bugmail) Dahlin 2008-08-09 14:05:50 UTC
Comment on attachment 116230 [details] [review]
add File.replace_contents methods

>Index: gio/gio.defs

>+  (docstring
>+  "F.replace_contents(contents, [etag, [make_backup, [flags, [cancellable]]]]) -> etag_out\n\n"
>+  "Replaces the content of the file, returning the new etag value for the file.\n"
>+  "If an etag is specified, any existing file must have that etag, or the\n"
>+  "error gio.IO_ERROR_WRONG_ETAG will be returned.\n"
>+  "If make_backup is True, this method will attempt to make a backup of the file.\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.\n"

Make sure this is wrapped at 76 columns, you can easily test by doing
pydoc gio.File.replace_contents in a terminal. It needs to be readable.
I didn't test it might already look good, in that case just ignore this comment.

>Index: gio/gfile.override

>+_wrap_g_file_replace_contents_finish(PyGObject *self, PyObject *args, PyObject *kwargs)

>+    static char *kwlist[] = { "res", NULL };

shouldn't that be result instead of res?

>+    if (ret) {
>+        PyObject *py_ret = PyString_FromString(etag_out);
>+        g_free(etag_out);
>+        return py_ret;
>+    } else {
>+        Py_INCREF(Py_None);
>+        return Py_None;
>+    }

Shouldn't etag_out always be freed? Or is it only set if ret is true?

The rest looks good, if the above comments are addressed or deemed invalid, please commit.
Comment 3 Gian Mario Tagliaretti 2008-08-09 18:53:42 UTC
etag can be NULL in both replace_contents and replace_contents_async, so you should use z instead of s
Comment 4 Jonathan Matthew 2008-08-10 03:28:52 UTC
I've fixed up the docstring line length, made the freeing of etag_out unconditional, renamed 'res' to 'result', used 'z' rather than 's' for etags, added a couple more tests, and committed.  Thanks for the prompt review.

I noticed that File.load_contents_async also calls the result parameter 'res'.  Should I fix that one too?

There are a number of other docstrings in gio.defs that wrap across lines in a 80 column terminal.  I can provide a patch for these.