import hashlib


def _get_local_log_hashes(local_base, logger):
    """Get a dict mapping file paths to hashes for logs in the specified
    local directory.
    File paths will be relative to the root path of the extracted logs.
    journalctl.log and supervisord.log will be checked for existence but not
    contents, as we can't prevent them from changing reliably.
    """
    logger.info('Checking local log hashes in %s', str(local_base))
    files = list(local_base.walkfiles())

    logger.info('Checking both `journalctl.log` and '
                '`supervisord.log`exist inside %s',
                str(local_base))
    assert str(local_base / 'journalctl.log') in files
    assert str(local_base / 'supervisord.log') in files

    log_hashes_local = {
        str(f)[len(local_base):]: hashlib.md5(
            open(str(f), 'rb').read()).hexdigest()
        for f in files
        if 'journalctl' not in f.basename()
        and 'supervisord' not in f.basename()
    }
    logger.info('Calculated local log hashes are %s',
                log_hashes_local)
    return log_hashes_local