OCDocker.Toolbox.FilesFolders module¶
Sets of classes and functions that are used to manipulate and create files and folders.
Usage:
import OCDocker.Toolbox.FilesFolders as ocff
- OCDocker.Toolbox.FilesFolders.empty_docking_digest(digestPath, overwrite=False, digestFormat='')[source]¶
Create an empty digest file.
- Parameters:
digestPath (str) – Where to store the digest file.
overwrite (bool, optional) – If True, overwrites the output files if they already exist. (default is False)
digestFormat (str, optional) – The format of the digest file. The options are: [ ‘’ (no output, default), json, hdf5 (not implemented) ]
- Returns:
The empty digest object or the error code.
- Return type:
Dict[str, List[float]] | int
- OCDocker.Toolbox.FilesFolders.ensure_parent_dir(path)[source]¶
Ensure parent directory exists, creating if necessary.
- Parameters:
path (str) – Path to a file or directory. The parent directory will be created.
- Returns:
This function does not return a value. It silently handles errors.
- Return type:
None
- OCDocker.Toolbox.FilesFolders.from_hdf5(filePath)[source]¶
Read a data from a hdf5 file.
- Parameters:
filePath (str) – Path to the hdf5 file.
- Returns:
The data read from the file or None if there was an error.
- Return type:
None | Any
- OCDocker.Toolbox.FilesFolders.from_pickle(filePath, trusted=False)[source]¶
Unpickle a pickle file into an object.
Security¶
Only load pickle files from trusted sources. Pickle deserialization can execute arbitrary code if the file is malicious or untrusted. This function enforces explicit trust: pass
trusted=Trueor setOCDOCKER_ALLOW_UNSAFE_DESERIALIZATION=1.- param filePath:
Path to the pickle file.
- type filePath:
str
- param trusted:
Explicit opt-in that the file comes from a trusted source. Default is False.
- type trusted:
bool, optional
- returns:
The object if success or None otherwise.
- rtype:
None | Any
- Parameters:
filePath (str) –
trusted (bool) –
- Return type:
None | Any
- OCDocker.Toolbox.FilesFolders.normalize_path(path)[source]¶
Normalize a path to an absolute path with normalized separators and components.
This function normalizes paths by: - Converting to absolute path - Normalizing path separators - Resolving . and .. components
- Parameters:
path (str) – The path to normalize.
- Returns:
The normalized absolute path.
- Return type:
str
- OCDocker.Toolbox.FilesFolders.safe_create_dir(dirname)[source]¶
Create a dir if not exists.
- Parameters:
dirname (str, Path) – The dir to be created. It can be a string or a Path object.
- Returns:
The exit code of the command (based on the Error.py code table).
- Return type:
int
- OCDocker.Toolbox.FilesFolders.safe_remove_dir(dirname)[source]¶
Remove a dir if exists.
- Parameters:
dirname (str) – The dir to be removed.
- Returns:
The exit code of the command (based on the Error.py code table).
- Return type:
int
- OCDocker.Toolbox.FilesFolders.safe_remove_file(filePath)[source]¶
Remove a file if exists.
- Parameters:
filePath (str) – The file to be removed.
- Returns:
The exit code of the command (based on the Error.py code table).
- Return type:
int
- OCDocker.Toolbox.FilesFolders.to_hdf5(filePath, data)[source]¶
Save a data in a hdf5 file. If the data is a dict, use its keys as hdf5 key files. If is a list or tuple, use its indexes as keys. Otherwise, use the key ‘data’.
- Parameters:
filePath (str) – Path to the hdf5 file.
data (Any) – Data to be saved.
- Returns:
The exit code of the command (based on the Error.py code table).
- Return type:
int
- OCDocker.Toolbox.FilesFolders.to_pickle(filePath, data)[source]¶
Pickle an object in a given path.
- Parameters:
filePath (str) – Path to the pickle file.
data (Any) – Data to be pickled.
- Returns:
The exit code of the command (based on the Error.py code table).
- Return type:
int
- OCDocker.Toolbox.FilesFolders.untar(fname, out_path='.', delete=False)[source]¶
Untar a file.
- Parameters:
fname (str) – The file to be untarred.
out_path (str, optional) – The path where the file will be untarred. Default is the current directory.
delete (bool, optional) – If True, the tar file will be deleted after the untar process. Default is False.
- Returns:
The exit code of the command (based on the Error.py code table).
- Return type:
int