freezer.utils.checksum module

freezer.utils.checksum module

class freezer.utils.checksum.CheckSum(path, hasher_type='sha256', blocksize=1048576, exclude='', ignorelinks=False)

Bases: object

Checksum a file or directory with sha256 or md5 algorithms.

This is used by backup and restore jobs to check for backup consistency.

  • parameters::
    param path:the path to the file or directory to checksum
    type path:string
    param hasher_type:
     the hashing algorithm to use for checksum
    type hasher_type:
     string
    param hasher:hasher object for the specified hasher_type
    type hasher:hashlib object
    param blocksize:
     the max. size of block to read when hashing a file
    type blocksize:integer
    param exclude:pattern of files to exclude
    type exclude:string
    param checksum:final result for checksum computing
    type checksum:string
    param real_checksum:
     checksum without filename appended if unique file
    type real_checksum:
     string
    param count:number of files checksummed
    type count:int
compare(checksum)

Compute the checksum for the object path and compare with the given checksum. :return: boolean

compute()

Compute the checksum for the given path. If a single file is provided, the result is its checksum concatenated with its name. If a directory is provided, the result is the checksum of the checksum concatenation for each file. :return: string

get_files_hashes_in_path()

Walk the files in path computing the checksum for each one and updates the concatenation checksum for the final result

get_hash(filepath)

Open filename and calculate its hash. Append the hash to the previous result and stores the checksum for this concatenation :param filepath: path to file :type filepath: string :return: string containing the hash of the given file

hashes = []
hashfile(afile)

Checksum a single file with the chosen algorithm. The file is read in chunks of self.blocksize. :return: string

hashstring(string)
Returns:the hash for a given string
set_hasher(hasher_type)

Sets the hasher from hashlib according to the chosen hasher_type. Also sets the size of the expected output

Creative Commons Attribution 3.0 License

Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.