files

File utils module.

This module provides utility functions for other modules.

Hint

Use pip to install the necessary dependencies for this module: pip install mltb2[files]

mltb2.files.fetch_remote_file(dirname, filename, url: str, sha256_checksum: str) str[source]

Fetch a file from a remote URL.

Parameters:
  • dirname – the directory where the file will be saved

  • filename – the filename under which the file will be saved

  • url (str) – the url of the file

  • sha256_checksum (str) – the sha256 checksum of the file

Returns:

Full path of the created file.

Raises:

IOError – if the sha256 checksum is wrong

Return type:

str

mltb2.files.get_and_create_mltb2_data_dir(mltb2_base_data_dir: str | None = None) str[source]

Return and create a data dir for mltb2.

The exact directory is given by the mltb2_base_data_dir as the base folder and then the folder mltb2 is appended.

Parameters:

mltb2_base_data_dir (str | None) – The base data directory. If None the default user data directory is used. The default user data directory is determined by platformdirs.user_data_dir().

Returns:

The directory path.

Return type:

str