Commit Graph

28 Commits

Author SHA1 Message Date
Marcus Schäfer
ba27291de9
Drop destructor from CommandProcess
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.
2024-02-19 16:37:33 +01:00
Dan Čermák
48817a6441
Refactor Command class
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>
2024-02-19 16:33:24 +01:00
Marcus Schäfer
9b78b7e288
Fixed no-self-use issue from codacy report
The Logger.progress method is actually a static method
and should be used as such
2020-12-17 10:37:24 +01:00
Marcus Schäfer
bdb7123fa1
Refactor use of logging facility
Use getLogger method instead of a global log object
Also use caplog fixture to capture log messages in
unit tests. This Fixes #1244
2019-10-23 17:54:27 +02:00
Dan Čermák
b015b91679
Stop inheriting from object
This is no longer required in Python3
2019-08-22 15:43:27 +02:00
Marcus Schäfer
a2ea326d09
Fixed left over import of six module
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.
2019-07-26 16:03:03 +02:00
Marcus Schäfer
1566750242
Drop support for python2
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
2019-07-10 11:58:57 +02:00
Marcus Schäfer
892c6332f2
Add API for package manager returncode validation
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
2019-02-06 17:13:56 +01:00
David Cassany
fda157296e
Add Codec utils for bytes literals decoding
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
2018-10-08 15:48:51 +02:00
Marcus Schäfer
75b1e2d6c7
Fixed docstring :rtype: values
In Python the string type name is str not string
2018-04-18 10:33:15 +02:00
Marcus Schäfer
f7c64d4443
Fixup docstring typos per review 2018-04-17 12:03:20 +02:00
Marcus Schäfer
41970d3dd4
Cleanup api doc strings
This cleans up and fixes the api documentation for the
public interface of the projects toplevel source code
files and Fixes #697
2018-04-16 16:10:04 +02:00
Marcus Schäfer
1a5257a0e8 Prevent use of project relative import statements
For details on the motivation of this change please visit:
https://wiki.python.org/moin/FutureProofPython
2017-03-07 11:23:37 +01:00
Marcus Schäfer
20b02bf683
Explain why bytes type is redefined
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
2016-07-25 10:52:20 +02:00
Marcus Schäfer
22c2227e28
Use six.Iterator instead of global object builtin
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
2016-07-25 10:43:23 +02:00
Marcus Schäfer
319fb9e6e4
Adapt to common python style
Private methods should start with _f() not __f()
2016-06-15 16:27:45 +02:00
Bo Maryniuk
80900e46c5 Bring byte strings to Py2 compatibility in ISO 2016-06-08 11:46:36 +02:00
Bo Maryniuk
6ee5981bd5 Make iterators Py2 comptible 2016-06-07 23:44:33 +02:00
Thomas Schraitle
741e3a8c04 Use iterator protocol instead of StopIteration
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.
2016-05-01 19:18:51 +02:00
Marcus Schäfer
8e6812dcf6
Update inline API documentation 2016-04-11 15:09:26 +02:00
Marcus Schäfer
58861fdcc8 Update inline API documentation 2016-04-10 22:51:20 +02:00
Marcus Schäfer
40e6308aa9 Port application from python 2.7 to 3.4
For new applications like this kiwi version and its use cases
it is better to base it on a more recent python version
2016-02-17 22:38:38 +01:00
Marcus Schäfer
f540dc4b04
Fixed CommandIterator
check for output before sending an iteration stop
2016-02-07 18:12:31 +01:00
Marcus Schäfer
638083fb76
Prevent duplicate error logging 2016-02-03 22:32:33 +01:00
Marcus Schäfer
2e9f596c4a
Refactor CommandProcess class
Use an iterator class to run through the process. implement
poll variants explicit and clear structured
2016-02-03 22:14:52 +01:00
Marcus Schäfer
5d6fa811f5
Fixing landscape issues 2016-01-18 17:30:38 +01:00
Marcus Schäfer
61ea327a4c
Added isolinux bootloader support 2015-12-09 10:39:21 +01:00
Marcus Schäfer
09daca60c0
KIWI - appliance builder next generation
a rewrite of the current kiwi from https://github.com/openSUSE/kiwi
2015-12-05 16:17:10 +01:00