Command#
- class phalanx.storage.command.Command(command)#
Bases:
object
Wrapper around executing external commands.
This class provides some generic wrappers around subprocess that are helpful for executing external commands, checking their status, and optionally capturing their output in a consistent way. It expects commands to take the form of a subcommand followed by arguments. It is intended for use by storage classes that perform operations via external commands.
- Parameters:
command (
str
) – Base command. If this is not a full path, the command will be found on the user’s PATH.
Methods Summary
capture
(*args[, cwd])Run the command, checking for errors and capturing the output.
run
(*args[, cwd, ignore_fail, quiet, stdin, ...])Run the command with the provided arguments.
Methods Documentation
- capture(*args, cwd=None)#
Run the command, checking for errors and capturing the output.
This method should only be called by subclasses, which should provide a higher-level interface used by the rest of the program.
- Parameters:
- Returns:
Results of the process, containing the standard output and standard error streams.
- Return type:
- Raises:
CommandFailedError – Raised if the command failed.
subprocess.SubprocessError – Raised if the command could not be executed at all.
- run(*args, cwd=None, ignore_fail=False, quiet=False, stdin=None, timeout=None)#
Run the command with the provided arguments.
Standard output and standard error are not redirected and will go to the standard output and error of the caller. This method should only be called by subclasses, which should provide a higher-level interface used by the rest of the program.
- Parameters:
*args (
str
) – Arguments to the command.cwd (
Path
|None
, default:None
) – If provided, change working directories to this path before running the command.ignore_fail (
bool
, default:False
) – IfTrue
, do not raise an exception on failure.quiet (
bool
, default:False
) – IfTrue
, discard standard output. Standard error is still displayed on the process standard error stream.timeout (
timedelta
|None
, default:None
) – If given, the command will be terminated and aCommandTimedOutError
will be raised if execution time exceeds this timeout.
- Raises:
CommandFailedError – Raised if the command failed and
ignore_fail
was not set toTrue
.CommandTimedOutError – Raised if
timeout
was given and the command took longer than that to complete.subprocess.SubprocessError – Raised if the command could not be executed at all.
- Return type: