qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 2/5] python/qemu: Delint the qmp module


From: John Snow
Subject: Re: [PATCH 2/5] python/qemu: Delint the qmp module
Date: Wed, 8 Jan 2020 19:17:10 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.3.0


On 12/27/19 8:40 AM, Wainer dos Santos Moschetta wrote:
> 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>

ACK, thanks for the delinting work here. It will be nice to get our
python code in such a shape that it *could* be packaged if we want to.

Like, if we wanted to publish a standalone QMP client, for instance...

Reviewed-by: John Snow <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
> 

-- 
—js




reply via email to

[Prev in Thread] Current Thread [Next in Thread]