plate_model_manager.utils package

Submodules

plate_model_manager.utils.collect_update_model module

plate_model_manager.utils.collect_update_model.collect_model(model_name, target_dir='.', source='https://repo.gplates.org/webdav/pmm/config/model_sources.json')[source]
plate_model_manager.utils.collect_update_model.create_hex_hash_sidecar_files(model_path)[source]

Create SHA256 hash sidecar files for all .zip files in the given directory.

plate_model_manager.utils.collect_update_model.upload_model(model_path, remote_target, identity_file)[source]

Upload a plate model folder to a remote server via SCP.

This function uploads all files in the specified model directory to a remote server. Before uploading, it creates SHA256 hash sidecar files for all .zip files in the directory. Existing files on the remote server are archived with a timestamp before the new files are uploaded.

Parameters:
  • model_path – Path to the local model directory containing files to upload.

  • remote_target – Remote destination in the format ‘user@host:path’. The model name will be appended to the path automatically.

  • identity_file – Path to the SSH private key file for authentication.

Raises:
  • RuntimeError – If no files are found in the model directory or if the SSH connection to the remote host fails.

  • AssertionError – If the remote_target format is invalid (must contain ‘:’).

Example

upload_model(

“models/muller2022”, “ubuntu@example.com:/data/models”, “~/.ssh/id_rsa”

)

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.layer_validation module

plate_model_manager.utils.layer_validation.list_remote_zip_layers(model_name, base_url, timeout=30)[source]
plate_model_manager.utils.layer_validation.load_models_config(source, timeout=30)[source]
plate_model_manager.utils.layer_validation.normalize_svr_base_url(all_models)[source]
plate_model_manager.utils.layer_validation.validate_layers(model_config, base_url=None, timeout=30)[source]

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.