def _ensure_directory(path):
    'Ensures that the directory hierarchy of the given path exists.'
    target_dir = os.path.dirname(path)
    try:
        os.makedirs(target_dir)
    except OSError as exception:
        if ((exception.errno == errno.EEXIST) and os.path.isdir(target_dir)):
            pass
        else:
            raise
Ensures that the directory hierarchy of the given path exists.
def _ensure_directory(path):
    
    target_dir = os.path.dirname(path)
    try:
        os.makedirs(target_dir)
    except OSError as exception:
        if ((exception.errno == errno.EEXIST) and os.path.isdir(target_dir)):
            pass
        else:
            raise