[dts] [PATCH V1 1/2] QMP: optimization file qemu-ga-client and qmp.py
lihong
lihongx.ma at intel.com
Thu Jun 4 03:38:19 CEST 2020
1. modify code to support python3
2. return None string if file not exist when use cat command
Signed-off-by: lihong <lihongx.ma at intel.com>
---
dep/QMP/qemu-ga-client | 10 ++++++----
dep/QMP/qmp.py | 4 ++--
2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/dep/QMP/qemu-ga-client b/dep/QMP/qemu-ga-client
index 46676c3..caf44b1 100755
--- a/dep/QMP/qemu-ga-client
+++ b/dep/QMP/qemu-ga-client
@@ -68,7 +68,7 @@ class QemuGuestAgentClient:
def __file_read_all(self, handle):
eof = False
- data = ''
+ data = b''
while not eof:
ret = self.qga.file_read(handle=handle, count=1024)
_data = base64.b64decode(ret['buf-b64'])
@@ -77,7 +77,10 @@ class QemuGuestAgentClient:
return data
def read(self, path):
- handle = self.qga.file_open(path=path)
+ try:
+ handle = self.qga.file_open(path=path)
+ except:
+ return ''
try:
data = self.__file_read_all(handle)
finally:
@@ -162,7 +165,6 @@ class QemuGuestAgentClient:
except self.qga.timeout:
return
-
def _cmd_cat(client, args):
if len(args) != 1:
print('Invalid argument')
@@ -259,7 +261,7 @@ def main(address, cmd, args):
try:
client = QemuGuestAgentClient(address)
- except QemuGuestAgent.error, e:
+ except QemuGuestAgent.error as e:
import errno
print(e)
diff --git a/dep/QMP/qmp.py b/dep/QMP/qmp.py
index 9e6f4cf..430887d 100755
--- a/dep/QMP/qmp.py
+++ b/dep/QMP/qmp.py
@@ -108,7 +108,7 @@ class QEMUMonitorProtocol:
been closed
"""
try:
- self.__sock.sendall(json.dumps(qmp_cmd))
+ self.__sock.sendall(str.encode(json.dumps(qmp_cmd)))
except socket.error as err:
if err[0] == errno.EPIPE:
return
@@ -135,7 +135,7 @@ class QEMUMonitorProtocol:
if not ret:
return
else:
- if 'error' in ret:
+ if 'error' in ret.keys():
raise Exception(ret['error']['desc'])
return ret['return']
--
2.7.4
More information about the dts
mailing list