[elbe-devel] [PATCH v2 43/66] shellhelper: Fix Pylint

Torben Hohn torben.hohn at linutronix.de
Wed Jun 10 13:42:20 CEST 2020


On Fri, Jun 05, 2020 at 01:07:07PM -0400, Olivier Dion wrote:
> 22:4:   W0231: (super-init-not-called)
> 132:0:  W0102: (dangerous-default-value)
> 146:12: W0612: (unused-variable)
> 15:0:   C0411: (wrong-import-order)
> 
> Signed-off-by: Olivier Dion <dion at linutronix.de>
> ---
>  elbepack/shellhelper.py | 17 ++++++++++++-----
>  1 file changed, 12 insertions(+), 5 deletions(-)
> 
> diff --git a/elbepack/shellhelper.py b/elbepack/shellhelper.py
> index 203b5f4c..b317945f 100644
> --- a/elbepack/shellhelper.py
> +++ b/elbepack/shellhelper.py
> @@ -10,16 +10,18 @@ import logging
>  
>  from subprocess import Popen, PIPE, STDOUT, call
>  
> -from elbepack.log import async_logging
> -
>  from io import TextIOWrapper, BytesIO
>  
> +from elbepack.log import async_logging
> +
>  log = logging.getLogger("log")
>  soap = logging.getLogger("soap")
>  
>  
>  class CommandError(Exception):
> +
>      def __init__(self, cmd, returncode):
> +        super(CommandError, self).__init__(cmd, returncode)
>          self.returncode = returncode
>          self.cmd = cmd
>  
> @@ -129,9 +131,14 @@ def chroot(directory, cmd, env_add=None, **kwargs):
>      chcmd = 'chroot %s %s' % (directory, cmd)
>      do(chcmd, env_add=new_env, **kwargs)
>  
> -def get_command_out(cmd, stdin=None, allow_fail=False, env_add={}):
> +# env_add is read-only; there's no danger
> +# pylint: disable=dangerous-default-value

drop the comment, its obsolete now.

> +def get_command_out(cmd, stdin=None, allow_fail=False, env_add=None):
> +
>      new_env = os.environ.copy()
> -    new_env.update(env_add)
> +
> +    if env_add:
> +        new_env.update(env_add)
>  
>      logging.info(cmd, extra={"context":"[CMD] "})
>  
> @@ -143,7 +150,7 @@ def get_command_out(cmd, stdin=None, allow_fail=False, env_add={}):
>          p = Popen(cmd, shell=True, stdin=PIPE, stdout=w, stderr=STDOUT, env=new_env)
>  
>      async_logging(r, w, soap, log)
> -    stdout, stderr = p.communicate(input=stdin)
> +    stdout, _ = p.communicate(input=stdin)
>  
>      if p.returncode and not allow_fail:
>          raise CommandError(cmd, p.returncode)


after comment remove:

Reviewed-by: Torben Hohn <torben.hohn at linutronix.de>

> -- 
> 2.27.0
> 
> 
> _______________________________________________
> elbe-devel mailing list
> elbe-devel at linutronix.de
> https://lists.linutronix.de/mailman/listinfo/elbe-devel

-- 
Torben Hohn
Linutronix GmbH | Bahnhofstrasse 3 | D-88690 Uhldingen-Mühlhofen
Phone: +49 7556 25 999 18; Fax.: +49 7556 25 999 99

Hinweise zum Datenschutz finden Sie hier (Informations on data privacy 
can be found here): https://linutronix.de/kontakt/Datenschutz.php

Linutronix GmbH | Firmensitz (Registered Office): Uhldingen-Mühlhofen | 
Registergericht (Registration Court): Amtsgericht Freiburg i.Br., HRB700 
806 | Geschäftsführer (Managing Directors): Heinz Egger, Thomas Gleixner



More information about the elbe-devel mailing list