API Reference¶
This document is for developers of furtive, it contains the API functions
Furtive Class¶
Furtive - File Integrity Verification System
-
class
furtive.
Furtive
(base_dir, manifest_path, exclude=None)[source]¶ Bases:
object
Furtive is an application which stores file state and allows users to verify the state in the future. Example use cases include file archives and file transport.
If the manifest file exists, it will be automatcally loaded. Calling create() will overwrite the existing manifest in memory as well as the file.
Parameters: - base_dir (str) – Base directory to use for the manifest. Can be a full or relative path.
- manifest_path (str) – Path to the manifest file. Can be a full or relative path.
- exclude (list) – list containing patterns to use to exclude files from the manifest.
Sub-Modules¶
Hasher¶
Manages the hashing of files
-
class
furtive.hasher.
HashDirectory
(directory, exclude=None)[source]¶ Bases:
object
Object to manage hashing files in a directory.
This object is responsible for walking the directory tree and adding each file to a list. Once the directory walk has compelted, each file path is passed to hash_task(). After each file has been hashed, this object will then create a Python dictionary of files with their associated hash.
Parameters: - directory (str) – Path to directory containing files
- exclude (list) – list containing patterns to use to exclude files from the manifest.
Returns: Dictionary of file:hash
Return type: dict
-
excluded
(file_path)[source]¶ Should the file be excluded from the manifest?
Determines if a file should be excluded based on UNIX style pattern matching. Think *, ?, and [] sequences.
For matchers, see https://docs.python.org/2/library/fnmatch.html
Parameters: file_path (str) – path of the file to match against. Returns: True or False indicating if the file should be excluded from the list of files containted within the manifest. Return type: bool
-
furtive.hasher.
hash_task
(file_path, hash_algorithm='md5')[source]¶ Responsible for hashing a file.
This function reads in the file
file_path
in small chuncks the size of the hash algorithm’s block size in order to avoid running out of memory. This means that this function should be able to read any file irregardless of the size.Parameters: - file_path (str) – path of file to hash
- hash_algorithm (str) – the hashing algorithm to use. All options available in hashlib.algorithms should work. See: https://docs.python.org/2/library/hashlib.html
Returns: hash of file
Return type: dict
Manifest¶
Manifest of files and their hashes
-
class
furtive.manifest.
Manifest
(directory, manifest_file, exclude=None)[source]¶ Bases:
object
Manifest of files and the associated hashes.
Parameters: - directory – directory which will serve as the root for the manifest. All files under the directory will be hashed and added to or compared with the manifest.
- type – str
- manifest_file – file location of the manifest file. This is the
path which will be used for the
create()
andcompare()
methods. If the file exists, thecreate()
method will overwrite it. - exclude (list) – list containing patterns to use to exclude files from the manifest.
-
create
()[source]¶ Creates a new manifest from the directory by calling furtive.hasher.HashDirectory() and placing the return dictionary in to Manifest.manifest.
-
is_empty
()[source]¶ Determines if the manifest within memory is empty.
This simply checks to see if the manifest is None.
Returns: True if manifest is empty, False otherwise. Return type: bool