Api

fsdb.Fsdb

class fsdb.Fsdb(fsdbRoot, mode=None, deep=None, hash_alg=None)

File system database expose a simple api (add,get,remove) to menage the saving of files on disk. files are placed under specified fsdb root folder and are managed using a directory tree generated from the file digest

CONFIG_FILE = '.fsdb.conf'
_calc_digest(path)

calculate digest of the file at the given path

_makedirs(path)
Make folders recursively for the given path and
check read and write permission on the path
Args:
path – path to the leaf folder
add(filePath)
Add an existing file to fsdb.
File under @filePath will be copied under fsdb directory tree
Args:
filePath – path of the file to be add
Returns:
String rapresenting the digest of the file
check(digest)

Check the integrity of the file with the given digest

Args:
digest – digest of the file to check
Returns:
True if the file is not corrupted
static config_exists(fsdbRoot)
corrupted()

Iterate over digests of all corrupted stored files

exists(digest)

Check file existence in fsdb

Returns:
True if file exists under this instance of fsdb, false otherwise
static file_digest(filepath, algorithm='sha1', block_size=1048576)

Calculate digest of the file located at @filepath

Args:
digest – digest of the file to remove
static generate_tree_path(fileDigest, deep)
Generate a relative path from the given fileDigest
relative path has a numbers of directories levels according to @deep
Args:
fileDigest – digest for which the relative path will be generate deep – number of levels to use in relative path generation
Returns:
relative path for the given digest
get_file_path(digest)

Retrieve the absolute path to the file with the given digest

Args:
digest – digest of the file
Returns:
String rapresenting the absolute path of the file
remove(digest)
Remove an existing file from fsdb.
File with the given digest will be removed from fsdb and the directory tree will be cleaned (remove empty folders)
Args:
digest – digest of the file to remove

Table Of Contents

Previous topic

Fsdb documentation

This Page