Scripts.DatabankLib.databankio module
- module databankio:
Inut/Output auxilary module
- description:
Input/Output auxilary module with some small usefull functions. It includes: - Network communication. - Downloading files. - Checking links. - Resolving DOIs. - Calculating file hashes.
- Scripts.DatabankLib.databankio.download_resource_from_uri(uri: str, dest: str, override_if_exists: bool = False, dry_run_mode: bool = False) int [source]
Download file resource [from uri] to given file destination using urllib
- Parameters:
uri – (str) file URL
dest – (str) file destination path
override_if_exists – (bool, optional) Override dest. file if exists. Defaults to False.
- Raises:
HTTPException – An error occured during download
- Returns:
code (int) 0 - OK, 1 - skipped, 2 - redownloaded
- Scripts.DatabankLib.databankio.calc_file_sha1_hash(fi: str, step: int = 67108864, one_block: bool = True) str [source]
Calculates SHA1 hash of given file using hashlib.
- Parameters:
fi – (str) path to file
step – (int, optional) file read bytes step. Defaults to 64MB.
one_block – (bool, optional) read just a single block. Defaults to True.
- Returns str:
sha1 filehash of 40 char length
- Scripts.DatabankLib.databankio.create_databank_directories(sim: Mapping, sim_hashes: Mapping, out: str, dry_run_mode: bool = False) str [source]
Creates nested output directory structure to save results.
- Parameters:
sim – Processed simulation entries.
sim_hashes – File hashes needed for directory structure.
out – Output base path (str).
dry_run_mode – If True, do not create directories, just return the path.
- Returns:
Output directory (str).
- Raises:
NotImplementedError – If the simulation software is unsupported.
OSError – If an error occurs while creating the output directory.
FileExistsError – If the output directory already exists and is not empty.