[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 02/46] python/qemu: Delint the qmp module
From: |
Philippe Mathieu-Daudé |
Subject: |
[PULL 02/46] python/qemu: Delint the qmp module |
Date: |
Thu, 6 Feb 2020 22:18:52 +0100 |
From: Wainer dos Santos Moschetta <address@hidden>
This clean up the pylint-3 report on qmp:
************* Module qemu.qmp
python/qemu/qmp.py:1:0: C0111: Missing module docstring (missing-docstring)
python/qemu/qmp.py:17:0: C0111: Missing class docstring (missing-docstring)
python/qemu/qmp.py:21:0: C0111: Missing class docstring (missing-docstring)
python/qemu/qmp.py:25:0: C0111: Missing class docstring (missing-docstring)
python/qemu/qmp.py:29:0: C0111: Missing class docstring (missing-docstring)
python/qemu/qmp.py:33:0: C0111: Missing class docstring (missing-docstring)
python/qemu/qmp.py:33:0: R0205: Class 'QEMUMonitorProtocol' inherits from
object, can be safely removed from bases in python3 (useless-object-inheritance)
python/qemu/qmp.py:80:4: R1710: Either all return statements in a function
should return an expression, or none of them should.
(inconsistent-return-statements)
python/qemu/qmp.py:131:4: R1710: Either all return statements in a function
should return an expression, or none of them should.
(inconsistent-return-statements)
python/qemu/qmp.py:159:4: R1710: Either all return statements in a function
should return an expression, or none of them should.
(inconsistent-return-statements)
python/qemu/qmp.py:245:4: C0111: Missing method docstring (missing-docstring)
python/qemu/qmp.py:249:4: C0111: Missing method docstring (missing-docstring)
python/qemu/qmp.py:252:4: C0111: Missing method docstring (missing-docstring)
python/qemu/qmp.py:255:4: C0111: Missing method docstring (missing-docstring)
Signed-off-by: Wainer dos Santos Moschetta <address@hidden>
Reviewed-by: John Snow <address@hidden>
Reviewed-by: Philippe Mathieu-Daudé <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Philippe Mathieu-Daudé <address@hidden>
---
python/qemu/qmp.py | 51 +++++++++++++++++++++++++++++++++++++---------
1 file changed, 41 insertions(+), 10 deletions(-)
diff --git a/python/qemu/qmp.py b/python/qemu/qmp.py
index 8c6c9847d0..f4e04a6683 100644
--- a/python/qemu/qmp.py
+++ b/python/qemu/qmp.py
@@ -1,5 +1,4 @@
-# QEMU Monitor Protocol Python class
-#
+""" QEMU Monitor Protocol Python class """
# Copyright (C) 2009, 2010 Red Hat Inc.
#
# Authors:
@@ -15,22 +14,34 @@ import logging
class QMPError(Exception):
- pass
+ """
+ QMP base exception
+ """
class QMPConnectError(QMPError):
- pass
+ """
+ QMP connection exception
+ """
class QMPCapabilitiesError(QMPError):
- pass
+ """
+ QMP negotiate capabilities exception
+ """
class QMPTimeoutError(QMPError):
- pass
+ """
+ QMP timeout exception
+ """
-class QEMUMonitorProtocol(object):
+class QEMUMonitorProtocol:
+ """
+ Provide an API to connect to QEMU via QEMU Monitor Protocol (QMP) and then
+ allow to handle commands and events.
+ """
#: Logger object for debugging messages
logger = logging.getLogger('QMP')
@@ -81,7 +92,7 @@ class QEMUMonitorProtocol(object):
while True:
data = self.__sockfile.readline()
if not data:
- return
+ return None
resp = json.loads(data)
if 'event' in resp:
self.logger.debug("<<< %s", resp)
@@ -132,7 +143,7 @@ class QEMUMonitorProtocol(object):
"""
Connect to the QMP Monitor and perform capabilities negotiation.
- @return QMP greeting dict
+ @return QMP greeting dict, or None if negotiate is false
@raise OSError on socket connection errors
@raise QMPConnectError if the greeting is not received
@raise QMPCapabilitiesError if fails to negotiate capabilities
@@ -141,6 +152,7 @@ class QEMUMonitorProtocol(object):
self.__sockfile = self.__sock.makefile()
if negotiate:
return self.__negotiate_capabilities()
+ return None
def accept(self):
"""
@@ -169,7 +181,7 @@ class QEMUMonitorProtocol(object):
self.__sock.sendall(json.dumps(qmp_cmd).encode('utf-8'))
except OSError as err:
if err.errno == errno.EPIPE:
- return
+ return None
raise err
resp = self.__json_read()
self.logger.debug("<<< %s", resp)
@@ -243,14 +255,33 @@ class QEMUMonitorProtocol(object):
self.__events = []
def close(self):
+ """
+ Close the socket and socket file.
+ """
self.__sock.close()
self.__sockfile.close()
def settimeout(self, timeout):
+ """
+ Set the socket timeout.
+
+ @param timeout (float): timeout in seconds, or None.
+ @note This is a wrap around socket.settimeout
+ """
self.__sock.settimeout(timeout)
def get_sock_fd(self):
+ """
+ Get the socket file descriptor.
+
+ @return The file descriptor number.
+ """
return self.__sock.fileno()
def is_scm_available(self):
+ """
+ Check if the socket allows for SCM_RIGHTS.
+
+ @return True if SCM_RIGHTS is available, otherwise False.
+ """
return self.__sock.family == socket.AF_UNIX
--
2.21.1
- [PULL 00/46] Python queue 2020-02-06, Philippe Mathieu-Daudé, 2020/02/06
- [PULL 01/46] python/qemu: qmp: Replace socket.error with OSError, Philippe Mathieu-Daudé, 2020/02/06
- [PULL 02/46] python/qemu: Delint the qmp module,
Philippe Mathieu-Daudé <=
- [PULL 04/46] python/qemu: qmp: Make QEMUMonitorProtocol a context manager, Philippe Mathieu-Daudé, 2020/02/06
- [PULL 05/46] python/qemu: qmp: Remove unnused attributes, Philippe Mathieu-Daudé, 2020/02/06
- [PULL 03/46] python/qemu: qmp: Make accept()'s timeout configurable, Philippe Mathieu-Daudé, 2020/02/06
- [PULL 06/46] python/qemu: accel: Fix kvm_available() on ppc64le, Philippe Mathieu-Daudé, 2020/02/06
- [PULL 07/46] qemu-deprecated: Remove text about Python 2, Philippe Mathieu-Daudé, 2020/02/06
- [PULL 08/46] python: Treat None-return of greeting cmd, Philippe Mathieu-Daudé, 2020/02/06
- [PULL 09/46] python/qemu/machine: Allow to use other serial consoles than default, Philippe Mathieu-Daudé, 2020/02/06
- [PULL 10/46] Acceptance tests: Extract _console_interaction(), Philippe Mathieu-Daudé, 2020/02/06
- [PULL 11/46] Acceptance tests: Add interrupt_interactive_console_until_pattern(), Philippe Mathieu-Daudé, 2020/02/06
- [PULL 12/46] travis.yml: install rpm2cpio for acceptance tests, Philippe Mathieu-Daudé, 2020/02/06