reana_workflow_controller/utils.py
def remove_files_recursive_wildcard(directory_path, path):
    """Remove file(s) fitting the wildcard from the workspace.

    :param directory_path: Directory to delete files from.
    :param path: Wildcard pattern to use for the removal.
    :return: Dictionary with the results:
       - dictionary with names of succesfully deleted files and their sizes
       - dictionary with names of failed deletions and corresponding
       error messages.
    """
    deleted = {"deleted": {}, "failed": {}}
    secure_path = remove_upper_level_references(path)
    posix_dir_prefix = Path(directory_path)
    paths = list(posix_dir_prefix.glob(secure_path))
    # sort paths by length to start with the leaves of the directory tree
    paths.sort(key=lambda path: len(str(path)), reverse=True)
    for posix_path in paths:
        try:
            file_name = str(posix_path.relative_to(posix_dir_prefix))
            object_size = posix_path.stat().st_size
            os.unlink(posix_path) if posix_path.is_file() \
                else os.rmdir(posix_path)

            deleted['deleted'][file_name] = \
                {"size": object_size}
        except Exception as e:
            deleted['failed'][file_name] = \
                {"error": str(e)}

    return deleted
Remove file(s) fitting the wildcard from the workspace.

    :param directory_path: Directory to delete files from.
    :param path: Wildcard pattern to use for the removal.
    :return: Dictionary with the results:
       - dictionary with names of succesfully deleted files and their sizes
       - dictionary with names of failed deletions and corresponding
       error messages.
    
Remove file(s) fitting the wildcard from the workspace.
Remove file ( s ) fitting the wildcard from the workspace .
def remove_files_recursive_wildcard(directory_path, path):
    deleted = {"deleted": {}, "failed": {}}
    secure_path = remove_upper_level_references(path)
    posix_dir_prefix = Path(directory_path)
    paths = list(posix_dir_prefix.glob(secure_path))
    paths.sort(key=lambda path: len(str(path)), reverse=True)
    for posix_path in paths:
        try:
            file_name = str(posix_path.relative_to(posix_dir_prefix))
            object_size = posix_path.stat().st_size
            os.unlink(posix_path) if posix_path.is_file() \
                else os.rmdir(posix_path)
            deleted['deleted'][file_name] = \
                {"size": object_size}
        except Exception as e:
            deleted['failed'][file_name] = \
                {"error": str(e)}
    return deleted
def remove_files_recursive_wildcard ( directory_path , path ) : deleted = { "deleted" : { } , "failed" : { } } secure_path = remove_upper_level_references ( path ) posix_dir_prefix = Path ( directory_path ) paths = list ( posix_dir_prefix . glob ( secure_path ) ) paths . sort ( key = lambda path : len ( str ( path ) ) , reverse = True ) for posix_path in paths : try : file_name = str ( posix_path . relative_to ( posix_dir_prefix ) ) object_size = posix_path . stat ( ) . st_size os . unlink ( posix_path ) if posix_path . is_file ( ) else os . rmdir ( posix_path ) deleted [ 'deleted' ] [ file_name ] = { "size" : object_size } except Exception as e : deleted [ 'failed' ] [ file_name ] = { "error" : str ( e ) } return deleted
Remove file(s) fitting the wildcard from the workspace.
Remove file ( s ) fitting the wildcard from the workspace .
"""Remove file(s) fitting the wildcard from the workspace.

    :param directory_path: Directory to delete files from.
    :param path: Wildcard pattern to use for the removal.
    :return: Dictionary with the results:
       - dictionary with names of succesfully deleted files and their sizes
       - dictionary with names of failed deletions and corresponding
       error messages.
    """ # sort paths by length to start with the leaves of the directory tree
Dictionary with the results:
dictionary with names of succesfully deleted files and their sizes
dictionary with names of failed deletions and corresponding
error messages.
Dictionary with the results : dictionary with names of succesfully deleted files and their sizes dictionary with names of failed deletions and corresponding error messages .
directory_path
Directory to delete files from.
Directory to delete files from .
path
Wildcard pattern to use for the removal.
Wildcard pattern to use for the removal .