Mondaic

salvus.flow.executors.remote_io_executor

salvus.flow.executors.remote_io_executor salvus flow executors remote_io_executor

Remote I/O functionality.

Classes

LocalSFTPClient

class LocalSFTPClient(builtins.object):
    def __init__(self): ...

Everything is based on SSH but for the local site its not needed. Thus we implement a custom SFTP client on top of direct file system operations.

Methods
close()
def close(self) -> None: ...

Mock method.

Returns None
get()
def get(
    self, remotepath: str, localpath: str, callback: typing.Callable | None
) -> None: ...

Get a remote file.

Parameters
  • remotepath str — Remote path.
  • localpath str — Local path.
  • callback typing.Callable | None — Callback function.
Returns None
getfo()
def getfo(
    self, remotepath: str, fl: typing.IO, callback: typing.Callable | None
) -> None: ...

Get a remote file and copy it to an open file handle.

Parameters
  • remotepath str — Remote path.
  • fl typing.IO — Open file handle.
  • callback typing.Callable | None — Callback function.
Returns None
listdir()
def listdir(self, path: str) -> list[str]: ...

List the contents of a directory.

Parameters
  • path str — The path.
Returns list[str]
mkdir()
def mkdir(self, path: str, mode: int = 511) -> None: ...

Create directory.

Parameters
  • path str — The path.
  • mode int — Permission mode.
Returns None
put()
def put(
    self, localpath: str, remotepath: str, callback: typing.Callable | None
) -> None: ...

Copy a local file to remote site.

Parameters
  • localpath str — Local file.
  • remotepath str — Remote path.
  • callback typing.Callable | None — Callback function.
Returns None
putfo()
def putfo(
    self, fl: typing.IO, remotepath: str, callback: typing.Callable | None
) -> None: ...

Put the contents of an open file handle to a remote path.

Parameters
  • fl typing.IO — Open file handle.
  • remotepath str — Remote path.
  • callback typing.Callable | None — Callback function.
Returns None
rmdir()
def rmdir(self, path: str) -> None: ...

Remove a directory.

Parameters
  • path str — The path.
Returns None
stat()
def stat(self, path: str) -> os.stat_result: ...

Return stat().

Parameters
  • path str — The path.
Returns os.stat_result
def unlink(self, path: str) -> None: ...

Unlink the path.

Parameters
  • path str — The path.
Returns None

LocalSSHClient

class LocalSSHClient(builtins.object):
    def __init__(self): ...

Fake “local” SSH client.

Methods
close()
def close(self) -> None: ...

Mock method.

Returns None
connect()
def connect(self) -> None: ...

Mock method.

Returns None
exec_command()
def exec_command(self) -> None: ...

Mock method.

Returns None
load_system_host_keys()
def load_system_host_keys(self) -> None: ...

Mock method.

Returns None
open_sftp()
def open_sftp(self) -> None: ...

Mock method.

Returns None
set_missing_host_key_policy()
def set_missing_host_key_policy(self) -> None: ...

Mock method.

Returns None

OSType

class OSType(enum.Enum):
    def __init__(self): ...

Enumerate the type of operating system.

RemoteIOExecutor

class RemoteIOExecutor(builtins.object):
    def __init__(self): ...

Class to encapsulate SSH/SFTP client initialization and remote I/O functionality.

Not useful on its own - does require self.name and self.config to be available.

Attributes
file_path_type type[pathlib.PurePosixPath | pathlib.PureWindowsPath]

Returns the type of file paths for the given site.

home_dir pathlib.PurePosixPath | pathlib.PureWindowsPath

The home directory.

os_type OSType

Returns the type of the operating system.

Subclasses can overwrite this.

sftp_client paramiko.sftp_client.SFTPClient | LocalSFTPClient

Get the sftp client instance.

Will be initialized upon the first access.

ssh_client paramiko.client.SSHClient | LocalSSHClient

Get the ssh client instance.

Will be initialized upon the first access.

Methods
execute_command()
def execute_command(
    self,
    command: str,
    assert_ok: bool = True,
    environment: dict[str, str] | None = None,
) -> tuple[int, list[str], list[str]]: ...

Execute the command.

Parameters
  • command str — The command to run as a string.
  • assert_ok bool — Raise if the command does not exist with a code of 0.
  • environment dict[str, str] | None — Environment variables to be set for this command.
Returns tuple[int, list[str], list[str]]
is_folder_writeable()
def is_folder_writeable(self, path: _RemotePathInputType) -> bool: ...

Return True if the user has write permissions in the chosen folder.

Parameters
  • path _RemotePathInputType — Path on the remote machine.
Returns bool
remote_exists()
def remote_exists(self, path: _RemotePathInputType) -> bool: ...

Check if a remote file or directory exists.

Parameters
  • path _RemotePathInputType — Path to check.
Returns bool
remote_get()
def remote_get(
    self,
    remotepath: _RemotePathInputType,
    localpath: io.BytesIO | pathlib.Path,
    show_progressbar: bool = False,
) -> None: ...

Get a remote file.

Parameters
  • remotepath _RemotePathInputType — Remote file to get.
  • localpath io.BytesIO | pathlib.Path — Local path to save to Can be a file or a file like object.
  • show_progressbar bool — Show a progressbar or not.
Returns None
remote_listdir()
def remote_listdir(self, path: _RemotePathInputType) -> list[str]: ...

List the contents of a remote directory.

Just dispatches to the underlying representation.

Parameters
  • path _RemotePathInputType — Remote path whose contents to list.
Returns list[str]
remote_mkdir()
def remote_mkdir(
    self, path: _RemotePathInputType, mode: int = 511
) -> None: ...

Create a directory on the remote or local machine.

Parameters
  • path _RemotePathInputType — Directory to create.
  • mode int — Permissions for the new directory.
Returns None
remote_put()
def remote_put(
    self,
    localpath: io.BytesIO | pathlib.Path,
    remotepath: _RemotePathInputType,
    show_progressbar: bool = False,
) -> None: ...

Copy a local file to a remote path.

Parameters
  • localpath io.BytesIO | pathlib.Path — Local file to copy. Can be a file like object.
  • remotepath _RemotePathInputType — Where to copy to.
  • show_progressbar bool — Show a progressbar or not.
Returns None
remote_rmdir()
def remote_rmdir(
    self, path: _RemotePathInputType, verbosity: int = 1
) -> None: ...

Remotely and recursively delete a remote folder and its contents.

Parameters
  • path _RemotePathInputType — Remote path to delete.
  • verbosity int — Verbosity level.
Returns None
safe_remote_rmdir()
def safe_remote_rmdir(
    self, path: _RemotePathInputType, allow_failure: bool, verbosity: int = 1
) -> None: ...

Convenience wrapper that optionally allows the remote_rmdir() command to fail. Useful for some networked file systems.

Parameters
  • path _RemotePathInputType — Remote path to delete.
  • allow_failure bool — Whether to allow failure or not.
  • verbosity int — Verbosity level.
Returns None