def move_files(ctx, source, target, workflow, access_token): # noqa: D301 """Move files within workspace. The `mv` command allow to move the files within workspace. Examples:\n \t $ reana-client mv data/input.txt input/input.txt """ from reana_client.api.client import get_workflow_status, list_files, mv_files 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: try: current_status = get_workflow_status(workflow, access_token).get("status") if current_status == "running": click.echo( click.style( "File(s) could not be moved for running " "workflow", fg="red" ), err=True, ) sys.exit(1) files = list_files(workflow, access_token) current_files = [file["name"] for file in files] if not any(source in item for item in current_files): click.echo( click.style( "Source file(s) {} does not exist in " "workspace {}".format(source, current_files), fg="red", ), err=True, ) sys.exit(1) mv_files(source, target, workflow, access_token) click.echo( click.style( "{} was successfully moved to {}.".format(source, target), fg="green", ) ) except Exception as e: logging.debug(traceback.format_exc()) logging.debug(str(e)) click.echo( click.style("Something went wrong. {}".format(e), fg="red"), err=True )
def move_files(ctx, source, target, workflow, access_token): # noqa: D301 r"""Move files within workspace. Examples:\n \t $ reana-client mv data/input.txt input/input.txt """ 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: try: current_status = get_workflow_status(workflow, access_token).get('status') if current_status == 'running': click.echo(click.style( 'File(s) could not be moved for running ' 'workflow', fg='red'), err=True) sys.exit(1) files = list_files(workflow, access_token) current_files = [file['name'] for file in files] if not any(source in item for item in current_files): click.echo(click.style('Source file(s) {} does not exist in ' 'workspace {}'.format( source, current_files), fg='red'), err=True) sys.exit(1) response = mv_files(source, target, workflow, access_token) click.echo( click.style('{} was successfully moved to {}.'.format( source, target), fg='green')) except Exception as e: logging.debug(traceback.format_exc()) logging.debug(str(e)) click.echo(click.style('Something went wrong. {}'.format(e), fg='red'), err=True)