pybiocfilecache package¶
Subpackages¶
Submodules¶
pybiocfilecache.BiocFileCache module¶
Python Implementation of BiocFileCache.
- class pybiocfilecache.BiocFileCache.BiocFileCache(cacheDirOrPath: str | Path = '/tmp/tmp1m9194ak')[source]¶
Bases:
object
Class to manage and cache files.
- add(rname: str, fpath: str | Path, rtype: Literal['local', 'web', 'relative'] = 'local', action: Literal['copy', 'move', 'asis'] = 'copy', ext: bool = False) Resource [source]¶
Add a resource from the provided fpath to cache as rname.
- Parameters:
rname – Name of the resource to add to cache.
fpath – Location of the resource.
rtype – One of
local
,web
, orrelative
. Defaults tolocal
.action – Either
copy
,move
orasis
. Defaults tocopy
.ext – Whether to use filepath extension when storing in cache. Defaults to False.
- Raises:
NoFpathError – When the fpath does not exist.
RnameExistsError – When the rname already exists in the cache. sqlalchemy exceptions: When something is up with the cache.
- Returns:
Database record of the new resource in cache.
- get(rname: str) Resource | None [source]¶
Get resource by name from cache.
- Parameters:
rname – Name of the file to search.
- Returns:
Matched Resource from cache if exists.
- query(query: str, field: str = 'rname') List[Resource] [source]¶
Search cache for a resource.
- Parameters:
query – Query string or keywords to search.
field – Field to search. Defaults to “rname”.
- Returns:
List of matching resources from cache.
- remove(rname: str) None [source]¶
Remove a resource from cache by name.
- Parameters:
rname – Name of the resource to remove.
- update(rname: str, fpath: str | Path, action: Literal['copy', 'move', 'asis'] = 'copy') Resource [source]¶
Update a resource in cache.
- Parameters:
rname – Name of the resource in cache.
fpath – New resource to replace existing file in cache.
action –
Either
copy
,move
orasis
.Defaults to
copy
.
- Returns:
Updated resource record in cache.
pybiocfilecache.const module¶
pybiocfilecache.utils module¶
- pybiocfilecache.utils.copy_or_move(source: str | Path, target: str | Path, rname: str, action: Literal['copy', 'move', 'asis'] = 'copy') None [source]¶
Copy or move a resource from
source
totarget
.- Parameters:
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.
- pybiocfilecache.utils.create_tmp_dir() str [source]¶
Create a temporary directory.
- Returns:
Temporary path to the directory.