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, or relative. Defaults to local.

  • action – Either copy, move or asis. Defaults to copy.

  • 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.

purge()[source]

Remove all files from cache.

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 or asis.

    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 to target.

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.

pybiocfilecache.utils.generate_id() str[source]

Generate uuid.

Returns:

Unique string for use as id.

pybiocfilecache.utils.setup_logging(loglevel)[source]

Setup basic logging.

Parameters:

loglevel (int) – minimum loglevel for emitting messages

Module contents