BalancedDiscStorage class

class BalancedDiscStorage.balanced_disc_storage.BalancedDiscStorage(path, dir_limit=32000)

Bases: object

Store files, make sure, that there are never more files in one directory than _dir_limit.

path = None

Path on which the storage operates.

dir_limit = None

Maximal number of files in directory.

read_bs = None

File read blocksize.

hash_builder = None

Hashing function used for FN.

file_path_from_hash(file_hash, path=None, hash_list=None)

For given file_hash, return path on filesystem.

Parameters:
  • file_hash (str) – Hash of the file, for which you wish to know the path.
  • path (str, default None) – Recursion argument, don’t set this.
  • hash_list (list, default None) – Recursion argument, don’t set this.
Returns:

Path for given file_hash contained in PathAndHash object.

Return type:

str

Raises:

IOError – If the file with corresponding file_hash is not in storage.

add_file(file_obj)

Add new file into the storage.

Parameters:

file_obj (file) – Opened file-like object.

Returns:

Path where the file-like object is stored contained with hash in PathAndHash object.

Return type:

obj

Raises:
  • AssertionError – If the file_obj is not file-like object.
  • IOError – If the file couldn’t be added to storage.
delete_by_file(file_obj)

Remove file from the storage. File is identified by opened file_obj, from which the hashes / path are computed.

Parameters:file_obj (file) – Opened file-like object, which is used to compute hashes.
Raises:IOError – If the file_obj is not in storage.
delete_by_hash(file_hash)

Remove file/archive by it’s file_hash.

Parameters:file_hash (str) – Hash, which is used to find the file in storage.
Raises:IOError – If the file for given file_hash was not found in storage.
delete_by_path(path)

Delete file/directory identified by path argument.

Warning

path have to be in path.

Parameters:path (str) – Path of the file / directory you want to remove.
Raises:IOError – If the file / directory doesn’t exists, or is not in path.