[docs]defcreate_tmp_dir()->str:"""Create a temporary directory. Returns: Temporary path to the directory. """returntempfile.mkdtemp()
[docs]defgenerate_id()->str:"""Generate uuid. Returns: Unique string for use as id. """returnuuid.uuid4().hex
[docs]defcopy_or_move(source:Union[str,Path],target:Union[str,Path],rname:str,action:Literal["copy","move","asis"]="copy",)->None:"""Copy or move a resource from ``source`` to ``target``. Args: source: Source location of the resource to copy of move. target: Destination to copy of move to. rname: Name of resource to add to cache. action: Copy of move file from source. Defaults to copy. Raises: ValueError: If action is not `copy`, `move` or `asis`. Exception: Error storing resource in the cache directory. """ifactionnotin["copy","move","asis"]:raiseValueError(f"Action must be either 'move', 'copy' or 'asis', provided {action}.")try:ifaction=="copy":copy2(source,target)elifaction=="move":move(str(source),target)elifaction=="asis":passexceptExceptionase:raiseException(f"Error storing resource: '{rname}' from: '{source}' in '{target}'.",)frome