def delete_files(ctx, workflow, filenames, access_token): # noqa: D301 """Delete files from workspace. The `rm` command allow to delete files and directories from workspace. Note that you can use glob to remove similar files. Examples:\n \t $ reana-client rm -w myanalysis.42 data/mydata.csv \n \t $ reana-client rm -w myanalysis.42 'code/\*' """ from reana_client.api.client import delete_file logging.debug("command: {}".format(ctx.command_path.replace(" ", "."))) for p in ctx.params: logging.debug("{param}: {value}".format(param=p, value=ctx.params[p])) if workflow: for filename in filenames: try: response = delete_file(workflow, filename, access_token) freed_space = 0 for file_ in response["deleted"]: freed_space += response["deleted"][file_]["size"] click.echo( click.style( "File {} was successfully deleted.".format(file_), fg="green", )) for file_ in response["failed"]: click.echo( click.style( "Something went wrong while deleting {}.\n{}". format(file_, response["failed"][file_]["error"]), fg="red", ), err=True, ) if freed_space: click.echo( click.style("{} bytes freed up.".format(freed_space), fg="green")) except FileDeletionError as e: click.echo(click.style(str(e), fg="red"), err=True) if "invoked_by_subcommand" in ctx.parent.__dict__: sys.exit(1) except Exception as e: logging.debug(traceback.format_exc()) logging.debug(str(e)) click.echo( click.style( "Something went wrong while deleting {}".format( filename), fg="red", ), err=True, ) if "invoked_by_subcommand" in ctx.parent.__dict__: sys.exit(1)
def delete_files(ctx, workflow, filenames, access_token): # noqa: D301 """Delete files from workspace. The `rm` command allow to delete files and directories from workspace. Note that you can use glob to remove similar files. Examples:\n \t $ reana-client rm -w myanalysis.42 data/mydata.csv \n \t $ reana-client rm -w myanalysis.42 'code/\*' """ logging.debug('command: {}'.format(ctx.command_path.replace(" ", "."))) for p in ctx.params: logging.debug('{param}: {value}'.format(param=p, value=ctx.params[p])) if not access_token: click.echo( click.style(ERROR_MESSAGES['missing_access_token'], fg='red'), err=True) sys.exit(1) if workflow: for filename in filenames: try: response = delete_file(workflow, filename, access_token) freed_space = 0 for file_ in response['deleted']: freed_space += response['deleted'][file_]['size'] click.echo(click.style( 'File {} was successfully deleted.'. format(file_), fg='green')) for file_ in response['failed']: click.echo( click.style( 'Something went wrong while deleting {}.\n{}'. format(file_, response['failed'][file_]['error']), fg='red'), err=True) if freed_space: click.echo(click.style('{} bytes freed up.'.format( freed_space), fg='green')) except FileDeletionError as e: click.echo(click.style(str(e), fg='red'), err=True) if 'invoked_by_subcommand' in ctx.parent.__dict__: sys.exit(1) except Exception as e: logging.debug(traceback.format_exc()) logging.debug(str(e)) click.echo( click.style( 'Something went wrong while deleting {}'. format(filename), fg='red'), err=True) if 'invoked_by_subcommand' in ctx.parent.__dict__: sys.exit(1)
def delete_reana_workflow_files(workflow_id, path=None, workflow=None): """Delete files from a workflow.""" rec_uuid = resolve_uuid(workflow_id) token = get_reana_token(rec_uuid) try: resp = delete_file(workflow_id, path, token) return jsonify(resp) except FileDeletionError: return jsonify({ 'message': '{} did not match any existing file. ' 'Aborting deletion.'.format(path) }), 400
def delete_files(ctx, workflow, filenames, access_token): # noqa: D301 """Delete files from workspace. The ``rm`` command allow to delete files and directories from workspace. Note that you can use glob to remove similar files. Examples:\n \t $ reana-client rm -w myanalysis.42 data/mydata.csv \n \t $ reana-client rm -w myanalysis.42 'data/*root*' """ # noqa: W605 from reana_client.api.client import delete_file logging.debug("command: {}".format(ctx.command_path.replace(" ", "."))) for p in ctx.params: logging.debug("{param}: {value}".format(param=p, value=ctx.params[p])) if workflow: for filename in filenames: try: response = delete_file(workflow, filename, access_token) freed_space = 0 for file_ in response["deleted"]: freed_space += response["deleted"][file_]["size"] display_message(f"File {file_} was successfully deleted.", msg_type="success") for file_ in response["failed"]: display_message( "Something went wrong while deleting {}.\n" "{}".format(file_, response["failed"][file_]["error"]), msg_type="error", ) if freed_space: display_message(f"{freed_space} bytes freed up.", msg_type="success") except FileDeletionError as e: display_message(str(e), msg_type="error") if "invoked_by_subcommand" in ctx.parent.__dict__: sys.exit(1) except Exception as e: logging.debug(traceback.format_exc()) logging.debug(str(e)) display_message( "Something went wrong while deleting {}".format(filename), msg_type="error", ) if "invoked_by_subcommand" in ctx.parent.__dict__: sys.exit(1)
def delete_files(ctx, workflow, filenames, access_token): """Delete files contained in the workflow workspace.""" logging.debug('command: {}'.format(ctx.command_path.replace(" ", "."))) for p in ctx.params: logging.debug('{param}: {value}'.format(param=p, value=ctx.params[p])) if not access_token: click.echo(click.style(ERROR_MESSAGES['missing_access_token'], fg='red'), err=True) sys.exit(1) if workflow: for filename in filenames: try: response = delete_file(workflow, filename, access_token) freed_space = 0 for file_ in response['deleted']: freed_space += response['deleted'][file_]['size'] click.echo( click.style( 'File {} was successfully deleted.'.format(file_), fg='green')) for file_ in response['failed']: click.echo(click.style( 'Something went wrong while deleting {}.\n{}'.format( file_, response['failed'][file_]['error']), fg='red'), err=True) if freed_space: click.echo( click.style('{} bytes freed up.'.format(freed_space), fg='green')) except FileDeletionError as e: click.echo(click.style(str(e), fg='red'), err=True) if 'invoked_by_subcommand' in ctx.parent.__dict__: sys.exit(1) except Exception as e: logging.debug(traceback.format_exc()) logging.debug(str(e)) click.echo(click.style( 'Something went wrong while deleting {}'.format(filename), fg='red'), err=True) if 'invoked_by_subcommand' in ctx.parent.__dict__: sys.exit(1)