12 commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0b05eb4c37 | |||
| bb13aea694 | |||
| 3bda9bc826 | |||
| f37f025b17 | |||
| 02697af568 | |||
| 52dd3b8f21 | |||
| 76b702f5b4 | |||
| 888c1e7f16 | |||
| 67a2931f5e | |||
| 1325222fbd | |||
| fadf1bca49 | |||
| 3e897f4df8 |
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
| 0b05eb4c37 |
ExecContext: Make mode:xxx an enum
This commit introduces two new types, Input and InputMode. They replace the more error-prone special strings cmd_input could be used with. InputMode is an Enum, and Input can be either IntputMode, a string or None. Signed-off-by: Jan Lindemann <jan@janware.com> |
|||
| bb13aea694 |
lib.ExecContext: Fix ignored --interactive
Whether or not the CallContext.interactive property should be True or False, and hence, a call should be processed interactively, depends on multiple factors, constituting matrix of options with multiple preferences. --interactive is the application default and can be true, false,
or auto - A call can be explicitly invoked as interactive, non-interactive
or auto via the cmd_input parameter to ExecContext.run() This commit adds more "mode:" options to make the latter more explicit. It takes preference over the global --interactive parameter: Global --interactive is only given a chance to decide if cmd_input is None (default) or mode:opt-interactive. This commit also fixes a bug: --interactive is ignored because the interactive argument passed to ExecContext's constructor is ignored later on in calls to the wrapped _run() and _sudo() methods. Signed-off-by: Jan Lindemann <jan@janware.com> |
|||
| 3bda9bc826 |
lib.ExecContext.sudo(): Default None mod_env to {}
mod_env can be None. Make it an empty dict in that case to take a little burden off the implementations in the derived classes. Signed-off-by: Jan Lindemann <jan@janware.com> |
|||
| f37f025b17 |
lib.SSHClient: Move to lib.ec
SSHClient in an ExecContext, hence it's better off in lib.ec, move it there and adapt the references. Signed-off-by: Jan Lindemann <jan@janware.com> |
|||
| 02697af568 |
lib.ExecContext: Align .sudo() prototype to .run()
ExecContext's .sudo() omits many of run()'s parameters, and this commit adds them. To avoid redundancy around repeating and massaging the long parameter list of both functions and their return values, it also adds some deeper changes: - Make run(), _run(), sudo() and _sudo() always return instances of
Result. Before it was allowed to return a triplet of stdout,
stderr, and exit status. - Have ExecContext stay out of the business of decoding the result
entirely. Result provides a convenience method .decode()
operating on stdout and stderr and leaves the decision to the
caller. This entails miniscule adaptations in calling code, namely in
App.os_release, util.get_profile_env() and CmdListRepos._run(). - Wrap the _run() and _sudo() callbacks in a context manager object
of type CallContext to avoid code duplication. - Consistently name the first argument to run(), _run(), sudo() and
_sudo() "cmd", not "args". The latter suggests that the caller is
omitting the executable, which is not the case. Signed-off-by: Jan Lindemann <jan@janware.com> |
|||
| 52dd3b8f21 |
lib.ExecContext.run(): Push code up into base class
Take implementation burden from the derived classes _run() callback by moving the respective code into the run() wrapper methods of the base class. Signed-off-by: Jan Lindemann <jan@janware.com> |
|||
| 76b702f5b4 |
lib.ExecContext.create(): Add method
Add a class method to instantiate an ExecContext by its URI. Signed-off-by: Jan Lindemann <jan@janware.com> |
|||
| 888c1e7f16 |
lib.ExecContext.__init__(): Add parameter uri
Take a positional uri argument to the constructor of ExecContext, forcing SSHClient to follow suit. The latter was instantiated with a hostname as only argument up to now, which still works as a special case of an uri. Signed-off-by: Jan Lindemann <jan@janware.com> |
|||
| 67a2931f5e |
App: Support --verbose
Add the --verbose global option, which is made available as the App.verbose property. Some functions still take a verbose parameter, but the type of these parameters is converted from bool to bool|None. The idea is that, if they are None, their verbosity falls back to the global default. Signed-off-by: Jan Lindemann <jan@janware.com> |
|||
| 1325222fbd |
lib.ExecContext,Local: Remove callback default params
Remove defaults from protected callback function parameters. They have to be decided by the base class's public API. Signed-off-by: Jan Lindemann <jan@janware.com> |
|||
| fadf1bca49 |
lib.util.run_cmd(): Add parameter ec: ExecContext
Allow to specify the ExecContext in a call to run_cmd(). This effectively makes run_cmd() an thin wrapper around ExecContext.run(), which is what's going to be used in the future. The wrapper is for backwards-compatibility. Signed-off-by: Jan Lindemann <jan@janware.com> |
|||
| 3e897f4df8 |
lib.Distro, ExecContext: Add classes, refactor lib.distro
The code below lib.distro, as left behind by the previous commit, is geared towards being directly used as a command-line API. This commit introduces the abstract base class Distro, a proxy for distribution-specific interactions. The proxy abstracts distro specifics into an API with proper method prototypes, not argparse.Namespace contents, and can thus be more easily driven by arbitrary code. The Distro class is initialized with a member variable of type ExecContext, another new class introduced by this commit. It is designed to abstract the communication channel to the distribution instance. Currently only one specialization exists, Local, which interacts with the distribution and root file system it is running in, but is planned to be subclassed to support interaction via SSH, serial, chroot, or chains thereof. Signed-off-by: Jan Lindemann <jan@janware.com> |