scripts: Python 3 compatibility fixes
cover scripts: Python 3 compatibility fixes
Fix a few incompatibilities, which should be enough to allow device-crash-test to work with Python 3.
Eduardo Habkost (3):
qemu.py: Use items() instead of iteritems()
qmp.py: Encode json data before sending
device-crash-test: Use 'python' binary
scripts/qemu.py | 2 +- scripts/qmp/qmp.py | 2 +- scripts/device-crash-test | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
Signature · 1 line
2.14.3
PATCH 1/3 qemu.py: Use items() instead of iteritems()
items() is less efficient on Python 2.x, but makes the code work on both Python 2 and Python 3.
--- scripts/qemu.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/qemu.py +1 -1
@@ -277,7 +277,7 @@ class QEMUMachine(object): def qmp(self, cmd, conv_keys=True, **args): '''Invoke a QMP command and return the response dict''' qmp_args = dict() - for key, value in args.iteritems(): + for key, value in args.items(): if conv_keys: qmp_args[key.replace('_', '-')] = value else:
Signature · 1 line
2.14.3
Re: [Qemu-devel] [PATCH 1/3] qemu.py: Use items() instead of iteritems()
Quoted 16 lines · Eduardo Habkost
items()is less efficient on Python 2.x, but makes the code work on both Python 2 and Python 3.Cc Lukáš Doktor <[email protected]>Cc Philippe Mathieu-Daudé <[email protected]>Cc Cleber Rosa <[email protected]>Signed-off-by Eduardo Habkost <[email protected]>--- scripts/qemu.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)scripts/qemu.py +0
-0
scripts/qemu.py class QEMUMachine(object): · line 283
Quoted 8 lines
scripts/qemu.py +1
-1@@ -277,7 +277,7 @@ class QEMUMachine(object): def qmp(self, cmd, conv_keys=True, **args): '''Invoke a QMP command and return the response dict''' qmp_args = dict() - for key, value in args.iteritems(): + for key, value in args.items(): if conv_keys: qmp_args[key.replace('_', '-')] = value else:
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [Qemu-devel] [PATCH 1/3] qemu.py: Use items() instead of iteritems()
In reply to Eduardo HabkostQuoted 17 lines · Eduardo Habkost
items()is less efficient on Python 2.x, but makes the code work on both Python 2 and Python 3.Cc Lukáš Doktor <[email protected]>Cc Philippe Mathieu-Daudé <[email protected]>Cc Cleber Rosa <[email protected]>Signed-off-by Eduardo Habkost <[email protected]>--- scripts/qemu.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)scripts/qemu.py +0
-0
scripts/qemu.py class QEMUMachine(object): · line 283
Quoted 8 lines
scripts/qemu.py +1
-1@@ -277,7 +277,7 @@ class QEMUMachine(object): def qmp(self, cmd, conv_keys=True, **args): '''Invoke a QMP command and return the response dict''' qmp_args = dict() - for key, value in args.iteritems(): + for key, value in args.items(): if conv_keys: qmp_args[key.replace('_', '-')] = value else:
http://lists.nongnu.org/archive/html/qemu-devel/2017-12/msg04046.html
;)
Re: [Qemu-devel] [PATCH 1/3] qemu.py: Use items() instead of iteritems()
Quoted 12 lines · Philippe Mathieu-Daudé
Quoted 11 lines · Eduardo Habkost
items()is less efficient on Python 2.x, but makes the code work on both Python 2 and Python 3.Cc Lukáš Doktor <[email protected]>Cc Philippe Mathieu-Daudé <[email protected]>Cc Cleber Rosa <[email protected]>Signed-off-by Eduardo Habkost <[email protected]>--- scripts/qemu.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines
Quoted 6 lines
scripts/qemu.py +0
-0scripts/qemu.py class QEMUMachine(object): · line 283
Quoted 8 lines
scripts/qemu.py +1
-1@@ -277,7 +277,7 @@ class QEMUMachine(object): def qmp(self, cmd, conv_keys=True, **args): '''Invoke a QMP command and return the response dict''' qmp_args = dict() - for key, value in args.iteritems(): + for key, value in args.items(): if conv_keys: qmp_args[key.replace('_', '-')] = value else:http://lists.nongnu.org/archive/html/qemu-devel/2017-12/msg04046.html
Oops, that series had fallen through the cracks, sorry!
I remember merging a series with fixes for Python 3, but now I see there were two separate series: "Support building with py2 or py3¨ (already merged), and yours ("iotests: python3 compatibility¨).
Signature · 1 line
Eduardo
PATCH 2/3 qmp.py: Encode json data before sending
In reply to Eduardo HabkostOn Python 3, json.dumps() return a str object, which can't be sent directly through a socket and must be encoded into a bytes object. Use .encode('utf-8'), which will work on both Python 2 and Python 3.
--- scripts/qmp/qmp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/qmp/qmp.py +1 -1
@@ -166,7 +166,7 @@ class QEMUMonitorProtocol(object): """ self.logger.debug(">>> %s", qmp_cmd) try: - self.__sock.sendall(json.dumps(qmp_cmd)) + self.__sock.sendall(json.dumps(qmp_cmd).encode('utf-8')) except socket.error as err: if err[0] == errno.EPIPE: return
Signature · 1 line
2.14.3
Re: [Qemu-devel] [PATCH 2/3] qmp.py: Encode json data before sending
Quoted 15 lines · Eduardo Habkost
On Python 3,
json.dumps()return a str object, which can't be sent directly through a socket and must be encoded into a bytes object. Use .encode('utf-8'), which will work on both Python 2 and Python 3.Signed-off-by Eduardo Habkost <[email protected]>--- scripts/qmp/qmp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)scripts/qmp/qmp.py +0
-0
scripts/qmp/qmp.py class QEMUMonitorProtocol(object): · line 172
Quoted 8 lines
scripts/qmp/qmp.py +1
-1@@ -166,7 +166,7 @@ class QEMUMonitorProtocol(object): """ self.logger.debug(">>> %s", qmp_cmd) try: - self.__sock.sendall(json.dumps(qmp_cmd)) + self.__sock.sendall(json.dumps(qmp_cmd).encode('utf-8')) except socket.error as err: if err[0] == errno.EPIPE: return
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [Qemu-devel] [PATCH 2/3] qmp.py: Encode json data before sending
In reply to Eduardo HabkostQuoted 16 lines · Eduardo Habkost
On Python 3,
json.dumps()return a str object, which can't be sent directly through a socket and must be encoded into a bytes object. Use .encode('utf-8'), which will work on both Python 2 and Python 3.Signed-off-by Eduardo Habkost <[email protected]>--- scripts/qmp/qmp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)scripts/qmp/qmp.py +0
-0
scripts/qmp/qmp.py class QEMUMonitorProtocol(object): · line 172
Quoted 8 lines
scripts/qmp/qmp.py +1
-1@@ -166,7 +166,7 @@ class QEMUMonitorProtocol(object): """ self.logger.debug(">>> %s", qmp_cmd) try: - self.__sock.sendall(json.dumps(qmp_cmd)) + self.__sock.sendall(json.dumps(qmp_cmd).encode('utf-8')) except socket.error as err: if err[0] == errno.EPIPE: return
http://lists.nongnu.org/archive/html/qemu-devel/2017-12/msg04047.html
;)
PATCH 3/3 device-crash-test: Use 'python' binary
In reply to Eduardo HabkostNow the script works with Python 3, so we can use the 'python' binary provided by the system.
--- scripts/device-crash-test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/device-crash-test +1 -1
@@ -1,4 +1,4 @@ -#!/usr/bin/env python2.7 +#!/usr/bin/env python # # Copyright (c) 2017 Red Hat Inc #
Signature · 1 line
2.14.3
Re: [Qemu-devel] [PATCH 3/3] device-crash-test: Use 'python' binary
Quoted 13 lines · Eduardo Habkost
Now the script works with Python 3, so we can use the 'python' binary provided by the system.
Signed-off-by Eduardo Habkost <[email protected]>--- scripts/device-crash-test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)scripts/device-crash-test +0
-0
scripts/device-crash-test line 4
Quoted 5 lines
scripts/device-crash-test +1
-1@@ -1,4 +1,4 @@ -#!/usr/bin/env python2.7 +#!/usr/bin/env python # # Copyright (c) 2017 Red Hat Inc #
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|