Commit Graph

19 Commits

Author SHA1 Message Date
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
Alexandre Detiste
fb69627ad3
Use unittest.mock from core python everywhere
mock was an independent module that has been merged into the Python standard library.
2024-02-18 22:15:30 +01:00
Marcus Schäfer
41875f57ea
Add support for creating delta containers
Add new attribute delta_root="true|false" which in combination with
derived_from="OCI-base-image" allows to create a delta root tree
only containing the differences between the OCI-base-image and the
actions taken by the kiwi prepare step. Based on the delta root tree
the subsequent image creation process starts. Such an incomplete
root tree is only useful under certain circumstances which is also
the reason why the feature is only available to the oci and docker
image types.
2023-03-16 17:06:15 +01:00
Marcus Schäfer
3698e31bdf
Fixed scope of remove_hierarchy
The remove_hierarchy method walked through the entire path
it was given. That included the root path which is beyond
its scope. This Fixes #1515
2020-07-22 11:32:28 +02:00
David Cassany
7e43b86cd9
Fix string formatting
After a flake8 upgrade to v3.8.0 these changes were required to pass
the `tox -e check` validation.
2020-05-12 14:51:36 +02:00
David Cassany
75a91385e4
Do not create empty macros file
This commit makes sure to empty RPM macros files are created during
the build. Additionally it also ensures that no needless `rm` and `mkdir`
calls are done.

Fixes #1316
2020-02-18 14:08:30 +01:00
David Cassany
dd4d2ed78d
Add new root option in Path.which method
This commit adds to Path utility a couple of methods to manipulate
paths. One to rebase given paths to a new root and another one to
trim the given root path. In addition a new option in Path.which
is added to allow searches into chroot evironments.

Fixes #1276
2019-11-27 11:07:49 +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
3fd117187f
Fixed path_test unit test
The code there checked for the message of an exception
but recent changes in pytest did not allow to do it that
way anymore.
2019-07-01 11:31:20 +02:00
Dan Čermák
d28a7e935c
New method: Path.access - thin wrapper arround os.access
This function calls os.access, but first checks whether the input parameters are
sane, instead of simply returning false when the file in question does not exist
or an invalid mode was specified.
2019-03-26 15:20:49 +01:00
Marcus Schäfer
d29ba29276 Add restrictions to Path.remove_hierarchy
When an iso file is used as repo, this iso will be loop mounted on
the host and bind mounted into the image root as long as the image
builds. When the mount is released a recursive cleanup of the complete
path happens. This is done by calling Path.remove_hierarchy. However
if a sub path of the mount path contains a system root directory
which is mandatory for the Linux root system it is not allowed
to be deleted even if it is empty at the time of the mount cleanup.
Thus this patch adds a lookup for protected directory names and
only runs the recursive deletion as long as no protected member
is part of the path. This fixes bsc#1080301
2018-02-12 15:56:49 +01:00
Marcus Schäfer
6cc0b2085d Flake cleanup for unit tests 2017-03-07 13:03:10 +01:00
Marcus Schäfer
2fd177bd27
Better logging if Path.which doesn't find the file 2016-08-11 10:43:54 +02:00
David Cassany
0c4256e719 Updated Command to use Path.which
Command.run and Command.call now make use of Path.which in order
to test if the command is available or not. Also Path.which has
been extended in order to support custom environments and to be
able to test file permissions (read. write, execute)
2016-08-10 16:38:33 +02:00
Marcus Schäfer
92899c2064
Implement Path.which
Python provides methods to do this but we can't rely on them
to be available in all python versions
2016-07-07 11:32:47 +02:00
Marcus Schäfer
e6cc5bfa09 Move from nose to pytest
nose is no longer maintained, thus we have to move to another
testing system. This commit updates the tox setup and all tests
to use pytest instead of nose.
2016-03-14 12:23:14 +01: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
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