nussl/core/efz_utils.py
def _hash_directory(directory, ext=None):
    """
    Calculates the hash of every child file in the given directory using python's built-in SHA256
    function (using `os.walk()`, which also searches subdirectories recursively). If :param:`ext`
    is specified, this will only look at files with extension provided.

    This function is used to verify the integrity of data sets for use with nussl. Pretty much
    just makes sure that when we loop through/look at a directory, we understand the structure
    because the organization of the data set directories for different data sets are all unique
    and thus need to be hard coded by each generator function (below). If we get a hash mismatch
    we can throw an error easily.

    Args:
        directory (str): Directory within which file hashes get calculated. Searches recursively.
        ext (str): If provided, this function will only calculate the hash on files with the given
            extension.

    Returns:
        (str): String containing only hexadecimal digits of the has of the
            contents of the given directory.

    """
    hash_list = []
    for path, sub_dirs, files in os.walk(directory):
        if ext is None:
            hash_list.extend([_hash_file(os.path.join(path, f)) for f in files
                              if os.path.isfile(os.path.join(path, f))])
        else:
            hash_list.extend([_hash_file(os.path.join(path, f)) for f in files
                              if os.path.isfile(os.path.join(path, f))
                              if os.path.splitext(f)[1] == ext])

    hasher = hashlib.sha256()
    for hash_val in sorted(hash_list):  # Sort this list so we're platform agnostic
        hasher.update(hash_val.encode('utf-8'))

    return hasher.hexdigest()

    Calculates the hash of every child file in the given directory using python's built-in SHA256
    function (using `os.walk()`, which also searches subdirectories recursively). If :param:`ext`
    is specified, this will only look at files with extension provided.

    This function is used to verify the integrity of data sets for use with nussl. Pretty much
    just makes sure that when we loop through/look at a directory, we understand the structure
    because the organization of the data set directories for different data sets are all unique
    and thus need to be hard coded by each generator function (below). If we get a hash mismatch
    we can throw an error easily.

    Args:
        directory (str): Directory within which file hashes get calculated. Searches recursively.
        ext (str): If provided, this function will only calculate the hash on files with the given
            extension.

    Returns:
        (str): String containing only hexadecimal digits of the has of the
            contents of the given directory.

    
Calculates the hash of every child file in the given directory using python's built-in SHA256
function (using `os.walk()`, which also searches subdirectories recursively). If :param:`ext`
is specified, this will only look at files with extension provided.

This function is used to verify the integrity of data sets for use with nussl. Pretty much
just makes sure that when we loop through/look at a directory, we understand the structure
because the organization of the data set directories for different data sets are all unique
and thus need to be hard coded by each generator function (below). If we get a hash mismatch
we can throw an error easily.
Calculates the hash of every child file in the given directory using python ' s built - in SHA256 function ( using ` os . walk () ` which also searches subdirectories recursively ) . If : param : ` ext ` is specified this will only look at files with extension provided . This function is used to verify the integrity of data sets for use with nussl . Pretty much just makes sure that when we loop through / look at a directory we understand the structure because the organization of the data set directories for different data sets are all unique and thus need to be hard coded by each generator function ( below ) . If we get a hash mismatch we can throw an error easily .
def _hash_directory(directory, ext=None):
    hash_list = []
    for path, sub_dirs, files in os.walk(directory):
        if ext is None:
            hash_list.extend([_hash_file(os.path.join(path, f)) for f in files
                              if os.path.isfile(os.path.join(path, f))])
        else:
            hash_list.extend([_hash_file(os.path.join(path, f)) for f in files
                              if os.path.isfile(os.path.join(path, f))
                              if os.path.splitext(f)[1] == ext])
    hasher = hashlib.sha256()
    for hash_val in sorted(hash_list):  
        hasher.update(hash_val.encode('utf-8'))
    return hasher.hexdigest()
def _hash_directory ( directory , ext = None ) : hash_list = [ ] for path , sub_dirs , files in os . walk ( directory ) : if ext is None : hash_list . extend ( [ _hash_file ( os . path . join ( path , f ) ) for f in files if os . path . isfile ( os . path . join ( path , f ) ) ] ) else : hash_list . extend ( [ _hash_file ( os . path . join ( path , f ) ) for f in files if os . path . isfile ( os . path . join ( path , f ) ) if os . path . splitext ( f ) [ 1 ] == ext ] ) hasher = hashlib . sha256 ( ) for hash_val in sorted ( hash_list ) : hasher . update ( hash_val . encode ( 'utf-8' ) ) return hasher . hexdigest ( )
Calculates the hash of every child file in the given directory using python's built-in SHA256
function (using `os.walk()`, which also searches subdirectories recursively).
Calculates the hash of every child file in the given directory using python ' s built - in SHA256 function ( using ` os . walk () ` which also searches subdirectories recursively ) .
"""
    Calculates the hash of every child file in the given directory using python's built-in SHA256
    function (using `os.walk()`, which also searches subdirectories recursively). If :param:`ext`
    is specified, this will only look at files with extension provided.

    This function is used to verify the integrity of data sets for use with nussl. Pretty much
    just makes sure that when we loop through/look at a directory, we understand the structure
    because the organization of the data set directories for different data sets are all unique
    and thus need to be hard coded by each generator function (below). If we get a hash mismatch
    we can throw an error easily.

    Args:
        directory (str): Directory within which file hashes get calculated. Searches recursively.
        ext (str): If provided, this function will only calculate the hash on files with the given
            extension.

    Returns:
        (str): String containing only hexadecimal digits of the has of the
            contents of the given directory.

    """ # Sort this list so we're platform agnostic
String containing only hexadecimal digits of the has of the
contents of the given directory.
String containing only hexadecimal digits of the has of the contents of the given directory .
(str)
directory
Directory within which file hashes get calculated. Searches recursively.
Directory within which file hashes get calculated . Searches recursively .
ext
If provided, this function will only calculate the hash on files with the given
extension.
If provided this function will only calculate the hash on files with the given extension .