From: Wainer dos Santos Moschetta <wainersm@redhat.com>
To: qemu-devel@nongnu.org
Cc: jsnow@redhat.com, philmd@redhat.com, ehabkost@redhat.com,
crosa@redhat.com
Subject: [PATCH v2 2/5] python/qemu: Delint the qmp module
Date: Tue, 4 Feb 2020 11:11:08 -0300 [thread overview]
Message-ID: <20200204141111.3207-3-wainersm@redhat.com> (raw)
In-Reply-To: <20200204141111.3207-1-wainersm@redhat.com>
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 <wainersm@redhat.com>
Reviewed-by: John Snow <jsnow@redhat.com>
---
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.23.0
next prev parent reply other threads:[~2020-02-04 14:12 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-04 14:11 [PATCH v2 0/5] python/qemu: qmp: Fix, delint and improvements Wainer dos Santos Moschetta
2020-02-04 14:11 ` [PATCH v2 1/5] python/qemu: qmp: Replace socket.error with OSError Wainer dos Santos Moschetta
2020-02-04 14:11 ` Wainer dos Santos Moschetta [this message]
2020-02-04 14:11 ` [PATCH v2 3/5] python/qemu: qmp: Make accept()'s timeout configurable Wainer dos Santos Moschetta
2020-02-05 23:28 ` John Snow
2020-02-04 14:11 ` [PATCH v2 4/5] python/qemu: qmp: Make QEMUMonitorProtocol a context manager Wainer dos Santos Moschetta
2020-02-05 23:43 ` John Snow
2020-02-04 14:11 ` [PATCH v2 5/5] python/qemu: qmp: Remove unnused attributes Wainer dos Santos Moschetta
2020-02-06 14:52 ` [PATCH v2 0/5] python/qemu: qmp: Fix, delint and improvements Philippe Mathieu-Daudé
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200204141111.3207-3-wainersm@redhat.com \
--to=wainersm@redhat.com \
--cc=crosa@redhat.com \
--cc=ehabkost@redhat.com \
--cc=jsnow@redhat.com \
--cc=philmd@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).