[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 20/72] scripts/qemu-ga-client: replace deprecated optparse wit
From: |
John Snow |
Subject: |
[PATCH v2 20/72] scripts/qemu-ga-client: replace deprecated optparse with argparse |
Date: |
Tue, 3 Nov 2020 19:35:10 -0500 |
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 c4fbb6165d54..73d262e8beb4 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.26.2
- [PATCH v2 06/72] python: Add 'fh' to known-good variable names, (continued)
- [PATCH v2 06/72] python: Add 'fh' to known-good variable names, John Snow, 2020/11/03
- [PATCH v2 07/72] scripts/qom-fuse: Apply pylint rules, John Snow, 2020/11/03
- [PATCH v2 09/72] scripts/qom-fuse: Convert to QOMCommand, John Snow, 2020/11/03
- [PATCH v2 12/72] scripts/qom-fuse: add static type hints, John Snow, 2020/11/03
- [PATCH v2 11/72] scripts/qom-fuse: ensure QOMFuse.read always returns bytes, John Snow, 2020/11/03
- [PATCH v2 16/72] python: add optional fuse dependency, John Snow, 2020/11/03
- [PATCH v2 10/72] scripts/qom-fuse: use QOMCommand.qom_list(), John Snow, 2020/11/03
- [PATCH v2 13/72] scripts/qom-fuse: move to python/qemu/qmp/qom_fuse.py, John Snow, 2020/11/03
- [PATCH v2 15/72] python: add fuse command to 'qom' tools, John Snow, 2020/11/03
- [PATCH v2 18/72] scripts/qemu-ga-client: apply (most) flake8 rules, John Snow, 2020/11/03
- [PATCH v2 20/72] scripts/qemu-ga-client: replace deprecated optparse with argparse,
John Snow <=
- [PATCH v2 19/72] scripts/qemu-ga-client: Fix exception handling, John Snow, 2020/11/03
- [PATCH v2 26/72] python/qemu-ga-client: add entry point, John Snow, 2020/11/03
- [PATCH v2 29/72] scripts/qmp-shell: Apply flake8 rules, John Snow, 2020/11/03
- [PATCH v2 23/72] python/qmp: Correct type of QMPReturnValue, John Snow, 2020/11/03
- [PATCH v2 28/72] scripts/qmp-shell: apply isort rules, John Snow, 2020/11/03
- [PATCH v2 21/72] scripts/qemu-ga-client: add module docstring, John Snow, 2020/11/03
- [PATCH v2 27/72] scripts/qemu-ga-client: Add forwarder stub, John Snow, 2020/11/03
- [PATCH v2 25/72] scripts/qemu-ga-client: move to python/qemu/qmp/qemu_ga_client.py, John Snow, 2020/11/03
- [PATCH v2 17/72] scripts/qemu-ga-client: apply isort rules, John Snow, 2020/11/03
- [PATCH v2 14/72] scripts/qom-fuse: add redirection shim to python/qemu/qmp/qom-fuse.py, John Snow, 2020/11/03