def _publish_run_info(state): """Write run.yml to run publish dest. This function should be kept in sync with output generated by `guild runs info` - minus system-specific values (e.g. run_dir and pid) and flags (which are written to a separate file). """ run = state.run frun = state.formatted_run path = os.path.join(state.run_dest, "run.yml") encode = lambda x: util.encode_yaml(x).rstrip() fmt_ts = util.utcformat_timestamp started = run.get("started") stopped = run.get("stopped") with codecs.open(path, "w", "utf-8") as f: f.write("id: %s\n" % run.id) f.write("operation: %s\n" % encode(frun["operation"])) f.write("status: %s\n" % encode(frun["status"])) f.write("started: %s\n" % fmt_ts(started)) f.write("stopped: %s\n" % fmt_ts(stopped)) f.write("time: %s\n" % _format_time(started, stopped)) f.write("marked: %s\n" % encode(frun["marked"])) f.write("label: %s\n" % encode(run.get("label"))) f.write("command: %s\n" % encode(frun["command"])) f.write("exit_status: %s\n" % encode(frun["exit_status"]))
def write_attr(self, name, val, raw=False): if not raw: val = util.encode_yaml(val) with open(self._attr_path(name), "w") as f: f.write(val) f.write(os.linesep) f.close()
def encode_flag_val(val): if val is True: return "yes" elif val is False: return "no" elif val is None: return "null" elif isinstance(val, list): return _encode_list(val) elif isinstance(val, dict): return _encode_dict(val) else: return util.encode_yaml(val, default_flow_style=True)
def encode_flag_val(val): if val is True: return "yes" elif val is False: return "no" elif val is None: return "null" elif isinstance(val, list): return _encode_list(val) elif isinstance(val, float): return util.encode_yaml(val) elif isinstance(val, six.string_types): return _encode_str(val) elif isinstance(val, dict): return _encode_dict(val) else: return str(val)
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 _print_run_info_ordered(data): # Use consistent formatting across flags and run info output. encode_val = flag_util.encode_flag_val for name, val in data: if isinstance(val, list): cli.out("%s:" % name) for item in val: cli.out(" - %s" % encode_val(item)) elif isinstance(val, dict): cli.out("%s:" % name) for item_name, item_val in _sort_run_info_attr(name, val): if isinstance(item_val, list): cli.out(" %s:" % item_name) for item_item in item_val: cli.out(" - %s" % encode_val(item_item)) elif isinstance(item_val, dict): cli.out(" %s:" % item_name) # Use full YAML formatting for config blocks. cli.out(_indent(util.encode_yaml(item_val), 4)) else: cli.out(" %s: %s" % (item_name, encode_val(item_val))) else: cli.out("%s: %s" % (name, val))
def _encode_attr_val(val): return util.encode_yaml(val)
def _assigns_flag_data_desc(data, indent=2): desc = util.encode_yaml(data) return _indent(desc, indent)
def _write_config(config, path): with open(path, "w") as f: f.write(util.encode_yaml(config))
def _encode_str(s): return _quote_float(util.encode_yaml(s))