miranda.remote package#

Remote Operations module.

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

Bases: object

Connection contextualise class.

connect(**kwargs)[source]#

Connect to a remote server with credential prompts.

update(**kwargs)[source]#

Update connection keyword arguments.

Warning

Credentials are not encrypted.

miranda.remote.archive_database(source: Path | str | list, common_path: Path | str, destination: Path | str, file_suffixes: str = '.nc', server: str = None, username: str = None, project_name: str = 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 = None, delete: bool = True, compression: bool = False, recursive: bool = True) None[source]#

Create an archive from source files and transfer to another location (remote or local).

Parameters:
  • source_files (list of str or os.PathLike)

  • destination (str or os.PathLike)

  • transport (SCPClient or SFTPClient or fabric.Connection or miranda.remote.Connection, optional)

  • 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]#

Call “mkdir -p” function to create a folder structure over SFTP/SSH and wait for confirmation before continuing.

Parameters:
  • directory (str or os.PathLike)

  • transport (SSHClient or fabric.Connection or miranda.remote.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]#

Remove a selection of files based on a given date of last modification.

Parameters:
  • source (str or Path)

  • year (int, optional)

  • month (int, optional)

  • day (int, optional)

  • pattern (str, optional)

  • server (str or Path, optional)

  • user (str, optional)

  • password (str, optional)

  • date_object (date, optional)

Returns:

None

miranda.remote.delete_by_variable(*, target: str | Path | list[str | Path] | generator = None, variables: list[str], server: str | Path | None = None, user: str | None = None, password: str | None = None, file_suffix: str | None = None, delete: bool = False) None[source]#

Delete according to variable name.

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 (str, Path, list of str or Path, or GeneratorType])

  • variables (list of str)

  • server (str or Path, optional)

  • user (str, optional)

  • password (str, optional)

  • file_suffix (str, optional)

  • delete (bool)

Returns:

None

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

  • target (str or Path)

  • server (str or Path, optional)

  • user (str)

  • password (str)

  • pattern (str)

  • delete_target_duplicates (bool)

Returns:

None

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

Open and overwrite a list of file paths in order to delete data while preserving the file name.

Parameters:

file_list (list of str or Path, or GeneratorType) – 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 = None) bool[source]#

Transfer file from one location (remote or local) to another.

Parameters:
  • source_file (str or os.PathLike)

  • destination_file (str or os.PathLike)

  • transport (SCPClient or SFTPClient or fabric.Connection or miranda.remote.Connection, optional)

Returns:

bool

Submodules#

miranda.remote.archiver module#

Archive Module.

miranda.remote.archiver.archive_database(source: Path | str | list, common_path: Path | str, destination: Path | str, file_suffixes: str = '.nc', server: str = None, username: str = None, project_name: str = 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#

Remote Connection Operations module.

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

Bases: object

Connection contextualise class.

connect(**kwargs)[source]#

Connect to a remote server with credential prompts.

update(**kwargs)[source]#

Update connection keyword arguments.

Warning

Credentials are not encrypted.

miranda.remote.ops module#

Remote Operations 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 = None, delete: bool = True, compression: bool = False, recursive: bool = True) None[source]#

Create an archive from source files and transfer to another location (remote or local).

Parameters:
  • source_files (list of str or os.PathLike)

  • destination (str or os.PathLike)

  • transport (SCPClient or SFTPClient or fabric.Connection or miranda.remote.Connection, optional)

  • 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]#

Call “mkdir -p” function to create a folder structure over SFTP/SSH and wait for confirmation before continuing.

Parameters:
  • directory (str or os.PathLike)

  • transport (SSHClient or fabric.Connection or miranda.remote.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 = None) bool[source]#

Transfer file from one location (remote or local) to another.

Parameters:
  • source_file (str or os.PathLike)

  • destination_file (str or os.PathLike)

  • transport (SCPClient or SFTPClient or fabric.Connection or miranda.remote.Connection, optional)

Returns:

bool

miranda.remote.remove module#

Remote File Removal Operations 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]#

Remove a selection of files based on a given date of last modification.

Parameters:
  • source (str or Path)

  • year (int, optional)

  • month (int, optional)

  • day (int, optional)

  • pattern (str, optional)

  • server (str or Path, optional)

  • user (str, optional)

  • password (str, optional)

  • date_object (date, optional)

Returns:

None

miranda.remote.remove.delete_by_variable(*, target: str | Path | list[str | Path] | generator = None, variables: list[str], server: str | Path | None = None, user: str | None = None, password: str | None = None, file_suffix: str | None = None, delete: bool = False) None[source]#

Delete according to variable name.

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 (str, Path, list of str or Path, or GeneratorType])

  • variables (list of str)

  • server (str or Path, optional)

  • user (str, optional)

  • password (str, optional)

  • file_suffix (str, optional)

  • delete (bool)

Returns:

None

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

  • target (str or Path)

  • server (str or Path, optional)

  • 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]#

Open and overwrite a list of file paths in order to delete data while preserving the file name.

Parameters:

file_list (list of str or Path, or GeneratorType) – List of files to be overwritten

Returns:

None