Api

fsdb.Fsdb

class fsdb.Fsdb(fsdbRoot, depth=None, hash_alg=None, fmode=None, dmode=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

BLOCK_SIZE = 1048576
CONFIG_FILE = u'.fsdb.conf'
_calc_digest(origin)

calculate digest for the given file or readable/seekable object

Args:
origin – could be the path of a file or a readable/seekable object ( fileobject, stream, stringIO...)
Returns:
String rapresenting the digest for the given origin
_copy_content(origin, dstPath)

copy the content of origin into dstPath

Due to concurrency problem, the content will be first copied to a temporary file alongside dstPath and then atomically moved to dstPath

_create_empty_file(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(origin)

Add new element to fsdb.

Args:
origin – could be the path of a file or a readable/seekable object ( fileobject, stream, stringIO...)
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 generate_tree_path(fileDigest, depth)
Generate a relative path from the given fileDigest
relative path has a numbers of directories levels according to @depth
Args:
fileDigest – digest for which the relative path will be generate depth – 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
size()

Return the total size in bytes of all the files handled by this instance of fsdb.

Fsdb does not use auxiliary data structure, so this function could be expensive. Look at _iter_over_paths() functions for more details.