def cmd_delete(processes, force, verbose, dry_run): """Pass""" from aiida.manage.database.delete.nodes import delete_nodes verbosity = 2 if verbose else 0 delete_nodes([process.pk for process in processes], dry_run=dry_run, force=force, verbosity=verbosity)
def delete(codes, verbose, dry_run, force): """Delete a code. Note that codes are part of the data provenance, and deleting a code will delete all calculations using it. """ from aiida.manage.database.delete.nodes import delete_nodes verbosity = 1 if force: verbosity = 0 elif verbose: verbosity = 2 node_pks_to_delete = [code.pk for code in codes] delete_nodes(node_pks_to_delete, dry_run=dry_run, verbosity=verbosity, force=force)
def node_delete(nodes, dry_run, verbose, force, **kwargs): """Delete nodes from the provenance graph. This will not only delete the nodes explicitly provided via the command line, but will also include the nodes necessary to keep a consistent graph, according to the rules outlined in the documentation. You can modify some of those rules using options of this command. """ from aiida.manage.database.delete.nodes import delete_nodes verbosity = 1 if force: verbosity = 0 elif verbose: verbosity = 2 node_pks_to_delete = [node.pk for node in nodes] delete_nodes(node_pks_to_delete, dry_run=dry_run, verbosity=verbosity, force=force, **kwargs)
def delete_group(group, dry_run=False, verbosity=0, ignore_missing=True): """Delete a group, and all the nodes in it.""" from aiida import orm from aiida.common.exceptions import NotExistent from aiida.manage.database.delete.nodes import delete_nodes if isinstance(group, str): try: group = orm.Group.get(label=group) except NotExistent: if ignore_missing: return raise qb = (orm.QueryBuilder().append(group.__class__, filters={ 'id': group.id }, tag='group').append(orm.Node, with_group='group', project=["id"])) pks = [i for i, in qb.all()] delete_nodes(pks, force=True, dry_run=dry_run, verbosity=verbosity) if not dry_run: orm.Group.objects.delete(group.id)
def delete_process(process, dry_run=True, force=False, verbose=False): """Delete a process and its children recursively.""" from aiida import orm from aiida.common import exceptions from aiida.manage.database.delete.nodes import delete_nodes def has_descendants(pk): """Check whether a node has descendants.""" from aiida.orm import Node, QueryBuilder builder = QueryBuilder().append(Node, filters={ 'id': pk }, tag='origin').append(Node, with_incoming='origin', project='id') if builder.first(): return True else: return False verbosity = 2 if verbose else 0 # Get child processes and call this function recursively builder = orm.QueryBuilder().append(orm.Node, filters={ 'id': process.pk }, tag='origin').append( orm.ProcessNode, with_incoming='origin', project=['*']) for child, in builder.all(): delete_process(child, dry_run=dry_run, force=force, verbose=verbose) # Get nodes of incoming links builder = orm.QueryBuilder().append(orm.ProcessNode, filters={ 'id': process.pk }, tag='parent').append( orm.Data, with_outgoing='parent', project=['id']) incoming = [entry[0] for entry in builder.all()] delete_nodes([process.pk], dry_run=dry_run, force=force, verbosity=verbosity) orphans = [] for pk in incoming: try: orm.load_node(pk) except exceptions.NotExistent: continue else: if not has_descendants(pk): orphans.append(pk) if dry_run: logs = orm.Log.objects.get_logs_for(process) echo.echo_info('Would have deleted logs: {}'.format( [log.pk for log in logs])) echo.echo_info('Would have deleted orphaned inputs: {}'.format( [orphan for orphan in orphans])) else: echo.echo_info('Deleting orphaned inputs: {}'.format(orphans)) orm.Log.objects.delete_many(filters={'dbnode_id': process.pk}) delete_nodes(orphans, dry_run=dry_run, force=force, verbosity=verbosity)
import sys if len(sys.argv) > 1 and sys.argv[1] == "--pre": from aiida import orm group, _ = orm.Group.objects.get_or_create("delete-nodes") group.remove_nodes(group.nodes[:]) for i in range(1000): node = orm.Data() node.store() group.add_nodes([node]) else: from aiida import orm from aiida.manage.database.delete.nodes import delete_nodes group, _ = orm.Group.objects.get_or_create("delete-nodes") delete_nodes([node.pk for node in group.nodes[:]], force=True)