def calculation_cleanworkdir(calculations, past_days, older_than, computers, force): """ Clean all content of all output remote folders of calculations. If no explicit calculations are specified as arguments, one or both of the -p and -o options has to be specified. If both are specified, a logical AND is done between the two, i.e. the calculations that will be cleaned have been modified AFTER [-p option] days from now, but BEFORE [-o option] days from now. """ from aiida.orm.backend import construct_backend from aiida.orm.utils.loaders import ComputerEntityLoader, IdentifierType from aiida.orm.utils.remote import clean_remote, get_calculation_remote_paths if calculations: if (past_days is not None and older_than is not None): echo.echo_critical( 'specify either explicit calculations or use the filtering options' ) else: if (past_days is None and older_than is None): echo.echo_critical( 'if no explicit calculations are specified, at least one filtering option is required' ) calculations_pks = [calculation.pk for calculation in calculations] path_mapping = get_calculation_remote_paths(calculations_pks, past_days, older_than, computers) if path_mapping is None: echo.echo_critical('no calculations found with the given criteria') if not force: path_count = sum( [len(paths) for computer, paths in path_mapping.items()]) warning = 'Are you sure you want to clean the work directory of {} calculations?'.format( path_count) click.confirm(warning, abort=True) backend = construct_backend() user = backend.users.get_automatic_user() for computer_uuid, paths in path_mapping.items(): counter = 0 computer = ComputerEntityLoader.load_entity( computer_uuid, identifier_type=IdentifierType.UUID) transport = backend.authinfos.get(computer, user).get_transport() with transport: for path in paths: clean_remote(transport, path) counter += 1 echo.echo_success('{} remote folders cleaned on {}'.format( counter, computer.name))
def _clean(self): """ Remove all content of the remote folder on the remote computer """ from aiida.orm.utils.remote import clean_remote authinfo = self.get_authinfo() transport = authinfo.get_transport() remote_dir = self.get_remote_path() with transport: clean_remote(transport, remote_dir)
def calcjob_cleanworkdir(calcjobs, past_days, older_than, computers, force): """ Clean all content of all output remote folders of calcjobs. If no explicit calcjobs are specified as arguments, one or both of the -p and -o options has to be specified. If both are specified, a logical AND is done between the two, i.e. the calcjobs that will be cleaned have been modified AFTER [-p option] days from now, but BEFORE [-o option] days from now. """ from aiida.orm.utils.loaders import ComputerEntityLoader, IdentifierType from aiida.orm.utils.remote import clean_remote, get_calcjob_remote_paths from aiida import orm if calcjobs: if (past_days is not None and older_than is not None): echo.echo_critical('specify either explicit calcjobs or use the filtering options') else: if (past_days is None and older_than is None): echo.echo_critical('if no explicit calcjobs are specified, at least one filtering option is required') calcjobs_pks = [calcjob.pk for calcjob in calcjobs] path_mapping = get_calcjob_remote_paths(calcjobs_pks, past_days, older_than, computers) if path_mapping is None: echo.echo_critical('no calcjobs found with the given criteria') if not force: path_count = sum([len(paths) for computer, paths in path_mapping.items()]) warning = f'Are you sure you want to clean the work directory of {path_count} calcjobs?' click.confirm(warning, abort=True) user = orm.User.objects.get_default() for computer_uuid, paths in path_mapping.items(): counter = 0 computer = ComputerEntityLoader.load_entity(computer_uuid, identifier_type=IdentifierType.UUID) transport = orm.AuthInfo.objects.get(dbcomputer_id=computer.id, aiidauser_id=user.id).get_transport() with transport: for path in paths: clean_remote(transport, path) counter += 1 echo.echo_success(f'{counter} remote folders cleaned on {computer.label}')