There is code that sends a SIGTERM to the process in case
there is no error code information. I believe in this case
sending SIGTERM will not kill the process (defunct) and I
also don't see in what good condition we would be entering
this state.
Command.run() currently has a bit of a confusing behavior: if raise_on_error is
False and the executable is not found, then a weird CommandT is returned (return
code is -1 and stdout+stderr is None). This makes it possible to hanlde command
not found errors separately, but it makes that needlessly verbose. So instead,
let's just return None in *this* special case.
That in turn uncovered, that in most cases when we set `raise_on_error=True`, we
actually want an error if the command is not present but no error if the command
fails to execute (e.g. because it returns -1 if you run `$cmd --version`). Hence we
introduce the flag `raise_on_command_not_found`, which causes an exception to
be raised if the command is not found. This makes it independent of the
`raise_on_error` flag.
Additionally, we add a small optimization: if command starts with /, then we
assume it's a full path and we omit the call to which (and just check whether it
exists).
Co-authored-by: Marcus Schäfer <marcus.schaefer@gmail.com>
The use of the six compat module was needed to support py2
With the drop of py2 support all of six was no longer needed.
However this one was overlooked.
Python2 is announced to be unmaintained from Jan 2020.
KIWI supports Python 2.7 and it should not support any python version that
is not maintained upstream. This Fixes#1036
Allow to validate the return code from a package manager
operation. In case of zypper the standard UNIX return
code validation does not apply. Return codes from zypper
which are >= 100 are not treated as an error anymore
In case of a literal decoding failure it tries to decode
the result in utf-8. This is handy in python2 environments where
python and the host might be using different charset configurations.
In python3 this issue seams to be solved.
Fixes#829 and bsc#1110871
In python2 bytes is string which is different from the bytes
type in python3. The bytes type from the builtins generalizes
this type to be bytes always. However the redefinition of the
bytes type is marked as Smell in landscape. Thus the code
should at least inform why this is done
The use of six.Iterator as base class for the CommandIterator
seems more clear and explicit compared to the global object
type overwritten by the builtins import. Fixes Smell reported
by landscape
CommandIterator contains already the __iter__ magic method. We don't
need to manually use while and next() in order to advance to the next
element.
=> Code refactored to "for line in self.command" which does exactly the
same job, but is better readable. Plus we avoid the nasty try...except
block.