Determines if a particular path is larger than expected. Useful before any recursive remove.

def safe_size_check(checked_path, error_detail, max_bytes=500000000):
    """Determines if a particular path is larger than expected. Useful before any recursive remove."""
    actual_size = 0
    for dirpath, dirnames, filenames in os.walk(checked_path):
        for f in filenames:
            fp = os.path.join(dirpath, f)
            actual_size += os.path.getsize(fp)

    assert actual_size <= max_bytes, "Path {} size of {} >= {} bytes. {}".format(
        checked_path, actual_size, max_bytes, error_detail)