IOHandler — PyRemoteData 0.0.34 documentation

Skip to content

# IOHandler

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

  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: None | str, blocking: bool = True, **kwargs) → any

    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]

    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]

    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.

  multi_download(remote_paths: List[str], local_destination: str | List[str], blocking: bool = True, n: int = 5, **kwargs) → List[str]

    Downloads a list of files from the remote directory to the given local destination.

    Parameters:

      - remote_paths (List[str]) – A list of remote paths to download.

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

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

      - n (int) – The number of connections to use for downloading each file.

      - **kwargs – Extra keyword arguments are ignored.

    Returns:

      A list of the local paths of the downloaded files.

  start() → None

    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

    Close the connection to the remote directory.