pygobject / pgi

[Unmaintained: Use PyGObject instead] GTK+ / GObject Introspection Bindings for PyPy.
GNU Lesser General Public License v2.1
74 stars 16 forks source link

Error in documentation for call_unmount_finish #32

Closed damonlynch closed 8 years ago

damonlynch commented 8 years ago

GObject is far from my area of expertise, but I do believe that the documentation is wrong for UDisks.Filesystem.call_unmount_finish()

The docs state it takes 1 parameter, but it seems to require 2: the UDisks.Filesystem, and Gio.AsyncResult.

Another probably related issue is that when I called it using the parameters passed to the unmount callback (FilesystemProxy and the result), it gave me a False result even though it did actually unmount.

lazka commented 8 years ago

GObject is far from my area of expertise, but I do believe that the documentation is wrong for UDisks.Filesystem.call_unmount_finish()

The docs state it takes 1 parameter, but it seems to require 2: the UDisks.Filesystem, and Gio.AsyncResult.

It's a method of UDisks.Filesystem, so a UDisks.Filesystem gets always passed.

Another probably related issue is that when I called it using the parameters passed to the unmount callback (FilesystemProxy and the result), it gave me a False result even though it did actually unmount.

pgi only supports the basics and is currently only used for creating the documenation.

damonlynch commented 8 years ago

It's quite likely I'm a bit confused about the relationship between pgi and code that uses import gi. Is pgi something different from that? If so, sorry for the erroneous bug report, but I'm using just the regular import gi.

In any case I've adjusted my code pass the filesystem as part of the user data, and in the callback I now call fs.call_unmount_finish(result), where fs is the filesystem, but it still gives a False result, and not True, even though the unmount succeeded.

lazka commented 8 years ago

It's quite likely I'm a bit confused about the relationship between pgi and code that uses import gi. Is pgi something different from that? If so, sorry for the erroneous bug report, but I'm using just the regular import gi.

"import gi" is pygobject [0] not pgi. pgi tries to implement the same API and is currently used to produce the documentation [1]

In any case I've adjusted my code pass the filesystem as part of the user data, and in the callback I now call fs.call_unmount_finish(result), where fs is the filesystem, but it still gives a False result, and not True, even though the unmount succeeded.

Hm, weird, afaics it should never return False and just raise GLib.Error in that case

[0] https://git.gnome.org/browse/pygobject/ [1] https://lazka.github.io/pgi-docs/

damonlynch commented 8 years ago

Thanks for clarifying the difference between pygobject and pgi! So the documentation [1] is the documentation for both pgi and pygobject, is that right?

This code excerpt definitely results in False when calling call_unmount_finish(), not an exception:

   def unmount_volume(self, mount_point: str) -> None:
        ....
        try:
            fs.call_unmount(vparam, None, self.umount_volume_callback, (mount_point, fs))
        except GLib.GError:
            value = sys.exc_info()[1]
            logging.error('Unmounting failed with error:')
            logging.error("%s", value)

    def umount_volume_callback(self, source_object:  UDisks.FilesystemProxy,
                               result: Gio.AsyncResult,
                               user_data: Tuple[str, UDisks.Filesystem]) -> None:
        """
        Callback for asynchronous unmount operation.

        :param source_object: the FilesystemProxy object
        :param result: result of the unmount
        :param user_data: mount_point and the file system
        """

        mount_point, fs = user_data

        try:
            if fs.call_unmount_finish(result):
                logging.debug("...successfully unmounted %s", mount_point)
            else:
                # this is the result even when the unmount was unsuccessful
                logging.debug("...possibly failed to unmount %s", mount_point)
        except GLib.GError as e:
            logging.error('Exception occurred unmounting %s', mount_point)
            logging.exception('Traceback:')
lazka commented 8 years ago

Thanks for clarifying the difference between pygobject and pgi! So the documentation [1] is the documentation for both pgi and pygobject, is that right?

Correct

This code excerpt definitely results in False when calling call_unmount_finish(), not an exception:

Maybe try calling call_unmount_finish() on source_object in the callback instead of the user_data object?

damonlynch commented 8 years ago

Using the source object was the first thing I tried. It gave me a TypeError "first argument must be the method signature string: <Task object ....>"

lazka commented 8 years ago

No idea, sorry.

Fyi, the error you see is from the Python overrides https://git.gnome.org/browse/pygobject/tree/gi/overrides/Gio.py#n145

where it tries to dynamically create dbus method calls for attributes it doesn't know. about.