Commit Graph

13 Commits

Author SHA1 Message Date
Marcus Schäfer
8920eee324
Add silent flag to CommandCapabilities
an instance of CommandCapabilities allows to check for specific
options of a command. If the parsing of options has failed a
warning message is created by default. Under certain circumstances
like the check for the --help option of setfiles, such a warning
message can be misleading information in the build log file.
Therefore the new silent flag allows to suppress the warning
message and the flag is used for the capabilities of the
setfiles utility. This Fixes #2350
2024-02-27 21:06:19 +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
09b9d2a491
Fixed use of CommandCapabilities
The class allows to check for data produced on stdout
and stderr. However, programs reporting data on stderr
usually fails with an exit code != 0. If the command
is not called with raise_on_error=False it will never
be possible to catch information from stderr. As we
don't know if programs returns a failed exit code
even on their e.g --usage message we should always
pass the no raise option to make this more useful
2022-06-21 21:50:59 +02:00
David Cassany
c8d5c5a02e
Make CommandCapabilities.check_version take the longest match
This commit ensures that when trying to parse the version of a tool
the comparison is done with the longest match for the given regular
expression. This solves cases such in `grub2` where the tool name
already provides some digit that could be seen as a version.
2020-04-16 10:25:21 +02: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
Alberto Planas
0c095a98b1 Replace @staticmethod with @classmethod when needed
@classmethod are used in Python to represent methods that can
query and update the class (cls parameter). Is expected to be
used for metaprograming, or advanced techniques that require the
access to the class itself, before we have an instance.

@staticmethod are used to associate a function to a class. It will
not be have access to the instance (self) not the class (cls). In
other programming languages are known as class methods.

This patch replace all the @classmethod with @staticmethod when
there is not need to access to the cls parameter, because the
intention is to be used as normal functions.
2019-03-26 16:27:43 +01:00
Thomas Schraitle
3156bd14d8
Use cls in @classmethods instead of self
For consistency reasons.
2018-12-20 08:47:43 +01:00
Marcus Schäfer
afcbe93826
Fixed some code smells
* Use of unused variables, and dangerous defaults
* Update of design patterns on pylint and landscape
2018-07-11 10:31:04 +02:00
David Cassany
9eab3eebf9 Cleanup of the utils API docs 2018-04-17 18:05:09 +02:00
Marcus Schäfer
135fdcf4da
Extend has_option_in_help to also check error data 2018-03-02 10:04:13 +01:00
David Cassany
afbf2687c8 Extend CommandCapabilities to also check version 2018-01-16 16:53:59 +01:00
David Cassany Viladomat
02dc8e32e1
Update locale settings (#579)
* Use systemd-firstboot in order config basic settings

This commit updates locale and keyboard settings in order to make
use of the systemd tools, as this will be the only valid method starting
from SLE15.

Fixes #577

* Added CommandCapabilities utils class
2018-01-16 14:10:31 +01:00