Exemple #1
0
def sha256sum(path):
    blocksize = 65536
    sha = hashlib.new("sha256")
    with open(path, "r+b") as f:
        for block in iter(lambda: f.read(blocksize), ""):
            sha.update(block)

    return sha.hexdigest()
Exemple #2
0
def sha256sum(path):
    blocksize = 65536
    sha = hashlib.new("sha256")
    with open(path, "r+b") as f:
        for block in iter(lambda: f.read(blocksize), ""):
            sha.update(block)

    return sha.hexdigest()
Exemple #3
0
    def _md5_checksum(self, path):
        """Returns the checksum of the file"""

        if os.path.isdir(path):
            return None

        try:
            md5_gen = hashlib.new("md5")

            with open(path, "r") as fd:
                # Read the file in 1K chunks to avoid memory consumption
                while True:
                    chunk = fd.read(1024)
                    if not chunk:
                        break

                    md5_gen.update(chunk)

                return md5_gen.hexdigest()

        except Exception, ex: # pragma: no cover
            debug.exception(ex)
Exemple #4
0
    def _md5_checksum(self, path):
        """Returns the checksum of the file"""

        if os.path.isdir(path):
            return None

        try:
            md5_gen = hashlib.new("md5")

            with open(path, "r") as fd:
                # Read the file in 1K chunks to avoid memory consumption
                while True:
                    chunk = fd.read(1024)
                    if not chunk:
                        break

                    md5_gen.update(chunk)

                return md5_gen.hexdigest()

        except Exception, ex:  # pragma: no cover
            debug.exception(ex)