[libvirt] [jenkins-ci PATCH v2 02/12] lcitool: Stub out Python implementation

Katerina Koukiou kkoukiou at redhat.com
Tue Jul 17 09:16:35 UTC 2018


On Thu, Jul 12, 2018 at 05:19:19PM +0200, Andrea Bolognani wrote:
> Doesn't do much right now, but it's a start :)
> 
> Signed-off-by: Andrea Bolognani <abologna at redhat.com>
> ---
>  guests/lcitool | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 69 insertions(+)
>  create mode 100755 guests/lcitool
> 
> diff --git a/guests/lcitool b/guests/lcitool
> new file mode 100755
> index 0000000..1cba8ad
> --- /dev/null
> +++ b/guests/lcitool
> @@ -0,0 +1,69 @@
> +#!/usr/bin/env python
> +
> +# lcitool - libvirt CI guest management tool
> +# Copyright (C) 2017-2018  Andrea Bolognani <abologna at redhat.com>
> +#
> +# This program is free software; you can redistribute it and/or modify it
> +# under the terms of the GNU General Public License as published by the
> +# Free Software Foundation; either version 2 of the License, or (at your
> +# option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful, but
> +# WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
> +# Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License along
> +# with this program; if not, write to the Free Software Foundation, Inc.,
> +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
> +
> +import argparse
> +import sys
> +import textwrap
> +
> +# This is necessary to maintain Python 2.7 compatibility
> +try:
> +    import configparser
> +except ImportError:
> +    import ConfigParser as configparser

This import is unused here. Maybe we can introduce it at the point we
actually start using it?

> +
> +class Error(Exception):
> +
> +    def __init__(self, message):
> +        self.message = message
> +
> +class Application:
> +
> +    def __init__(self):
> +        self._parser = argparse.ArgumentParser(
> +            conflict_handler = "resolve",
> +            formatter_class = argparse.RawDescriptionHelpFormatter,
> +            description = "libvirt CI guest management tool",
> +            epilog = textwrap.dedent("""
> +                supported actions:
> +                """),
> +        )
> +        self._parser.add_argument(
> +            "-a",
> +            metavar = "ACTION",
> +            required = True,
> +            help = "action to perform (see below)",
> +        )
> +
> +    def run(self):
> +        cmdline = self._parser.parse_args()
> +        action = cmdline.a
> +
> +        method = "_action_{}".format(action.replace("-", "_"))
> +
> +        if hasattr(self, method):
> +            getattr(self, method).__call__()
> +        else:
> +            raise Error("Invalid action '{}'".format(action))
> +
> +if __name__ == "__main__":
> +    try:
> +        Application().run()
> +    except Error as e:
> +        sys.stderr.write("{}: {}\n".format(sys.argv[0], e.message))
> +        sys.exit(1)
> -- 
> 2.17.1
> 
> --
> libvir-list mailing list
> libvir-list at redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list

I am not very good with python myself, however whenever I am using it I
try to follow coding style standards enforced by pep8 (currently renamed
pycodestyle).

So here is the output of pep8 for this script, feel free to ignore it if
you don't agree though I encourage that we enforce pep8 for the python
scripts here.

$ pycodestyle guests/lcitool
guests/lcitool:30:1: E302 expected 2 blank lines, found 1
guests/lcitool:35:1: E302 expected 2 blank lines, found 1
guests/lcitool:39:29: E251 unexpected spaces around keyword / parameter equals
guests/lcitool:39:31: E251 unexpected spaces around keyword / parameter equals
guests/lcitool:40:28: E251 unexpected spaces around keyword / parameter equals
guests/lcitool:40:30: E251 unexpected spaces around keyword / parameter equals
guests/lcitool:41:24: E251 unexpected spaces around keyword / parameter equals
guests/lcitool:41:26: E251 unexpected spaces around keyword / parameter equals
guests/lcitool:42:19: E251 unexpected spaces around keyword / parameter equals
guests/lcitool:42:21: E251 unexpected spaces around keyword / parameter equals
guests/lcitool:48:20: E251 unexpected spaces around keyword / parameter equals
guests/lcitool:48:22: E251 unexpected spaces around keyword / parameter equals
guests/lcitool:49:21: E251 unexpected spaces around keyword / parameter equals
guests/lcitool:49:23: E251 unexpected spaces around keyword / parameter equals
guests/lcitool:50:17: E251 unexpected spaces around keyword / parameter equals
guests/lcitool:50:19: E251 unexpected spaces around keyword / parameter equals

To actually run the pep8 you don't have to install it globally on your
system, but you can create a virtualenv and install it there with
"pip install pep8".
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20180717/92fe5e3c/attachment-0001.sig>


More information about the libvir-list mailing list