Pino Toscano
2019-Apr-24 13:32 UTC
[Libguestfs] [PATCH 0/3] Few minor changes for bindings
*** BLURB HERE *** Pino Toscano (3): python: modernize inspect_vm example perl: silence usage of add_cdrom in test python: silence usage of add_cdrom in test perl/t/060-handle-properties.t | 7 +++++-- python/examples/inspect_vm.py | 26 ++++++++++++-------------- python/t/test050HandleProperties.py | 5 ++++- 3 files changed, 21 insertions(+), 17 deletions(-) -- 2.20.1
Pino Toscano
2019-Apr-24 13:32 UTC
[Libguestfs] [PATCH 1/3] python: modernize inspect_vm example
Since we already assume Python >= 2.7, modernize this example to make it work also on Python 3: - use print() as function - sort the mount points using a key for sorted(), instead of a comparison function - remove extra newline escape - reident two lines according to the PEP 8 style --- python/examples/inspect_vm.py | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/python/examples/inspect_vm.py b/python/examples/inspect_vm.py index 077157c19..22cd70f28 100644 --- a/python/examples/inspect_vm.py +++ b/python/examples/inspect_vm.py @@ -24,36 +24,34 @@ if len(roots) == 0: raise(Error("inspect_vm: no operating systems found")) for root in roots: - print "Root device: %s" % root + print("Root device: %s" % root) # Print basic information about the operating system. - print " Product name: %s" % (g.inspect_get_product_name(root)) - print " Version: %d.%d" % \ - (g.inspect_get_major_version(root), - g.inspect_get_minor_version(root)) - print " Type: %s" % (g.inspect_get_type(root)) - print " Distro: %s" % (g.inspect_get_distro(root)) + print(" Product name: %s" % (g.inspect_get_product_name(root))) + print(" Version: %d.%d" % + (g.inspect_get_major_version(root), + g.inspect_get_minor_version(root))) + print(" Type: %s" % (g.inspect_get_type(root))) + print(" Distro: %s" % (g.inspect_get_distro(root))) # Mount up the disks, like guestfish -i. # # Sort keys by length, shortest first, so that we end up # mounting the filesystems in the correct order. mps = g.inspect_get_mountpoints(root) - def compare(a, b): - return len(a) - len(b) - for device in sorted(mps.keys(), compare): + for device, mp in sorted(mps.items(), key=lambda k: len(k[0])): try: - g.mount_ro(mps[device], device) + g.mount_ro(mp, device) except RuntimeError as msg: - print "%s (ignored)" % msg + print("%s (ignored)" % msg) # If /etc/issue.net file exists, print up to 3 lines. filename = "/etc/issue.net" if g.is_file(filename): - print "--- %s ---" % filename + print("--- %s ---" % filename) lines = g.head_n(3, filename) for line in lines: - print line + print(line) # Unmount everything. g.umount_all() -- 2.20.1
Pino Toscano
2019-Apr-24 13:32 UTC
[Libguestfs] [PATCH 2/3] perl: silence usage of add_cdrom in test
One test explicitly tests add_cdrom, so silence the deprecation warning only for that function. --- perl/t/060-handle-properties.t | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/perl/t/060-handle-properties.t b/perl/t/060-handle-properties.t index 6b1ee4242..8df6a68c3 100644 --- a/perl/t/060-handle-properties.t +++ b/perl/t/060-handle-properties.t @@ -40,5 +40,8 @@ ok ($g->get_path () ne "", "path is empty"); $g->add_drive ("/dev/null"); ok (1, "add drive"); -$g->add_cdrom ("/dev/zero"); -ok (1, "add cdrom"); +do { + no warnings 'deprecated'; + $g->add_cdrom ("/dev/zero"); + ok (1, "add cdrom"); +} -- 2.20.1
Pino Toscano
2019-Apr-24 13:32 UTC
[Libguestfs] [PATCH 3/3] python: silence usage of add_cdrom in test
One test explicitly tests add_cdrom, so silence the deprecation warning only for that function. --- python/t/test050HandleProperties.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/python/t/test050HandleProperties.py b/python/t/test050HandleProperties.py index e2b12f1dc..59de8b806 100644 --- a/python/t/test050HandleProperties.py +++ b/python/t/test050HandleProperties.py @@ -16,6 +16,7 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. import unittest +import warnings import guestfs class Test050HandleProperties(unittest.TestCase): @@ -44,4 +45,6 @@ class Test050HandleProperties(unittest.TestCase): def test_add_cdrom(self): g = guestfs.GuestFS(python_return_dict=True) - g.add_cdrom("/dev/zero") + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", category=DeprecationWarning) + g.add_cdrom("/dev/zero") -- 2.20.1
Richard W.M. Jones
2019-Apr-25 14:01 UTC
Re: [Libguestfs] [PATCH 3/3] python: silence usage of add_cdrom in test
This series is fine. I don't even mind if you want to drop Python 2 support ... Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 100 libraries supported. http://fedoraproject.org/wiki/MinGW