Command#
- class nublado.startup.storage.command.Command(*, capture_output=True, ignore_fail=False, text=True, logger=None)#
Bases:
objectWrapper around executing external commands.
This class provides a generic wrapper around subprocess that is helpful for executing external commands, checking their status, and optionally capturing their output in a consistent way.
It represents a slight simplification of the standard ~subprocess.run() function. It is intended for use by storage classes that perform operations via external commands, which are expected to constrain the arguments to the command and the parameters to the run() call.
- Parameters:
capture_output (
bool, default:True)ignore_fail (
bool, default:False)text (
bool, default:True)logger (
Optional[BoundLogger], default:None)
Methods Summary
run(*args[, cwd, env, timeout])Run the command with the provided arguments.
Methods Documentation
- run(*args, cwd=None, env=None, timeout=None)#
Run the command with the provided arguments.
- Parameters:
*args (
str) – Arguments to the command. The first argument is the command itself, and if not fully-qualified must exist somewhere in the caller’sPATH.cwd (
Optional[Path], default:None) – If provided, change working directories to this path before running the command.env (
Optional[dict[str,str]], default:None) – If provided, use this dictionary as the process environment. If not, use the caller’s process environment.timeout (
Union[timedelta,float,None], default:None) – If given, the command will be terminated and aCommandTimedOutErrorwill be raised if execution time exceeds this timeout.
- Raises:
CommandFailedError – Raised if the command failed and
ignore_failwas not set toTrue.CommandTimedOutError – Raised if
timeoutwas given and the command took longer than that to complete.subprocess.SubprocessError – Raised if the command could not be executed at all.
- Return type: