I've discovered that libguestfs apis which return RHashtable are currently returned as a list of tuples in the python bindings rather than the obvious dict. I propose fixing this, whilst also maintaining API compatibility for a period of time. The following apis return RHashtable: inspect_get_mountpoints list_filesystems inspect_get_drive_mappings tune2fs_l mountpoints md_detail blkid list_disk_labels I propose the following: h = guestfs.GuestFS(return_dict=True) If return_dict is set, any RHashtable api would return a dict rather than a list of tuples. If not, the behaviour would be unchanged. The default would be False. We would advertise immediately that this parameter is recommended for all new code, and that old code should be updated. At some point in the future the default would be changed to True, and at some point after that the old code could be removed. Matt
On Wed, Apr 03, 2013 at 05:29:57PM +0100, Matthew Booth wrote:
I've discovered that libguestfs apis which return RHashtable are currently returned as a list of tuples in the python bindings rather than the obvious dict. I propose fixing this, whilst also maintaining API compatibility for a period of time.
The following apis return RHashtable:
inspect_get_mountpoints list_filesystems inspect_get_drive_mappings tune2fs_l mountpoints md_detail blkid list_disk_labels
I propose the following:
h = guestfs.GuestFS(return_dict=True)
If return_dict is set, any RHashtable api would return a dict rather than a list of tuples. If not, the behaviour would be unchanged. The default would be False.
Although it's not very likely, it is better to avoid a conflict with a future guestfs_create_flags flag by calling the flag 'python_return_dict'. Apart from that, it looks fine to me. Rich.
We would advertise immediately that this parameter is recommended for all new code, and that old code should be updated. At some point in the future the default would be changed to True, and at some point after that the old code could be removed.
Matt
_______________________________________________ Libguestfs mailing list Libguestfs@redhat.com https://www.redhat.com/mailman/listinfo/libguestfs
-- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming blog: http://rwmj.wordpress.com Fedora now supports 80 OCaml packages (the OPEN alternative to F#)
Here's a simple implementation. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://people.redhat.com/~rjones/virt-df/
On Wed, 2013-04-03 at 19:19 +0100, Richard W.M. Jones wrote:
From ba0199c487feec7f02cfc00ba3e900e6fa5ed4d8 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" <rjones@redhat.com> Date: Wed, 3 Apr 2013 18:58:43 +0100 Subject: [PATCH] python: Let RHashtable be returned as a Python dict.
The initial proposal was suggested by Matt Booth and discussed on the mailing list here:
https://www.redhat.com/archives/libguestfs/2013-April/msg00007.html --- generator/python.ml | 43 ++++++++++++++++++++++++++++++++------ python/examples/create_disk.py | 6 +++++- python/examples/guestfs-python.pod | 13 +++++++++++- python/examples/inspect_vm.py | 19 +++++++---------- python/t/010-basic.py | 2 +- python/t/028-python-dict.py | 34 ++++++++++++++++++++++++++++++ python/t/060-optargs.py | 2 +- python/t/400-events.py | 2 +- python/t/800-explicit-close.py | 6 +++--- python/t/rhbz811650.py | 2 +- 10 files changed, 103 insertions(+), 26 deletions(-) create mode 100644 python/t/028-python-dict.py
ACK. It hadn't occurred to me to transform this in python. It's a much more expedient patch. It will make sense to update the C when this is ultimately removed, though. Matt
On Thu, Apr 04, 2013 at 09:42:01AM +0100, Matthew Booth wrote:
On Wed, 2013-04-03 at 19:19 +0100, Richard W.M. Jones wrote:
From ba0199c487feec7f02cfc00ba3e900e6fa5ed4d8 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" <rjones@redhat.com> Date: Wed, 3 Apr 2013 18:58:43 +0100 Subject: [PATCH] python: Let RHashtable be returned as a Python dict.
The initial proposal was suggested by Matt Booth and discussed on the mailing list here:
https://www.redhat.com/archives/libguestfs/2013-April/msg00007.html --- generator/python.ml | 43 ++++++++++++++++++++++++++++++++------ python/examples/create_disk.py | 6 +++++- python/examples/guestfs-python.pod | 13 +++++++++++- python/examples/inspect_vm.py | 19 +++++++---------- python/t/010-basic.py | 2 +- python/t/028-python-dict.py | 34 ++++++++++++++++++++++++++++++ python/t/060-optargs.py | 2 +- python/t/400-events.py | 2 +- python/t/800-explicit-close.py | 6 +++--- python/t/rhbz811650.py | 2 +- 10 files changed, 103 insertions(+), 26 deletions(-) create mode 100644 python/t/028-python-dict.py
ACK. It hadn't occurred to me to transform this in python. It's a much more expedient patch. It will make sense to update the C when this is ultimately removed, though.
Agreed. I have just pushed this. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 100 libraries supported. http://fedoraproject.org/wiki/MinGW
participants (2)
-
Matthew Booth -
Richard W.M. Jones