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.
compare()[source]

Compare the hashes in the database with the current hashes of files on the file system.

Returns:Dictionary of added, deleted, and changed files.
Return type:dict
create()[source]

Create and save a new manifest.

The contents of the new Manfiest() will be saved to manifest_path.

Returns:None

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
hash_files()[source]

Orchestrates the discovery and hashing of files.

Note: This method only supports the md5 hashing algorithm

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:
Returns:

hash of file

Return type:

dict

furtive.hasher.initializer(terminating_)[source]

Method to make terminating a global variable so that it is inherited by child processes.

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() and compare() methods. If the file exists, the create() 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
load()[source]

Load a manifest from the manifest file.

This method will open the manfiest YAML file and load it in to the manifest object variable.

save()[source]

Save the manifest to the manifest file.

Open a YAML file and dump the contents of the manifest to it.