예제 #1
0
파일: publish.py 프로젝트: hkennyv/guildai
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: yaml_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"]))
예제 #2
0
 def write_attr(self, name, val, raw=False):
     if not raw:
         val = yaml_util.encode_yaml(val)
     with open(self._attr_path(name), "w") as f:
         f.write(val)
         f.write(os.linesep)
         f.close()
예제 #3
0
def _try_print_raw_run_attr(run, attr_name):
    try:
        val = run[attr_name]
    except KeyError:
        raise util.TryFailed()
    else:
        print(yaml_util.encode_yaml(val))
예제 #4
0
파일: op_cmd.py 프로젝트: hkennyv/guildai
def _encode_flag_arg_for_globals(val):
    """Returns an encoded flag value for Python globals interface.

    Flags destined for globals within a Python module are encoded
    using standard YAML encoding. Decoding must be handled using
    standard YAML decoding.
    """
    return yaml_util.encode_yaml(val, default_flow_style=True)
예제 #5
0
def _flagdef_choices(flagdef):
    if flagdef.choices:
        from guild import yaml_util

        return [yaml_util.encode_yaml(c.value) for c in flagdef.choices]
    elif flagdef.type == "boolean":
        return ["true", "false"]
    else:
        return []
예제 #6
0
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 yaml_util.encode_yaml(val, default_flow_style=True)
예제 #7
0
def _print_run_info_dict(name, val):
    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" % flag_util.encode_flag_val(item_item))
        elif isinstance(item_val, dict):
            cli.out("  %s:" % item_name)
            # Use full YAML formatting for config blocks.
            cli.out(_indent(yaml_util.encode_yaml(item_val), 4))
        else:
            cli.out("  %s: %s" %
                    (item_name, flag_util.encode_flag_val(item_val)))
예제 #8
0
파일: op_cmd.py 프로젝트: hkennyv/guildai
def _encode_yaml_list_for_globals_arg(parts):
    return yaml_util.encode_yaml(
        [yaml_util.decode_yaml(part) for part in parts],
        default_flow_style=True,
    )
예제 #9
0
def _assigns_flag_data_desc(data, indent=2):
    desc = yaml_util.encode_yaml(data)
    return _indent(desc, indent)
예제 #10
0
파일: util.py 프로젝트: hkennyv/guildai
def _resolved_part_str(part):
    if isinstance(part, six.string_types):
        return part
    from guild import yaml_util  # expensive

    return yaml_util.encode_yaml(part)
예제 #11
0
def _encode_splittable_list(l):
    return " ".join([util.shlex_quote(yaml_util.encode_yaml(x)) for x in l])