Allow top_cfg to be YAML
763951
def _parse_top_cfg(content, filename):
    '''
    
    '''
    try:
        obj = salt.utils.yaml.safe_load(content)
        if isinstance(obj, list):
            log.debug('MakoStack cfg `%s` parsed as YAML', filename)
            return obj
    except Exception as err:
        pass
    log.debug('MakoStack cfg `%s` parsed as plain text', filename)
    return content.splitlines()
1011613
def _load_yaml_config(path=None):
    """"""
    countour_yaml_path = path or find_contour_yaml()

    if countour_yaml_path is None:
        logging.debug("countour.yaml not found.")
        return None

    with open(countour_yaml_path) as yaml_file:
        return yaml_file.read()
738249
def load_config_yaml(self, flags, config_dict):
        
        if config_dict is None:
            print('Config File not specified. Using only input flags.')
            return flags
        try:
            config_yaml_dict = self.cfg_from_file(flags['YAML_FILE'], config_dict)
        except KeyError:
            print('Yaml File not specified. Using only input flags and config file.')
            return config_dict
        print('Using input flags, config file, and yaml file.')
        config_yaml_flags_dict = self._merge_a_into_b_simple(flags, config_yaml_dict)
        return config_yaml_flags_dict
1373501
def top(**kwargs):
    '''
    
    '''

    conf = __opts__['master_tops']['varstack']
    __grains__ = kwargs['grains']

    vs_ = varstack.Varstack(config_filename=conf)
    ret = vs_.evaluate(__grains__)
    return {'base': ret['states']}
630002
def load_yaml_file(file_path: str):
    """"""
    with codecs.open(file_path, 'r') as f:
        return yaml.safe_load(f)
427569
def slugify(scheme_file):
    """"""
    scheme_file_name = os.path.basename(scheme_file)
    if scheme_file_name.endswith('.yaml'):
        scheme_file_name = scheme_file_name[:-5]
    return scheme_file_name.lower().replace(' ', '-')
104883
def parse_yaml_config(args):
    """"""
    try:
        import yaml
    except ImportError:
        yaml = None

    yml = {}
    try:
        with open(args.coveralls_yaml, 'r') as fp:
            if not yaml:
                raise SystemExit('PyYAML is required for parsing configuration')
            yml = yaml.load(fp)
    except IOError:
        pass
    yml = yml or {}
    return yml
396999
def from_yaml(cls, path):
        """"""
        import yaml

        with path.open(mode='r') as fp:
            source = yaml.safe_load(fp) or {}
            self = cls.from_jsonld(
                source,
                __reference__=path,
                __source__=deepcopy(source),
            )

        return self
1249093
def include_yaml(self, node):
        '''
        
        '''
        filename = self.construct_scalar(node)
        if not filename.startswith('/'):
            if self._root is None:
                raise Exception('!include_yaml %s is a relative path, '
                                'but stream lacks path' % filename)
            filename = os.path.join(self._root, self.construct_scalar(node))
        with self.open(filename, 'r') as fin:
            return yaml.load(fin, Loader)
991935
def from_yaml(cls, path):
        """"""
        import yaml

        with path.open(mode='r') as fp:
            self = cls.from_cwl(yaml.safe_load(fp), __reference__=path)

        return self
170187
def main():
    """"""
    parser = argparse.ArgumentParser(description='Compose a yaml file.')
    parser.add_argument(
        'root',
        type=argparse.FileType('r'),
        help='The root yaml file to compose.'
    )

    args = parser.parse_args()

    result = yaml.load(args.root, Loader=ComposeLoader)

    print(yaml.dump(result))
975048
def build_from_yamlstr(cls, yamlstr):
        
        top_dict = yaml.safe_load(yamlstr)
        coordsys = top_dict.pop('coordsys')
        output_list = []
        for e_key, e_dict in sorted(top_dict.items()):
            if e_key == 'coordsys':
                continue
            e_dict = top_dict[e_key]
            e_dict['coordsys'] = coordsys
            output_list += cls.build_from_energy_dict(e_key, e_dict)
        return output_list
465686
def load_yaml(fname):
    """"""
    yaml = YAML(typ="safe")
    # Compat with HASS
    yaml.allow_duplicate_keys = True
    # Stub HASS constructors
    HassSafeConstructor.name = fname
    yaml.Constructor = HassSafeConstructor

    with open(fname, encoding="utf-8") as conf_file:
        # If configuration file is empty YAML returns None
        # We convert that to an empty dict
        return yaml.load(conf_file) or {}
184858
def to_yaml(opts = {}) #:nodoc:
        if YAML.const_defined?(:ENGINE) && !YAML::ENGINE.syck?
          super
        else
          coder = {}
          encode_with(coder)
          YAML.quick_emit(self, opts) do |out|
            out.map(taguri, to_yaml_style) do |map|
              coder.each { |k, v| map.add(k, v) }
            end
          end
        end
      end
1086081
def __init_yaml():
    """"""
    global _yaml_initialized
    if not _yaml_initialized:
        _yaml_initialized = True
        yaml.add_constructor(u'tag:yaml.org,2002:Frame', _frame_constructor)
        yaml.add_constructor(u'tag:yaml.org,2002:Signal', _signal_constructor)
        yaml.add_representer(canmatrix.Frame, _frame_representer)
267418
def to_yaml
      require 'yaml'
      trackers_export = @trackers.reduce({}) do |export, tracker|
        export[tracker.title] = tracker.to_yaml_object; export
      end
      YAML.dump(trackers_export)
    end
323264
def cli(ctx, setkv, copyk, delk,showtype):
    """"""

    if not ctx.bubble:
        ctx.say_yellow(
            'There is no bubble present, will not show or set the config')
        raise click.Abort()

    new_cfg = flat(ctx, ctx.cfg)
    ctx.say('current config', stuff=ctx.cfg, verbosity=10)
    ctx.say('current flat config with meta', stuff=new_cfg, verbosity=100)
    new_cfg_no_meta = {}
    meta_ends = ['_doct_as_key',
                 '_doct_level',
                 '___bts_flat_',
                 '___bts_flat_star_path_',
                 '___bts_flat_star_select_']

    lkeys = list(new_cfg.keys())
    for k in lkeys:
        addkey = True
        # ctx.say('k:'+k)
        if k.startswith('___bts_'):
            addkey = False
        for meta_end in meta_ends:
            if k.endswith(meta_end):
                addkey = False
        if addkey:
            # ctx.say('adding k:'+k)
            new_cfg_no_meta[k] = new_cfg[k]
        else:
            pass
            # ctx.say('not adding meta k:'+k)
    ctx.say('current flat config without metakeys',
            stuff=new_cfg_no_meta,
            verbosity=3)
    if not setkv and not copyk and not delk:
        ctx.say('current configuration')
        for k, v in new_cfg_no_meta.items():
            tstr=''
            if showtype:
                tstr=' type: '+TYPES[str(type(v))]
            ctx.say(' '+k+': '+str(v)+tstr)

    modified = 0
    if setkv:
        for key, value,vtype in setkv:
            ctx.say('setting k:%s,v:%s,t:%s'%(key,value,vtype))
            vtval='VALUE_NOT_SET'
            try:
                if vtype=="STRING":
                    vtval=str(value)
                if vtype=="INTEGER":
                    vtval=int(value)
                if vtype=="FLOAT":
                    vtval=float(value)
                if vtype=="BOOLEAN":
                    if value.lower() in TRUES:
                        vtval=True
                    if value.lower() in FALSES:
                        vtval=False
                    if vtval not in [True,False]:
                        ctx.cry("boolean value must be one of (case insensitive):",
                                stuff={'True':TRUES,'False':FALSES})
                        raise TypeError()
            except Exception as e:
                ctx.cry('cannot set k:%s,v:%s,t:%s:'%(key,value,vtype))
                raise e
            if vtval != 'VALUE_NOT_SET':
                new_cfg[str(key)] = vtval
                modified += 1
            else:
                ctx.cry('cannot set k:%s,v:%s,t:%s:typed value is not set yet'%(key,value,vtype))
    if copyk:
        for srckey, destkey in copyk:
            if srckey.endswith('.*'):
                src_val = get_flat_path(ctx, new_cfg, srckey)
                for k in src_val:
                    # TODO: use magic for sep
                    sep = '.'
                    new_cfg[str(destkey + sep + k)] = str(src_val[k])
                modified += 1
            else:
                if srckey in new_cfg:
                    new_cfg[str(destkey)] = new_cfg[srckey]
                    modified += 1

    if delk:
        if delk.endswith('.*'):
            # fix PY3: RuntimeError: dictionary changed size during iteration
            lkeys = list(new_cfg.keys())
            for k in lkeys:
                if k.startswith(delk[:-2]):
                    del(new_cfg[k])
                    modified += 1

        else:
            if delk in new_cfg:
                del(new_cfg[delk])
                modified += 1

    if modified:
        ctx.say('new flat config', stuff=new_cfg, verbosity=100)
        fat_cfg = unflat(ctx, new_cfg)
        ctx.say('new config, #changes:'+str(modified), verbosity=3)
        ctx.say('new config', stuff=fat_cfg, verbosity=30)
        fat_cfg = unflat(ctx, new_cfg)
        doct_fat_cfg = BubbleDoct(fat_cfg)
        ctx.say('new config fat doct', stuff=doct_fat_cfg, verbosity=100)
        res = put_config(ctx, YCFG=BubbleDoct(doct_fat_cfg))
        ctx.say('put config res:', stuff=res, verbosity=10)

    return True