IOHandler

class pyremotedata.implicit_mount.IOHandler(local_dir: str | None = None, user_confirmation: bool = False, clean: bool = False, **kwargs)[source]

Bases: ImplicitMount

This is a high-level wrapper for the ImplicitMount class, which provides human-friendly methods for downloading files from a remote directory without the need to have technical knowledge on how to use LFTP.

OBS: The attributes of this method should not be used unless for development or advanced use cases, all responsibility in this case is on the user.

Parameters:
  • local_dir (str) – The local directory to use for downloading files. If None, a temporary directory will be used (suggested, unless truly necessary).

  • user_confirmation (bool) – If True, the user will be asked for confirmation before deleting files. (strongly suggested for debugging and testing)

  • clean (bool) – If True, the local directory will be cleaned after the context manager is exited. (suggested, if not it may lead to rapid exhaustion of disk space)

  • **kwargs – Keyword arguments to pass to the ImplicitMount constructor.

clone(local_destination: str | None, blocking: bool = True, **kwargs) List[str] | None[source]

Clones the current remote directory to the given local destination.

Parameters:
  • local_destination (str) – The local destination to clone the current remote directory to.

  • blocking (bool) – If True, the function will block until the download is complete.

  • **kwargs – Keyword arguments to pass to the mirror function.

Returns:

The output of ImplicitMount.mirror, which depend on the arguments passed to the function. Most likely a list of the newly downloaded files.

download(remote_path: str | List[str], local_destination: str | List[str] | None = None, blocking: bool = True, **kwargs) str | List[str][source]

Downloads one or more files or a directory from the remote directory to the given local destination.

Parameters:
  • remote_path (Union[str, List[str]]) – The remote path(s) to download.

  • local_destination (Union[str, List[str]]) – The local destination to download the file(s) to. If None, the file(s) will be downloaded to the current local directory.

  • blocking (bool) – If True, the function will block until the download is complete.

  • **kwargs – Extra keyword arguments are passed to the IOHandler.multi_download, IOHandler.pget or IOHandler.mirror functions depending on the type of the remote path(s).

Returns:

(List of) The local path of the downloaded file(s) or directory.

get_file_index(skip: int = 0, nmax: int | None = None, override: bool = False, store: bool = True, pattern: str | None = None) List[str][source]

Get a list of files in the current remote directory.

Parameters:
  • skip (int) – The number of files to skip.

  • nmax (int) – The maximum number of files to include.

  • override (bool) – If True, the file index will be overridden if it already exists.

  • store (bool) – If True, the file index will be stored on the remote directory.

  • pattern (str) – A regular expression pattern to filter the file names by, e.g. “.txt$” to only include files with the “.txt” extension.

Returns:

A list of files in the current remote directory.

lcd(local_path: str)[source]

Changes the current local directory using the LFTP command lcd.

Parameters:

local_path (str) – The local directory to change to.

lpwd()[source]

Get the current local directory using the LFTP command lpwd.

Returns:

The current local directory.

Return type:

str

start() None[source]

Initialize the connection to the remote directory.

Very useful for interactive use, but shouldn’t be used in scripts, using a context manager is safer and does the same.

stop() None[source]

Close the connection to the remote directory.