plate_model_manager.utils package

Submodules

plate_model_manager.utils.download module

class plate_model_manager.utils.download.FileDownloader(file_url: str, meta_filepath: str, dst_dir: str, filename: str | None = None, auto_unzip: bool = True, expire_hours=12, expiry_time_format='%Y/%m/%d, %H:%M:%S', large_file_hint=False, timeout=(None, None), http_client: HttpClient = HttpClient.REQUESTS)[source]

Bases: object

class for managing single file download

check_if_expire_date_need_update()[source]
check_if_file_need_update()[source]

Decide whether the target file should be downloaded again.

Returns:

True when the file should be downloaded/re-downloaded, False when the existing local file can be reused.

Return type:

bool

Decision flow:
  1. If the metadata file is missing, return True.

  2. If the stored url differs from self.file_url (or is missing), return True.

  3. If the metadata expiry is still valid, return False.

  4. If expired (or expiry is invalid/missing), compare remote content state: - Prefer SHA-256 comparison when available. - Fall back to ETag comparison if SHA-256 cannot be obtained. - If neither reliable value is available, return True.

download_file_and_update_metadata()[source]

download a file from “file_url”, save the file in “dst_dir” and update the metadata file

Parameters:
  • file_url – the url to the file

  • metadata_file – the path to the metadata file

  • dst_dir – the destination to save the file

update_metadata()[source]

update metadata file

class plate_model_manager.utils.download.HttpClient(*values)[source]

Bases: Enum

AIOHTTP = 2
REQUESTS = 1

plate_model_manager.utils.enums module

class plate_model_manager.utils.enums.GenerationMethod(*values)[source]

Bases: Enum

Isochrons = 'UsingIsochrons'
Topologies = 'UsingTopologies'
class plate_model_manager.utils.enums.ReferenceFrame(*values)[source]

Bases: Enum

MantleReferenceFrame = 'MantleFrame'
PmagReferenceFrame = 'PMAG'

plate_model_manager.utils.misc module

plate_model_manager.utils.misc.add_logging_file(filename: str = 'pmm.log', level=20)[source]
plate_model_manager.utils.misc.disable_stdout_logging()[source]
plate_model_manager.utils.misc.get_distribution_version()[source]

get the version string from the package metadata

plate_model_manager.utils.misc.is_debug_mode()[source]

Check if the debug mode is enabled by checking the environment variable “PMM_DEBUG”.

export PMM_DEBUG=true to enable the debug mode.

plate_model_manager.utils.misc.my_warningformat(message, category, filename, lineno, line=None)[source]
plate_model_manager.utils.misc.print_error(msg)[source]
plate_model_manager.utils.misc.print_warning(msg)[source]
plate_model_manager.utils.misc.set_logging_level(level=30)[source]
plate_model_manager.utils.misc.setup_logging()[source]
plate_model_manager.utils.misc.turn_on_debug_logging()[source]

plate_model_manager.utils.network module

plate_model_manager.utils.network.get_content_length(headers)[source]
plate_model_manager.utils.network.get_etag(headers)[source]

return the etag in the headers. The return could be none if the server does not support etag.

Parameters:

headers – call get_headers(url) to get headers

plate_model_manager.utils.network.get_headers(url, timeout=(None, None))[source]
plate_model_manager.utils.network.get_sha256(url, timeout=(None, None))[source]

Return the sha256 hash from the sidecar file name in a WebDAV/XML or HTML directory listing.

Parameters:

timeout – a (connect_timeout, read_timeout) tuple for requests.get(). None keeps requests’ default behavior for that timeout component.

plate_model_manager.utils.unzip module

plate_model_manager.utils.unzip.save_compressed_data(url, data, dst_path)[source]

extract files from compressed data

Parameters:
  • url – URL

  • data – bytes-like object

  • dst_path – location to save the files

Module contents

Utility helpers for plate_model_manager.