python: improve errors in inspect_vm example

When validating user input, print an error message and exit, instead of
either asserting or raising a non-existing exception.
This commit is contained in:
Pino Toscano
2020-01-10 13:57:04 +01:00
parent 7d0f8e1b22
commit 92759efbf5

View File

@@ -3,7 +3,9 @@
import sys
import guestfs
assert(len(sys.argv) == 2)
if len(sys.argv) < 2:
print("inspect_vm: missing disk image to inspect", file=sys.stderr)
sys.exit(1)
disk = sys.argv[1]
# All new Python code should pass python_return_dict=True
@@ -21,7 +23,8 @@ g.launch()
# Ask libguestfs to inspect for operating systems.
roots = g.inspect_os()
if len(roots) == 0:
raise(Error("inspect_vm: no operating systems found"))
print("inspect_vm: no operating systems found", file=sys.stderr)
sys.exit(1)
for root in roots:
print("Root device: %s" % root)