Dump a yaml file containing client info.
776633
def DumpClientYaml(client_urn, target_dir, token=None, overwrite=False):
  """"""
  fd = aff4.FACTORY.Open(client_urn, aff4_grr.VFSGRRClient, token=token)
  dirpath = os.path.join(target_dir, fd.urn.Split()[0])
  try:
    # Due to threading this can actually be created by another thread.
    os.makedirs(dirpath)
  except OSError:
    pass
  filepath = os.path.join(dirpath, "client_info.yaml")
  if not os.path.isfile(filepath) or overwrite:
    with open(filepath, "wb") as out_file:
      out_file.write(serialize.YamlDumper(fd))
83134
def get_json_or_yaml(file_path, content):
    
    if os.path.splitext(file_path)[1] == ".json":
        return json.dumps(content, sort_keys=False, indent=4, separators=(',', ': '))
    else:
        return inginious.common.custom_yaml.dump(content)
955659
def dump(config):
    

    return yaml.safe_dump(
        config.to_primitive(),
        default_flow_style=False,
        encoding='utf-8',
        allow_unicode=True)
101078
def dump_yaml(testcase, yaml_file):
    
    logging.info("dump testcase to YAML format.")

    with io.open(yaml_file, 'w', encoding="utf-8") as outfile:
        yaml.dump(testcase, outfile, allow_unicode=True, default_flow_style=False, indent=4)

    logging.info("Generate YAML testcase successfully: {}".format(yaml_file))
143044
def safe_dump(data, stream=None, **kwds):
    """"""
    return yaml.dump(data, stream=stream, Dumper=ODYD, **kwds)
61588
def dump_engines(target=sys.stderr):
    """"""
    print("Available templating engines:", file=target)

    width = max(len(engine) for engine in engines.engines)
    for handle, engine in sorted(engines.engines.items()):
        description = engine.__doc__.split('\n', 0)[0]
        print("  %-*s  -  %s" % (width, handle, description), file=target)
803084
def generate_write_yaml_to_file(file_name):
    
    def write_yaml(config):
        with open(file_name, 'w+') as fh:
            fh.write(yaml.dump(config))
    return write_yaml
584943
def dump(filename, options, out=sys.stdout):
    """"""
    with open(filename, 'rb') as file_obj:
        return _dump(file_obj, options=options, out=out)
200573
def to_yaml(template, clean_up=False, long_form=False):
    

    data = load_json(template)

    if clean_up:
        data = clean(data)

    return dump_yaml(data, clean_up, long_form)
655182
def yaml_dump(dict_to_dump):
    
    yaml.SafeDumper.add_representer(OrderedDict, _dict_representer)
    return yaml.safe_dump(dict_to_dump, default_flow_style=False)
896854
def read_yaml(self, filename):
        '''
        
        '''
        with open(filename, 'r') as f:
            d = re.sub(r'\{\{ *([^ ]+) *\}\}', r'\1', f.read())
            y = yaml.safe_load(d)
            return y if y else {}
797039
def yaml_dump_hook(cfg, text: bool=False):
    

    data = cfg.config.dump()
    if not text:
        yaml.dump(data, cfg.fd, Dumper=cfg.dumper, default_flow_style=False)
    else:
        return yaml.dump(data, Dumper=cfg.dumper, default_flow_style=False)
22454
def cli(yamlfile, format, output, context):
    
    print(RDFGenerator(yamlfile, format).serialize(output=output, context=context))
580893
def write_yaml(data, out_path, Dumper=yaml.Dumper, **kwds):
    ''''''
    import errno
    import os

    class OrderedDumper(Dumper):
        pass
    def _dict_representer(dumper, data):
        return dumper.represent_mapping(
            yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG,
            data.items())

    OrderedDumper.add_representer(OrderedDict, _dict_representer)

    # Make directory for calibration file if does not exist
    base_path, file_name = os.path.split(out_path)
    try:
        os.makedirs(base_path)
    except OSError as exc: # Python >2.5
        if exc.errno == errno.EEXIST and os.path.isdir(base_path):
            pass
        else: raise

    # Write dictionary to YAML
    with open(out_path, 'w') as f:
        return yaml.dump(data, f, OrderedDumper, default_flow_style=False, **kwds)
871596
def cfgdump(path, config):
    """"""
    dump = yaml_dump(config)
    if not os.path.exists(path):
        os.makedirs(path)
    with open(os.path.join(path, 'config.yaml'), 'w') as outf:
        outf.write(dump)
    print(dump)
696046
def Dump(obj):
  
  text = yaml.safe_dump(obj, default_flow_style=False, allow_unicode=True)

  if compatibility.PY2:
    text = text.decode("utf-8")

  return text
1191378
def generate_yaml_file(filename, contents):
    """"""
    with open(filename, 'w') as file:
        file.write(yaml.dump(contents, default_flow_style=False))