def export(selected): if args.copy_resources and not args.yes: cli.out( "WARNING: you have specified --copy-resources, which will " "copy resources used by each run!" "" ) if not cli.confirm("Really copy resources exported runs?"): return util.ensure_dir(args.location) util.touch(os.path.join(args.location, ".guild-nocopy")) exported = 0 for run in selected: dest = os.path.join(args.location, run.id) if os.path.exists(dest): log.warning("%s exists, skipping", dest) continue if args.move: cli.out("Moving {}".format(run.id)) if args.copy_resources: shutil.copytree(run.path, dest) shutil.rmtree(run.path) else: shutil.move(run.path, dest) else: cli.out("Copying {}".format(run.id)) symlinks = not args.copy_resources shutil.copytree(run.path, dest, symlinks) exported += 1 cli.out("Exported %i run(s)" % exported)
def runs_op(args, ctx, force_deleted, preview_msg, confirm_prompt, no_runs_help, op_callback, default_runs_arg=None, confirm_default=False, runs_callback=None): get_selected = runs_callback or runs_op_selected selected = get_selected(args, ctx, default_runs_arg, force_deleted) if not selected: _no_selected_runs_exit(no_runs_help) formatted = None # expensive, lazily init as needed if not args.yes: formatted = formatted = format_runs(selected) cli.out(preview_msg) cols = [ "short_index", "op_desc", "started", "status_with_remote", "label" ] cli.table(formatted, cols=cols, indent=2) fmt_confirm_prompt = confirm_prompt.format(count=len(selected)) if args.yes or cli.confirm(fmt_confirm_prompt, confirm_default): # pylint: disable=deprecated-method if len(inspect.getargspec(op_callback).args) == 2: formatted = formatted = format_runs(selected) op_callback(selected, formatted) else: op_callback(selected)
def export(selected): if args.copy_resources and not args.yes: cli.out( "WARNING: you have specified --copy-resources, which will " "copy resources used by each run!" ) if not cli.confirm("Really copy resources exported runs?"): return imported = 0 for run in selected: dest = os.path.join(var.runs_dir(), run.id) if os.path.exists(dest): log.warning("%s exists, skipping", run.id) continue if args.move: cli.out("Moving {}".format(run.id)) if args.copy_resources: shutil.copytree(run.path, dest) shutil.rmtree(run.path) else: shutil.move(run.path, dest) else: cli.out("Copying {}".format(run.id)) symlinks = not args.copy_resources shutil.copytree(run.path, dest, symlinks) imported += 1 cli.out("Imported %i run(s)" % imported)
def _runs_op(args, ctx, force_deleted, preview_msg, confirm_prompt, no_runs_help, op_callback, default_runs_arg=None, confirm_default=False, runs_callback=None): get_selected = runs_callback or _runs_op_selected selected = get_selected(args, ctx, default_runs_arg, force_deleted) if not selected: _no_selected_runs_exit(no_runs_help) formatted = [run_util.format_run(run) for run in selected] if not args.yes: cli.out(preview_msg) cols = [ "short_index", "operation_with_marked", "started", "status_with_remote", "label" ] cli.table(formatted, cols=cols, indent=2) formatted_confirm_prompt = confirm_prompt.format(count=len(formatted)) if args.yes or cli.confirm(formatted_confirm_prompt, confirm_default): if len(inspect.getargspec(op_callback).args) == 2: op_callback(selected, formatted) else: op_callback(selected)
def _confirm(config): cli.out("You are about to initialize a Guild environment:") for name, val in config.prompt_params: if isinstance(val, tuple): cli.out(" {}:".format(name)) for x in val: cli.out(" {}".format(x)) else: cli.out(" {}: {}".format(name, val)) return cli.confirm("Continue?", default=True)
def _remote_op(op, prompt, default_resp, args): if not args.yes: cli.out(prompt) if args.yes or cli.confirm("Continue?", default_resp): try: op() except guild.remote.OperationNotSupported as e: cli.error(e) except guild.remote.OperationError as e: cli.error(e)
def _confirm_run(op, args): prompt = ( "You are about to {action} {op_desc}{batch_suffix}{remote_suffix}\n" "{flags}" "{resources}" "Continue?".format(action=_action_desc(args), op_desc=_op_desc(op), batch_suffix=_batch_suffix(op, args), remote_suffix=_remote_suffix(args), flags=_format_op_flags(op), resources=_format_op_resources(op.resource_config))) return cli.confirm(prompt, default=True)
def _confirm_run(S): prompt = ("You are about to {action} {subject}" "{batch_suffix}{remote_suffix}{flags_note}\n" "{flags}" "Continue?".format( action=_preview_op_action(S), subject=_preview_op_subject(S), batch_suffix=_preview_batch_suffix(S), remote_suffix=_preview_remote_suffix(S), flags_note=_preview_flags_note(S), flags=_preview_flags(S), )) return cli.confirm(prompt, default=True)
def _runs_op(args, ctx, force_delete, preview_msg, confirm_prompt, no_runs_help, op_callback): runs = runs_for_args(args, force_delete) runs_arg = args.runs or ALL_RUNS_ARG selected = selected_runs(runs, runs_arg, ctx) if not selected: _no_selected_runs_error(no_runs_help) preview = [format_run(run) for run in selected] if not args.yes: cli.out(preview_msg) cols = ["short_index", "operation", "started", "status"] cli.table(preview, cols=cols, indent=2) if args.yes or cli.confirm(confirm_prompt): op_callback(selected)
def delete(selected): stoppable = [ run for run in selected if run.status == "running" and not run.remote ] if stoppable and not args.yes: cli.out("WARNING: one or more runs are still running " "and will be stopped before being deleted.") if not cli.confirm("Really delete these runs?"): return for run in stoppable: _stop_run(run, no_wait=True) var.delete_runs(selected, args.permanent) if args.permanent: cli.out("Permanently deleted %i run(s)" % len(selected)) else: cli.out("Deleted %i run(s)" % len(selected))
def _edit_op_flags(op): encoded_flags = util.encode_yaml(op._op_flag_vals) while True: # Loop to let user re-edit on error. edited = util.editor(encoded_flags) if edited is None or not edited.strip(): break try: flag_vals = util.decode_yaml(edited) except ValueError as e: cli.out("Error reading flags: %s" % e, err=True) if not cli.confirm("Would you like to re-edit these flags?", default=True): cli.error() else: op._op_flag_vals = flag_vals break
def import_f(selected): if args.copy_resources and not args.yes: cli.out( cmd_impl_support.format_warn( "WARNING: You specified --copy-resources, which will " "copy resources used by each run."), err=True, ) if not cli.confirm("Really copy resources exported runs?"): raise SystemExit(exit_code.ABORTED) try: imported = run_util.import_runs( selected, move=args.move, copy_resources=args.copy_resources, ) except run_util.RunsImportError as e: cli.error(e.args[0]) cli.out("Imported %i run(s) from %s" % (len(imported), args.archive), err=True)
def delete(selected): stoppable = [ run for run in selected if run.status == "running" and not run.remote ] if stoppable and not args.yes: cli.out( cmd_impl_support.format_warn( "WARNING: One or more runs are still running " "and will be stopped before being deleted."), err=True, ) if not cli.confirm("Really delete these runs?"): raise SystemExit(exit_code.ABORTED) for run in stoppable: _stop_run(run, no_wait=True) var.delete_runs(selected, args.permanent) if args.permanent: cli.out("Permanently deleted %i run(s)" % len(selected), err=True) else: cli.out("Deleted %i run(s)" % len(selected), err=True)