Mondaic
This API reference is not for the latest stable Salvus version.

salvus.flow.sites.remote_io_site

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.

Initialize self. See help(type(self)) for accurate signature.

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

Mock method.

Returns None
get()
def get(
    self, remotepath: str, localpath: str, callback: Optional[Callable]
) -> None:
    ...

Get a remote file.

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

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

Parameters
  • remotepath str — Remote path.
  • fl IO — Open file handle.
  • callback Optional[Callable] — 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: Optional[Callable]
) -> None:
    ...

Copy a local file to remote site.

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

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

Parameters
  • fl IO — Open file handle.
  • remotepath str — Remote path.
  • callback Optional[Callable] — 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):
        ...

Initialize self. See help(type(self)) for accurate signature.

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

RemoteIOSite

class RemoteIOSite(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.

Initialize self. See help(type(self)) for accurate signature.

Attributes
home_dir pathlib.PurePosixPath

The home directory.

sftp_client Union[paramiko.sftp_client.SFTPClient, salvus.flow.sites.remote_io_site.LocalSFTPClient]

Get the sftp client instance.

Will be initialized upon the first access.

ssh_client Union[paramiko.client.SSHClient, salvus.flow.sites.remote_io_site.LocalSSHClient]

Get the ssh client instance.

Will be initialized upon the first access.

Methods
check_if_folder_can_be_written_to()
def check_if_folder_can_be_written_to(
    self, path: Union[str, pathlib.Path, pathlib.PurePosixPath]
) -> bool:
    ...

Checks if the folder can be written to.

Parameters
  • path Union[str, pathlib.Path, pathlib.PurePosixPath] — Path on the remote machine.
Returns bool
remote_exists()
def remote_exists(
    self, path: Union[str, pathlib.Path, pathlib.PurePosixPath]
) -> bool:
    ...

Check if the remote path exists or not.

Parameters
  • path Union[str, pathlib.Path, pathlib.PurePosixPath] — Remote path to check.
Returns bool
remote_get()
def remote_get(
    self,
    remotepath: Union[str, pathlib.Path, pathlib.PurePosixPath],
    localpath: Union[_io.BytesIO, pathlib.Path],
    progressbar: bool = False,
) -> None:
    ...

Get a remote file.

Parameters
  • remotepath Union[str, pathlib.Path, pathlib.PurePosixPath] — Remote file to get.
  • localpath Union[_io.BytesIO, pathlib.Path] — Local path to save to Can be a file or a file like object.
  • progressbar bool — Show progressbar.
Returns None
remote_listdir()
def remote_listdir(
    self, path: Union[str, pathlib.Path, pathlib.PurePosixPath]
) -> List[str]:
    ...

List the contents of a remote directory.

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

Remotely create a directory.

Parameters
  • path Union[str, pathlib.Path, pathlib.PurePosixPath] — Directory to create.
  • mode int — Permissions for the new directory.
Returns None
remote_put()
def remote_put(
    self,
    localpath: Union[_io.BytesIO, pathlib.Path],
    remotepath: Union[str, pathlib.Path, pathlib.PurePosixPath],
    progressbar: bool = False,
) -> None:
    ...

Copy a local file to a remote path.

Parameters
  • localpath Union[_io.BytesIO, pathlib.Path] — Local file to copy. Can be a file like object.
  • remotepath Union[str, pathlib.Path, pathlib.PurePosixPath] — Where to copy to.
  • progressbar bool — Show a progressbar.
Returns None
remote_rmdir()
def remote_rmdir(
    self,
    path: Union[str, pathlib.Path, pathlib.PurePosixPath],
    verbosity: int = 1,
) -> None:
    ...

Remotely and recursively delete a remote folder and its contents.

Parameters
  • path Union[str, pathlib.Path, pathlib.PurePosixPath] — Remote path to delete.
  • verbosity int — Verbosity level.
Returns None
run_ssh_command()
def run_ssh_command(
    self,
    cmd: str,
    assert_ok: bool = True,
    environment: Optional[Dict[str, str]] = None,
) -> Tuple[int, List[str], List[str]]:
    ...

Directly runs the given command via SSH on the remote machine.

Parameters
  • cmd str — Command to run.
  • assert_ok bool — Assert that it exits with code zero, otherwise raise a remote execution error with more information.
  • environment Optional[Dict[str, str]] — A dict of shell environment variables to be merged into the default environment that the remote command executes with.
Returns Tuple[int, List[str], List[str]]
safe_remote_rmdir()
def safe_remote_rmdir(
    self,
    path: Union[str, pathlib.Path, pathlib.PurePosixPath],
    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 Union[str, pathlib.Path, pathlib.PurePosixPath] — Remote path to delete.
  • allow_failure bool — Whether to allow failure or not.
  • verbosity int — Verbosity level.
Returns None