diff mbox series

[RFC,3/9] scripts/qmp: Update 'qmp-shell' forwarder stub

Message ID 20211217022939.279559-4-jsnow@redhat.com
State New
Headers show
Series Python: Switch to externally hosted qemu.qmp dependency | expand

Commit Message

John Snow Dec. 17, 2021, 2:29 a.m. UTC
The text here is slightly different than the text in other forwarder
stubs in this directory, because the only dependency needed here is
outside of the QEMU source tree entirely.

Signed-off-by: John Snow <jsnow@redhat.com>
---
 scripts/qmp/qmp-shell | 39 ++++++++++++++++++++++++++++++++++-----
 1 file changed, 34 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell
index 4a20f97db7..1d30425547 100755
--- a/scripts/qmp/qmp-shell
+++ b/scripts/qmp/qmp-shell
@@ -1,11 +1,40 @@ 
 #!/usr/bin/env python3
 
-import os
 import sys
 
-sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python'))
-from qemu.qmp import qmp_shell
+try:
+    from qemu.qmp import qmp_shell
+    _HAVE_QMP = True
+except ModuleNotFoundError:
+    _HAVE_QMP = False
 
+bold = "\033[1m"
+end = "\033[0m"
+cmd = 'qmp-shell'
 
-if __name__ == '__main__':
-    qmp_shell.main()
+EMSG = f"""
+{bold}'{sys.argv[0]}' is just a forwarder, and is not necessary.{end}
+
+However, the 'qemu.qmp' package is not installed.
+
+To use the '{cmd}' command directly from the installed package,
+install the python package and then add (for a --user install)
+~/.local/bin/ to $PATH if it isn't already. Then, you should have access
+to the '{cmd}' command.
+
+For more information, please see ../../python/README.rst.
+
+maybe:
+ > pip3 install --user qemu.qmp
+ > export PATH=$PATH:~/.local/bin/
+ > {cmd} --help
+
+Alternatively, after installing the qemu.qmp package, this forwarder
+will work again. However, it will eventually be removed. I apologize for
+the inconvenience!"""
+
+if not _HAVE_QMP:
+    print(EMSG, file=sys.stderr)
+    sys.exit(1)
+
+qmp_shell.main()