get_image_hash will return an md5 hash of the file based on a criteria level.
    :param level: one of LOW, MEDIUM, HIGH
    :param image_path: full path to the singularity image
546653
def get_image_file_hash(image_path):
    '''
    '''
    hasher = hashlib.md5()
    with open(image_path, "rb") as f:
        for chunk in iter(lambda: f.read(4096), b""):
            hasher.update(chunk)
    return hasher.hexdigest()
1228861
def hash_tree(filepath: str) -> str:
    
    if isfile(filepath):
        return hash_file(filepath)
    if isdir(filepath):
        base_dir = filepath
        md5 = hashlib.md5()
        for root, dirs, files in walk(base_dir):
            dirs.sort()
            for fname in sorted(files):
                filepath = join(root, fname)
                # consistent hashing between POSIX & Windows
                md5.update(relpath(filepath, base_dir)
                           .replace('\\', '/').encode('utf8'))
                acc_hash(filepath, md5)
        return md5.hexdigest()
    return None
1090473
def hash_file(filepath: str) -> str:
    """"""
    md5 = hashlib.md5()
    acc_hash(filepath, md5)
    return md5.hexdigest()
285248
def hash_opensubtitles(video_path):
    
    bytesize = struct.calcsize(b'<q')
    with open(video_path, 'rb') as f:
        filesize = os.path.getsize(video_path)
        filehash = filesize
        if filesize < 65536 * 2:
            return
        for _ in range(65536 // bytesize):
            filebuffer = f.read(bytesize)
            (l_value,) = struct.unpack(b'<q', filebuffer)
            filehash += l_value
            filehash &= 0xFFFFFFFFFFFFFFFF  # to remain as 64bit number
        f.seek(max(0, filesize - 65536), 0)
        for _ in range(65536 // bytesize):
            filebuffer = f.read(bytesize)
            (l_value,) = struct.unpack(b'<q', filebuffer)
            filehash += l_value
            filehash &= 0xFFFFFFFFFFFFFFFF
    returnedhash = '%016x' % filehash

    return returnedhash
267415
def get_hash_tuple(header_path, cython_path, gen_file_path):
    """"""

    header_hash = (sha1_of_file(header_path)
                   if os.path.exists(header_path) else 'NA')
    from_hash = sha1_of_file(cython_path)
    to_hash = (sha1_of_file(gen_file_path)
               if os.path.exists(gen_file_path) else 'NA')

    return header_hash, from_hash, to_hash
71118
def sha1_of_file(filepath):
    
    import hashlib
    try:
        with open(filepath, 'rb') as file_to_hash:
            return hashlib.sha1(file_to_hash.read()).hexdigest()
    except:  # pylint: disable=bare-except
        return None
1331887
def get_file_hash(storage, path):
    
    contents = storage.open(path).read()
    file_hash = hashlib.md5(contents).hexdigest()

    # Check if content should be gzipped and hash gzipped content
    content_type = mimetypes.guess_type(path)[0] or 'application/octet-stream'
    if settings.is_gzipped and content_type in settings.gzip_content_types:
        cache_key = get_cache_key('gzip_hash_%s' % file_hash)
        file_hash = cache.get(cache_key, False)
        if file_hash is False:
            buffer = BytesIO()
            zf = gzip.GzipFile(
                mode='wb', compresslevel=6, fileobj=buffer, mtime=0.0)
            zf.write(force_bytes(contents))
            zf.close()
            file_hash = hashlib.md5(buffer.getvalue()).hexdigest()
            cache.set(cache_key, file_hash)

    return '"%s"' % file_hash
669840
def get_abs_image_path(self, path):
        

        if not path:
            return ""
        orig_path = path

        server_config = self.config.get_section_config("Server")
        img_directory = self.get_images_directory()

        # Windows path should not be send to a unix server
        if not sys.platform.startswith("win"):
            if re.match(r"^[A-Z]:", path) is not None:
                raise NodeError("{} is not allowed on this remote server. Please use only a filename in {}.".format(path, img_directory))

        if not os.path.isabs(path):
            for directory in images_directories(self._NODE_TYPE):
                path = self._recursive_search_file_in_directory(directory, orig_path)
                if path:
                    return force_unix_path(path)

            # Not found we try the default directory
            s = os.path.split(orig_path)
            path = force_unix_path(os.path.join(img_directory, *s))
            if os.path.exists(path):
                return path
            raise ImageMissingError(orig_path)

        # For non local server we disallow using absolute path outside image directory
        if server_config.getboolean("local", False) is True:
            path = force_unix_path(path)
            if os.path.exists(path):
                return path
            raise ImageMissingError(orig_path)

        path = force_unix_path(path)
        for directory in images_directories(self._NODE_TYPE):
            if os.path.commonprefix([directory, path]) == directory:
                if os.path.exists(path):
                    return path
                raise ImageMissingError(orig_path)
        raise NodeError("{} is not allowed on this remote server. Please use only a filename in {}.".format(path, img_directory))
296065
def _md5_of_file(sub_string):
    
    md5 = hashlib.md5()
    file_path = sub_string
    if not os.path.exists(file_path):
        file_path = os.path.join(os.environ['CAFE_DATA_DIR_PATH'], file_path)
    if not os.path.exists(file_path):
        file_path = file_path.replace(' ', '_')
    assert (os.path.exists(file_path)), "File %s doesn't exist" % file_path
    with open(file_path, 'rb') as f:
        for chunk in iter(lambda: f.read(8192), b''):
            md5.update(chunk)
    return md5.hexdigest()
1269302
def write_and_get_hash(path, write_to_file, hash=None):
    
    hash = hash or hashlib.md5()
    try:
        # Access path
        r = config.DOWNLOAD_SESSION.get(path, stream=True)
        r.raise_for_status()
        for chunk in r:
            write_to_file.write(chunk)
            hash.update(chunk)

    except (MissingSchema, InvalidSchema):
        # If path is a local file path, try to open the file (generate hash if none provided)
        with open(path, 'rb') as fobj:
            for chunk in iter(lambda: fobj.read(2097152), b""):
                write_to_file.write(chunk)
                hash.update(chunk)

    assert write_to_file.tell() > 0, "File failed to write (corrupted)."

    return hash
512965
def get_hash(self, handle):
        """"""
        fpath = self._fpath_from_handle(handle)
        return DiskStorageBroker.hasher(fpath)
1183063
def _getProcessedImage(self):
        """"""
        if self.imageDisp is None:
            self.imageDisp = self.image
            self.levelMin, self.levelMax = self._quickLevels(
                self.imageDisp)
            #list( map(float, self._quickLevels(self.imageDisp)))
        return self.imageDisp
144170
def add_asset_hashes(self, path='dist/assets'):
		
		for fullpath in _listfiles(os.path.join(self.root_path, path)):
			relpath = fullpath.replace(self.root_path + '/' + path + '/', '')
			md5sum = hashlib.md5(open(fullpath, 'rb').read()).hexdigest()
			LOG.debug('MD5 of %s (%s): %s', fullpath, relpath, md5sum)
			self.asset_hash[relpath] = md5sum
1298837
def top_level_file(absolute_path=true)
     
      path = get_property(TopLevelFileProperty)

      #If the absolute_path flag is set, and we know how, expand the file path.
      if absolute_path
        path = File.expand_path(path, @base_path) 
      end

      #Return the relevant path.
      path

    end
1128515
def get_file_hash(self, *algorithms: str):
        '''
        
        '''
        from .hashs import hashfile_hexdigest
        return hashfile_hexdigest(self._path, algorithms)
559651
def md5sum(path):
    

    if path is None or len(path) == 0 or not os.path.exists(path):
        return None

    try:
        with open(path + '.md5sum') as f:
            md5 = f.read()
            if len(md5) == 32:
                return md5
    # Unicode error is when user rename an image to .md5sum ....
    except (OSError, UnicodeDecodeError):
        pass

    try:
        m = hashlib.md5()
        with open(path, 'rb') as f:
            while True:
                buf = f.read(128)
                if not buf:
                    break
                m.update(buf)
        digest = m.hexdigest()
    except OSError as e:
        log.error("Can't create digest of %s: %s", path, str(e))
        return None

    try:
        with open('{}.md5sum'.format(path), 'w+') as f:
            f.write(digest)
    except OSError as e:
        log.error("Can't write digest of %s: %s", path, str(e))

    return digest
604410
def _md5_sum_file(path):
    
    with Path(path).open('rb') as fhandle:
        md5sum = hashlib.md5()
        while True:
            data = fhandle.read(8192)
            if not data:
                break
            md5sum.update(data)
    return md5sum.hexdigest()