miranda.remote package#

class miranda.remote.Connection(username: str | Path | None = None, host: str | Path | None = None, protocol: str = 'sftp', *args, **kwargs)[source]#

Bases: object

connect(**kwargs)[source]#
update(**kwargs)[source]#
miranda.remote.archive_database(source: Path | str | List, common_path: Path | str, destination: Path | str, file_suffixes: str = '.nc', server: str | None = None, username: str | None = None, project_name: str | None = None, overwrite: bool = False, compression: bool = False, recursive: bool = False, use_grouping: bool = True, use_subdirectories: bool = True, dry_run: bool = False) None[source]#
Given a source, destination, and dependent on file size limit, create tarfile archives and transfer

files to another server for backup purposes

miranda.remote.create_archive(source_files: list[str | os.PathLike], destination: str | os.PathLike, transport: SCPClient | SFTPClient | fabric.Connection | miranda.remote.Connection = None, delete: bool = True, compression: bool = False, recursive: bool = True) None[source]#
Parameters:
  • source_files (List[Union[str, os.PathLike]])

  • destination (Union[str, os.PathLike])

  • transport (Union[SCPClient, SFTPClient, fabric.Connection, Connection])

  • delete (bool)

  • compression (bool)

  • recursive (bool)

Returns:

None

miranda.remote.create_remote_directory(directory: str | os.PathLike, transport: SSHClient | fabric.Connection | miranda.remote.Connection) None[source]#

This calls a “mkdir -p” function to create a folder structure over SFTP/SSH and waits for confirmation before continuing

Parameters:
  • directory (Union[str, os.PathLike])

  • transport (Union[SSHClient, fabric.Connection, Connection])

Returns:

None

miranda.remote.delete_by_date(*, source: str | Path, year: int | None = None, month: int | None = None, day: int | None = None, pattern: str | None = None, server: str | Path | None = None, user: str | None = None, password: str | None = None, date_object: date | None = None) None[source]#
Parameters:
  • source (Union[str, Path])

  • year (Optional[int])

  • month (Optional[int])

  • day (Optional[int])

  • pattern (Optional[str])

  • server (Optional[Union[str, Path]])

  • user (Optional[str])

  • password (Optional[str])

  • date_object (Optional[date])

Returns:

None

miranda.remote.delete_by_variable(*, target: str | Path | List[str | Path] | generator | None = None, variables: List[str] | None = None, server: str | None, user: str | None = None, password: str | None = None, file_suffix: str | None = None, delete: bool = False) None[source]#
Given target location(s), a list of variables and a server address, perform a glob search

and delete file names starting with the variables identified

Parameters:
  • target (Union[str, Path, List[Union[str, Path]], GeneratorType])

  • variables (List[str])

  • server (Optional[Union[str, Path]])

  • user (Optional[str])

  • password (Optional[str])

  • file_suffix (Optional[str])

  • delete (bool)

Returns:

None

miranda.remote.delete_duplicates(*, source: str | Path, target: str | Path, server: str | Path | None, user: str | None = None, password: str | None = None, pattern: str | None = None, delete_target_duplicates: bool = False) None[source]#
Parameters:
  • source (Union[str, Path])

  • target (Union[str, Path])

  • server (Optional[Union[str, Path]])

  • user (str)

  • password (str)

  • pattern (str)

  • delete_target_duplicates (bool)

Returns:

None

miranda.remote.file_emptier(*, file_list: List[str | Path] | generator) None[source]#

Provided a list of file paths, will open and overwrite them in order to delete data while preserving the file name.

Parameters:

file_list (List[Union[str, Path]]) – List of files to be overwritten

Returns:

None

miranda.remote.transfer_file(source_file: str | os.PathLike, destination_file: str | os.PathLike, transport: SCPClient | SFTPClient | fabric.Connection | miranda.remote.Connection = None) bool[source]#
Parameters:
  • source_file (Union[str, os.PathLike])

  • destination_file (Union[str, os.PathLike])

  • transport (Union[SCPClient, SFTPClient, fabric.Connection, Connection])

Returns:

bool

Submodules#

miranda.remote.archiver module#

miranda.remote.archiver.archive_database(source: Path | str | List, common_path: Path | str, destination: Path | str, file_suffixes: str = '.nc', server: str | None = None, username: str | None = None, project_name: str | None = None, overwrite: bool = False, compression: bool = False, recursive: bool = False, use_grouping: bool = True, use_subdirectories: bool = True, dry_run: bool = False) None[source]#
Given a source, destination, and dependent on file size limit, create tarfile archives and transfer

files to another server for backup purposes

miranda.remote.connect module#

class miranda.remote.connect.Connection(username: str | Path | None = None, host: str | Path | None = None, protocol: str = 'sftp', *args, **kwargs)[source]#

Bases: object

connect(**kwargs)[source]#
update(**kwargs)[source]#

miranda.remote.ops module#

miranda.remote.ops.create_archive(source_files: list[str | os.PathLike], destination: str | os.PathLike, transport: SCPClient | SFTPClient | fabric.Connection | miranda.remote.Connection = None, delete: bool = True, compression: bool = False, recursive: bool = True) None[source]#
Parameters:
  • source_files (List[Union[str, os.PathLike]])

  • destination (Union[str, os.PathLike])

  • transport (Union[SCPClient, SFTPClient, fabric.Connection, Connection])

  • delete (bool)

  • compression (bool)

  • recursive (bool)

Returns:

None

miranda.remote.ops.create_remote_directory(directory: str | os.PathLike, transport: SSHClient | fabric.Connection | miranda.remote.Connection) None[source]#

This calls a “mkdir -p” function to create a folder structure over SFTP/SSH and waits for confirmation before continuing

Parameters:
  • directory (Union[str, os.PathLike])

  • transport (Union[SSHClient, fabric.Connection, Connection])

Returns:

None

miranda.remote.ops.transfer_file(source_file: str | os.PathLike, destination_file: str | os.PathLike, transport: SCPClient | SFTPClient | fabric.Connection | miranda.remote.Connection = None) bool[source]#
Parameters:
  • source_file (Union[str, os.PathLike])

  • destination_file (Union[str, os.PathLike])

  • transport (Union[SCPClient, SFTPClient, fabric.Connection, Connection])

Returns:

bool

miranda.remote.remove module#

miranda.remote.remove.delete_by_date(*, source: str | Path, year: int | None = None, month: int | None = None, day: int | None = None, pattern: str | None = None, server: str | Path | None = None, user: str | None = None, password: str | None = None, date_object: date | None = None) None[source]#
Parameters:
  • source (Union[str, Path])

  • year (Optional[int])

  • month (Optional[int])

  • day (Optional[int])

  • pattern (Optional[str])

  • server (Optional[Union[str, Path]])

  • user (Optional[str])

  • password (Optional[str])

  • date_object (Optional[date])

Returns:

None

miranda.remote.remove.delete_by_variable(*, target: str | Path | List[str | Path] | generator | None = None, variables: List[str] | None = None, server: str | None, user: str | None = None, password: str | None = None, file_suffix: str | None = None, delete: bool = False) None[source]#
Given target location(s), a list of variables and a server address, perform a glob search

and delete file names starting with the variables identified

Parameters:
  • target (Union[str, Path, List[Union[str, Path]], GeneratorType])

  • variables (List[str])

  • server (Optional[Union[str, Path]])

  • user (Optional[str])

  • password (Optional[str])

  • file_suffix (Optional[str])

  • delete (bool)

Returns:

None

miranda.remote.remove.delete_duplicates(*, source: str | Path, target: str | Path, server: str | Path | None, user: str | None = None, password: str | None = None, pattern: str | None = None, delete_target_duplicates: bool = False) None[source]#
Parameters:
  • source (Union[str, Path])

  • target (Union[str, Path])

  • server (Optional[Union[str, Path]])

  • user (str)

  • password (str)

  • pattern (str)

  • delete_target_duplicates (bool)

Returns:

None

miranda.remote.remove.file_emptier(*, file_list: List[str | Path] | generator) None[source]#

Provided a list of file paths, will open and overwrite them in order to delete data while preserving the file name.

Parameters:

file_list (List[Union[str, Path]]) – List of files to be overwritten

Returns:

None