plate_model_manager.utils package
Submodules
plate_model_manager.utils.collect_update_model module
- collect_model(model_name, target_dir='.', source='https://repo.gplates.org/webdav/pmm/config/model_sources.json')[source]
- create_hex_hash_sidecar_files(model_path)[source]
Create SHA256 hash sidecar files for all .zip files in the given directory.
- 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 is 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
remote_targetis invalid and does not contain:.
Example:
upload_model( "models/muller2022", "ubuntu@example.com:/data/models", "~/.ssh/id_rsa", )
plate_model_manager.utils.download module
- class 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:
objectClass for managing single file download
- check_if_expire_date_need_update()[source]
Return whether only the metadata expiry timestamp should be refreshed.
This helper is typically called after
check_if_file_need_update()has fetched remote state. It returnsTruewhen remote content is unchanged and therefore the local file can be kept while extending the metadataexpiryvalue.Match conditions (either is sufficient):
SHA-256 path:
self.new_sha256is available and equalsself.meta_sha256.ETag fallback path:
self.new_etagis available and equalsself.meta_etag.
- Returns:
Trueif content identity is unchanged and expiry metadata should be updated, otherwiseFalse.- Return type:
- check_if_file_need_update()[source]
Decide whether the target file should be downloaded again.
- Returns:
Truewhen the file should be downloaded/re-downloaded,Falsewhen the existing local file can be reused.- Return type:
- Decision flow:
If the metadata file is missing, return
True.If the stored
urldiffers fromself.file_url(or is missing), returnTrue.If the metadata
expiryis still valid, returnFalse.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 the target file and refresh its metadata cache.
The method selects an HTTP backend from
self.http_clientand then chooses download strategy based on size:If
self.large_file_hintisTrue, it first retrieves response headers and storesself.file_size.If
self.file_sizeis known and greater than 20 MB, it usesfetch_large_file.Otherwise, it uses
fetch_file.
After a successful download call,
self.new_etagis updated from the client response andupdate_metadata()is called to write metadata fields (URL, expiry, ETag, SHA-256) toself.meta_filepath.- Raises:
Exception – Propagates exceptions raised by network/header retrieval, download client calls, or metadata writing.
- update_metadata()[source]
Write or refresh the JSON metadata file for the current download.
The metadata file at
self.meta_filepathis created (including parent directories) and overwritten with these fields:url:self.file_urlexpiry: current time plusself.expire_hoursformatted withself.expiry_time_formatetag:self.new_etagsha256:self.new_sha256
If
self.new_sha256is not already populated, SHA-256 is retrieved from the remote resource before writing metadata.- Raises:
Exception – Propagates exceptions raised while fetching SHA-256, creating directories, or writing the metadata file.
plate_model_manager.utils.enums module
plate_model_manager.utils.layer_validation module
plate_model_manager.utils.misc module
plate_model_manager.utils.network module
plate_model_manager.utils.unzip module
Module contents
Utility helpers for plate_model_manager.