jobflow_remote.remote.host.base module#
- class jobflow_remote.remote.host.base.BaseHost(sanitize: bool = False)[source]#
Bases:
MSONable
Base Host class.
- Parameters:
sanitize – If True text a string will be prepended and appended to the output of the commands, to ease the parsing and avoid failures due to spurious text coming from the host shell.
- abstract execute(command: str | list[str], workdir: str | Path | None = None, timeout: int | None = None) tuple[str, str, int] [source]#
Execute the given command on the host.
- property interactive_login: bool#
True if the host requires interactive actions upon login. False by default. Subclasses should override the method to customize the value.
- abstract mkdir(directory: str | Path, recursive: bool = True, exist_ok: bool = True) bool [source]#
Create directory on the host.
- abstract rmtree(path: str | Path, raise_on_error: bool = False) bool [source]#
Recursively delete a directory tree on a host.
This method must be implemented by subclasses of BaseHost. It is intended to remove an entire directory tree, including all files and subdirectories, on the host represented by the subclass.
- Parameters:
path (str or Path) – The path to the directory tree to be removed.
raise_on_error (bool) – If set to False (default), errors will be ignored, and the method will attempt to continue removing remaining files and directories. Otherwise, any errors encountered during the removal process will raise an exception.
- Returns:
True if the directory tree was successfully removed, False otherwise.
- Return type:
- sanitize_command(cmd: str) str [source]#
Sanitizes a command by adding a prefix and suffix to the command string if sanitization is enabled. The prefix and suffix are the same and are used to mark the parts of the output that should be sanitized. The prefix and suffix are defined by SANITIZE_KEY.
- Parameters:
cmd – The command string to be sanitized
- Returns:
The sanitized command string
- Return type:
- sanitize_output(output: str) str [source]#
Sanitizes the output of a command by selecting the section between the SANITIZE_KEY strings. If the second instance of the key is not found, the part of the output after the key is returned. If the key is not present, the entire output is returned.
- Parameters:
output – The output of the command to be sanitized
- Returns:
The sanitized output
- Return type: