[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 5/5] python: qmp_shell: handle comment lines and escaped eol
From: |
Damien Hedde |
Subject: |
[PATCH 5/5] python: qmp_shell: handle comment lines and escaped eol |
Date: |
Mon, 21 Feb 2022 16:55:19 +0100 |
In order to support more user-friendly command list file,
this commit adds the support for:
+ comment lines: line staring by '#' are ignored
+ escaped enf-of-line: line with trailing ' \' are continued
on next one
For eol: we impose a space before the '\' in order not to trigger
the escape if the '\' is for example at the end of a value in a
'key=value' sequence.
Althought it does not have any real interest in interactive mode,
the prompt is adapted when in that case.
Signed-off-by: Damien Hedde <damien.hedde@greensocs.com>
---
python/qemu/aqmp/qmp_shell.py | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/python/qemu/aqmp/qmp_shell.py b/python/qemu/aqmp/qmp_shell.py
index dd38ef8a13..64cd31dcd6 100644
--- a/python/qemu/aqmp/qmp_shell.py
+++ b/python/qemu/aqmp/qmp_shell.py
@@ -188,6 +188,7 @@ def __init__(self, address: SocketAddrT,
self._greeting: Optional[QMPMessage] = None
self._completer = QMPCompleter()
self._transmode = False
+ self._escaped_eol = False
self._actions: List[QMPMessage] = []
self._histfile = os.path.join(os.path.expanduser('~'),
'.qmp-shell_history')
@@ -385,6 +386,8 @@ def prompt(self) -> str:
"""
if not sys.stdin.isatty():
return ""
+ if self._escaped_eol:
+ return '> '
if self._transmode:
return 'TRANS> '
return '(QEMU) '
@@ -397,6 +400,11 @@ def read_exec_command(self) -> bool:
"""
try:
cmdline = input(self.prompt)
+ self._escaped_eol = True
+ while cmdline[-2:] == ' \\':
+ #only remove the trailing '\', keep the space
+ cmdline = cmdline[:-1] + input(self.prompt)
+ self._escaped_eol = False
except EOFError:
print()
return False
@@ -406,6 +414,10 @@ def read_exec_command(self) -> bool:
print(event)
return True
+ if cmdline[0] == '#':
+ #consider these lines as comments
+ return True
+
if self.raise_error:
resp = self._execute_cmd(cmdline)
if resp and 'error' in resp:
--
2.35.1
- [PATCH 0/5] qmp-shell modifications for non-interactive use, Damien Hedde, 2022/02/21
- [PATCH 1/5] python: qmp_shell: don't prompt when stdin is non-interactive, Damien Hedde, 2022/02/21
- [PATCH 3/5] python: qmp_shell: refactor disconnection handling, Damien Hedde, 2022/02/21
- [PATCH 2/5] python: qmp_shell: refactor the parsing error handling, Damien Hedde, 2022/02/21
- [PATCH 5/5] python: qmp_shell: handle comment lines and escaped eol,
Damien Hedde <=
- [PATCH 4/5] python: qmp_shell: add -e/--exit-on-error option, Damien Hedde, 2022/02/21
- Re: [PATCH 4/5] python: qmp_shell: add -e/--exit-on-error option, John Snow, 2022/02/23
- Re: [PATCH 4/5] python: qmp_shell: add -e/--exit-on-error option, Daniel P . Berrangé, 2022/02/23
- Re: [PATCH 4/5] python: qmp_shell: add -e/--exit-on-error option, John Snow, 2022/02/23
- Re: [PATCH 4/5] python: qmp_shell: add -e/--exit-on-error option, Daniel P . Berrangé, 2022/02/23
- Re: [PATCH 4/5] python: qmp_shell: add -e/--exit-on-error option, John Snow, 2022/02/23
- Re: [PATCH 4/5] python: qmp_shell: add -e/--exit-on-error option, Damien Hedde, 2022/02/23
- Re: [PATCH 4/5] python: qmp_shell: add -e/--exit-on-error option, John Snow, 2022/02/23
- Re: [PATCH 4/5] python: qmp_shell: add -e/--exit-on-error option, Damien Hedde, 2022/02/24
- Re: [PATCH 4/5] python: qmp_shell: add -e/--exit-on-error option, Daniel P . Berrangé, 2022/02/23