[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 23/72] scripts/qemu-ga-client: replace deprecated optparse with ar
From: |
John Snow |
Subject: |
[PULL 23/72] scripts/qemu-ga-client: replace deprecated optparse with argparse |
Date: |
Fri, 18 Jun 2021 19:04:06 -0400 |
optparse isn't supported anymore, it's from the python2 days. Replace it
with the mostly similar argparse.
Signed-off-by: John Snow <jsnow@redhat.com>
Message-id: 20210604155532.1499282-5-jsnow@redhat.com
Signed-off-by: John Snow <jsnow@redhat.com>
---
scripts/qmp/qemu-ga-client | 32 +++++++++++++++-----------------
1 file changed, 15 insertions(+), 17 deletions(-)
diff --git a/scripts/qmp/qemu-ga-client b/scripts/qmp/qemu-ga-client
index 7aba09f0fe..8eb4015e61 100755
--- a/scripts/qmp/qemu-ga-client
+++ b/scripts/qmp/qemu-ga-client
@@ -37,8 +37,8 @@
# See also: https://wiki.qemu.org/Features/QAPI/GuestAgent
#
+import argparse
import base64
-import optparse
import os
import random
import sys
@@ -255,7 +255,7 @@ def _cmd_reboot(client, args):
commands = [m.replace('_cmd_', '') for m in dir() if '_cmd_' in m]
-def main(address, cmd, args):
+def send_command(address, cmd, args):
if not os.path.exists(address):
print('%s not found' % address)
sys.exit(1)
@@ -283,25 +283,23 @@ def main(address, cmd, args):
globals()['_cmd_' + cmd](client, args)
-if __name__ == '__main__':
+def main():
address = os.environ.get('QGA_CLIENT_ADDRESS')
- usage = ("%prog [--address=<unix_path>|<ipv4_address>]"
- " <command> [args...]\n")
- usage += '<command>: ' + ', '.join(commands)
- parser = optparse.OptionParser(usage=usage)
- parser.add_option('--address', action='store', type='string',
- default=address,
- help='Specify a ip:port pair or a unix socket path')
- options, args = parser.parse_args()
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--address', action='store',
+ default=address,
+ help='Specify a ip:port pair or a unix socket path')
+ parser.add_argument('command', choices=commands)
+ parser.add_argument('args', nargs='*')
- address = options.address
- if address is None:
+ args = parser.parse_args()
+ if args.address is None:
parser.error('address is not specified')
sys.exit(1)
- if len(args) == 0:
- parser.error('Less argument')
- sys.exit(1)
+ send_command(args.address, args.command, args.args)
- main(address, args[0], args[1:])
+
+if __name__ == '__main__':
+ main()
--
2.31.1
- [PULL 44/72] scripts/qmp-shell: fix shell history exception handling, (continued)
- [PULL 44/72] scripts/qmp-shell: fix shell history exception handling, John Snow, 2021/06/18
- [PULL 46/72] scripts/qmp-shell: use isinstance() instead of type(), John Snow, 2021/06/18
- [PULL 43/72] scripts/qmp-shell: rename one and two-letter variables, John Snow, 2021/06/18
- [PULL 49/72] scripts/qmp-shell: Make verbose a public attribute, John Snow, 2021/06/18
- [PULL 31/72] scripts/qmp-shell: apply isort rules, John Snow, 2021/06/18
- [PULL 39/72] scripts/qmp-shell: declare verbose in __init__, John Snow, 2021/06/18
- [PULL 40/72] scripts/qmp-shell: use triple-double-quote docstring style, John Snow, 2021/06/18
- [PULL 41/72] scripts/qmp-shell: ignore visit_Name name, John Snow, 2021/06/18
- [PULL 42/72] scripts/qmp-shell: make QMPCompleter returns explicit, John Snow, 2021/06/18
- [PULL 50/72] scripts/qmp-shell: move get_prompt() to prompt property, John Snow, 2021/06/18
- [PULL 23/72] scripts/qemu-ga-client: replace deprecated optparse with argparse,
John Snow <=
- [PULL 25/72] scripts/qemu-ga-client: apply (most) pylint rules, John Snow, 2021/06/18
- [PULL 24/72] scripts/qemu-ga-client: add module docstring, John Snow, 2021/06/18
- [PULL 34/72] scripts/qmp-shell: fix exception handling, John Snow, 2021/06/18
- [PULL 51/72] scripts/qmp-shell: remove prompt argument from read_exec_command, John Snow, 2021/06/18
- [PULL 53/72] scripts/qmp-shell: Fix "FuzzyJSON" parser, John Snow, 2021/06/18
- [PULL 54/72] scripts/qmp-shell: refactor QMPCompleter, John Snow, 2021/06/18
- [PULL 52/72] scripts/qmp-shell: move the REPL functionality into QMPShell, John Snow, 2021/06/18
- [PULL 47/72] scripts/qmp-shell: use argparse, John Snow, 2021/06/18
- [PULL 45/72] scripts/qmp-shell: remove if-raise-else patterns, John Snow, 2021/06/18
- [PULL 55/72] scripts/qmp-shell: initialize completer early, John Snow, 2021/06/18