Returns configuration dict from parsing either the file described by
    ``path`` or the environment variable described by ``env_var`` as YAML.
519084
def load_config(path, env_var, default_path=None, exit_on_config_errors=True):
    '''
    
    '''
    if path is None:
        # When the passed path is None, we just want the configuration
        # defaults, not actually loading the whole configuration.
        return {}

    if default_path is None:
        # This is most likely not being used from salt, i.e., could be salt-cloud
        # or salt-api which have not yet migrated to the new default_path
        # argument. Let's issue a warning message that the environ vars won't
        # work.
        import inspect
        previous_frame = inspect.getframeinfo(inspect.currentframe().f_back)
        log.warning(
            "The function '%s()' defined in '%s' is not yet using the "
            "new 'default_path' argument to `salt.config.load_config()`. "
            "As such, the '%s' environment variable will be ignored",
            previous_frame.function, previous_frame.filename, env_var
        )
        # In this case, maintain old behavior
        default_path = DEFAULT_MASTER_OPTS['conf_file']

    # Default to the environment variable path, if it exists
    env_path = os.environ.get(env_var, path)
    if not env_path or not os.path.isfile(env_path):
        env_path = path
    # If non-default path from `-c`, use that over the env variable
    if path != default_path:
        env_path = path

    path = env_path

    # If the configuration file is missing, attempt to copy the template,
    # after removing the first header line.
    if not os.path.isfile(path):
        template = '{0}.template'.format(path)
        if os.path.isfile(template):
            log.debug('Writing %s based on %s', path, template)
            with salt.utils.files.fopen(path, 'w') as out:
                with salt.utils.files.fopen(template, 'r') as ifile:
                    ifile.readline()  # skip first line
                    out.write(ifile.read())

    opts = {}

    if salt.utils.validate.path.is_readable(path):
        try:
            opts = _read_conf_file(path)
            opts['conf_file'] = path
        except salt.exceptions.SaltConfigurationError as error:
            log.error(error)
            if exit_on_config_errors:
                sys.exit(salt.defaults.exitcodes.EX_GENERIC)
    else:
        log.debug('Missing configuration file: %s', path)

    return opts
1173676
def find_and_parse_config(config, default_config='default.yaml'):
    

    def load_config(path):
        if os.path.isfile(path):
            with open(path, 'r') as f:
                config_dict_ = yaml.load(f)
            return config_dict_

    config_path = find_file(config)
    default_path = find_file(default_config)
    config = load_config(config_path)
    default_config = load_config(default_path)
    if config is None and default_config is None:
        raise ValueError('Both config and default_config return None')
    if config is None:
        config_dict = default_config
    elif default_config is None:
        config_dict = config
    else:
        config_dict = merge(default_config, config)

    return config_dict
543073
def _read_conf_file(path):
    '''
    
    '''
    log.debug('Reading configuration from %s', path)
    with salt.utils.files.fopen(path, 'r') as conf_file:
        try:
            conf_opts = salt.utils.yaml.safe_load(conf_file) or {}
        except salt.utils.yaml.YAMLError as err:
            message = 'Error parsing configuration file: {0} - {1}'.format(path, err)
            log.error(message)
            raise salt.exceptions.SaltConfigurationError(message)

        # only interpret documents as a valid conf, not things like strings,
        # which might have been caused by invalid yaml syntax
        if not isinstance(conf_opts, dict):
            message = 'Error parsing configuration file: {0} - conf ' \
                      'should be a document, not {1}.'.format(path, type(conf_opts))
            log.error(message)
            raise salt.exceptions.SaltConfigurationError(message)

        # allow using numeric ids: convert int to string
        if 'id' in conf_opts:
            if not isinstance(conf_opts['id'], six.string_types):
                conf_opts['id'] = six.text_type(conf_opts['id'])
            else:
                conf_opts['id'] = salt.utils.data.decode(conf_opts['id'])
        return conf_opts
1374864
def get_config():
    """"""
    from os import environ
    from os.path import expanduser
    from pathlib import Path
    import yaml

    def pexp(p):
        try:
            return Path(p).expanduser()
        except AttributeError:
            # python 3.4
            return Path(expanduser(p))

    paths = [environ.get("METAPACK_CONFIG"), '~/.metapack.yaml', '/etc/metapack.yaml']

    for p in paths:

        if not p:
            continue

        p = pexp(p)

        if p.exists():
            with p.open() as f:
                config = yaml.safe_load(f)
                if not config:
                    config = {}

                config['_loaded_from'] = str(p)
                return config

    return None
351759
def _build_environ(self) -> Dict[str, Optional[str]]:
        
        d: Dict[str, Optional[str]] = {}

        if self.__config__.case_insensitive:
            env_vars = {k.lower(): v for k, v in os.environ.items()}
        else:
            env_vars = cast(Dict[str, str], os.environ)

        for field in self.__fields__.values():
            if field.has_alias:
                env_name = field.alias
            else:
                env_name = self.__config__.env_prefix + field.name.upper()

            env_name_ = env_name.lower() if self.__config__.case_insensitive else env_name
            env_val = env_vars.get(env_name_, None)

            if env_val:
                if field.is_complex():
                    try:
                        env_val = json.loads(env_val)
                    except ValueError as e:
                        raise SettingsError(f'error parsing JSON for "{env_name}"') from e
                d[field.alias] = env_val
        return d
881111
def parse_yaml(self, y):
        '''

        '''
        self.id = y['id']
        self._config_data = []
        if 'configurationData' in y:
            for d in y.get('configurationData'):
                self._config_data.append(ConfigurationData().parse_yaml(d))
        return self
1352714
def get_yaml_files_at_env_root(self):
        """"""
        yaml_files = glob.glob(
            os.path.join(self.env_root, '*.yaml')
        )
        yml_files = glob.glob(
            os.path.join(self.env_root, '*.yml')
        )
        return yaml_files + yml_files
481082
def get_config(config_file):
    """"""
    config_path = os.path.abspath(config_file)

    try:
        with open(config_path, 'r') as data:
            config = yaml.safe_load(data)
    except IOError as exc:
        sys.exit(str(exc))

    return config
617981
def parse_config_file(path: str, final: bool = True) -> None:
    
    return options.parse_config_file(path, final=final)
1010654
def load_environment_vars(self):
        
        for k, v in os.environ.items():
            if k.startswith(MACH9_PREFIX):
                _, config_key = k.split(MACH9_PREFIX, 1)
                self[config_key] = v
430615
def update_from_env(yaml_dict, prefix=None):
    '''
    
    '''
    prefix = prefix or ""

    def _set_env_var(path, node):
        env_path = "{0}{1}{2}".format(
            prefix.upper(),
            '_' if prefix else '',
            '_'.join([str(key).upper() for key in path])
        )
        env_val = os.environ.get(env_path, None)
        if env_val is not None:
            # convert the value to a YAML-defined type
            env_dict = yamldict.load('val: {0}'.format(env_val))
            return env_dict.val
        else:
            return None

    # traverse yaml_dict with the callback function
    yaml_dict.traverse(_set_env_var)
423470
def load_dict_from_yaml(path):
    
    f = file(path, 'r')
    dictionary = yaml.load(f)
    f.close()
    return dictionary
773746
def _load_config(self, path):
        
        try:
            with open(path) as f:
                values = yaml.safe_load(f)
                if isinstance(values, dict):
                    return values
                else:
                    raise yaml.YAMLError('Unable to parse/load {}'.format(path))
        except(IOError, yaml.YAMLError) as e:
            if self.ignore_errors:
                return None
            else:
                raise e
1307183
def GetParserFromFilename(self, path):
    """"""
    # Find the configuration parser.
    handler_name = path.split("://")[0]
    for parser_cls in itervalues(GRRConfigParser.classes):
      if parser_cls.name == handler_name:
        return parser_cls

    # Handle the filename.
    extension = os.path.splitext(path)[1]
    if extension in [".yaml", ".yml"]:
      return YamlParser

    return ConfigFileParser
1226266
def load_conf(yml_file, conf={}):
    
    with open(yml_file) as f:
        data = yaml.load(f)
        if conf:
            data.update(conf)
        return dictdot(data)
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
1188979
def from_envvar(self, variable_name):
        
        config_file = os.environ.get(variable_name)
        if not config_file:
            raise RuntimeError(
                "The environment variable %r is not set and "
                "thus configuration could not be loaded." % variable_name
            )
        return self.from_pyfile(config_file)