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:
  • *args (str) – Arguments for the command.

  • cwd (Path | None, default: None) – If provided, change working directories to this path before running the command.

Returns:

Results of the process, containing the standard output and standard error streams.

Return type:

subprocess.CompletedProcess

Raises:
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) – If True, do not raise an exception on failure.

  • stdin (str | None, default: None) – Input for the command.

  • quiet (bool, default: False) – If True, 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 a CommandTimedOutError will be raised if execution time exceeds this timeout.

Raises:
Return type:

None