Read a config file and pull out the value of a given keyword.
550975
def getEmbeddedKeyVal(cfgFileName, kwdName, dflt=None):
    
    # Assume this is a ConfigObj file.  Use that s/w to quickly read it and
    # put it in dict format.  Assume kwd is at top level (not in a section).
    # The input may also be a .cfgspc file.
    #
    # Only use ConfigObj here as a tool to generate a dict from a file - do
    # not use the returned object as a ConfigObj per se.  As such, we can call
    # with "simple" format, ie. no cfgspc, no val'n, and "list_values"=False.
    try:
        junkObj = configobj.ConfigObj(cfgFileName, list_values=False)
    except:
        if kwdName == TASK_NAME_KEY:
            raise KeyError('Can not parse as a parameter config file: '+ \
                           '\n\t'+os.path.realpath(cfgFileName))
        else:
            raise KeyError('Unfound key "'+kwdName+'" while parsing: '+ \
                           '\n\t'+os.path.realpath(cfgFileName))

    if kwdName in junkObj:
        retval = junkObj[kwdName]
        del junkObj
        return retval
    # Not found
    if dflt is not None:
        del junkObj
        return dflt
    else:
        if kwdName == TASK_NAME_KEY:
            raise KeyError('Can not parse as a parameter config file: '+ \
                           '\n\t'+os.path.realpath(cfgFileName))
        else:
            raise KeyError('Unfound key "'+kwdName+'" while parsing: '+ \
                           '\n\t'+os.path.realpath(cfgFileName))
883117
def config_from_file(self, config_file=None):
        """"""
        if PYLINT_VERSION >= (1, 5):
            self.read_config_file(config_file)
            if self.cfgfile_parser.has_option('MASTER', 'load-plugins'):
                # pylint: disable=protected-access
                plugins = _splitstrip(self.cfgfile_parser.get('MASTER', 'load-plugins'))
                self.load_plugin_modules(plugins)
            self.load_config_file()
            return True

        self.load_file_configuration(config_file)
        return False
862852
def read_config(self, path):
        """"""
        self.pyvlx.logger.info('Reading config file: ', path)
        try:
            with open(path, 'r') as filehandle:
                doc = yaml.load(filehandle)
                if 'config' not in doc:
                    raise PyVLXException('no element config found in: {0}'.format(path))
                if 'host' not in doc['config']:
                    raise PyVLXException('no element host found in: {0}'.format(path))
                if 'password' not in doc['config']:
                    raise PyVLXException('no element password found in: {0}'.format(path))
                self.host = doc['config']['host']
                self.password = doc['config']['password']
        except FileNotFoundError as ex:
            raise PyVLXException('file does not exist: {0}'.format(ex))
607708
def _load_config(configfile, section=None):
    '''
    '''
    if os.path.exists(configfile):
        config = read_config(configfile)
        if section is not None:
            if section in config:
                return config._sections[section]
            else:
                bot.warning('%s not found in %s' %(section, configfile))
        return config
1174839
def read_config_files(files):
    """"""

    config = ConfigObj()

    for _file in files:
        _config = read_config_file(_file)
        if bool(_config) is True:
            config.merge(_config)
            config.filename = _config.filename

    return config
569786
def parser(input_file_path='config.json'):
    '''
    
    '''

    # --- Read .json file
    try:
        with open(input_file_path, 'r') as config_file:
            config_new = json.load(config_file)
            config_file.close()
    except:
        raise Exception('Config file "'+input_file_path+'" not loaded properly. Please check it an try again.')

    import copy
    options = update_config(config_new, copy.deepcopy(default_config))

    return options
185469
def from_file(cls, config_path=None, *args, **kwargs):
        

        config_reader = kaptan.Kaptan()

        config = {}

        if config_path:
            if not os.path.exists(config_path):
                raise exc.CihaiException(
                    '{0} does not exist.'.format(os.path.abspath(config_path))
                )
            if not any(
                config_path.endswith(ext) for ext in ('json', 'yml', 'yaml', 'ini')
            ):
                raise exc.CihaiException(
                    '{0} does not have a yaml,yml,json,ini extend.'.format(
                        os.path.abspath(config_path)
                    )
                )
            else:
                custom_config = config_reader.import_config(config_path).get()
                config = merge_dict(config, custom_config)

        return cls(config)
1049957
def load_config_from_file(app, filepath):
    """"""
    try:
        app.config.from_pyfile(filepath)
        return True
    except IOError:
        # TODO: Can we print to sys.stderr in production? Should this go to
        # logs instead?
        print("Did not find settings file %s for additional settings, skipping it" % filepath, file=sys.stderr)
        return False
1254508
def read_config(desired_type: Type[ConfigParser], file_object: TextIOBase,
                logger: Logger, *args, **kwargs) -> ConfigParser:
    

    # see https://docs.python.org/3/library/configparser.html for details
    config = ConfigParser()
    config.read_file(file_object)

    return config
433805
def _config_stream(filename):
    
    if filename is None or filename == '-':
        log.info('Reading config from stdin')
        yield sys.stdin
    else:
        with open(filename, mode='rt') as handle:
            log.info('Reading config from %r', filename)
            yield handle
754372
def inspect(config_file, profile):
    """"""

    try:
        section = load_profile_from_files(
            [config_file] if config_file else None, profile)

        click.echo("Configuration file: {}".format(config_file if config_file else "auto-detected"))
        click.echo("Profile: {}".format(profile if profile else "auto-detected"))
        click.echo("---")
        for key, val in section.items():
            click.echo("{} = {}".format(key, val))

    except (ValueError, ConfigFileReadError, ConfigFileParseError) as e:
        click.echo(e)
1323884
def parse_config(path):
        """"""
        config = configparser.ConfigParser()

        if path:  # if user has config with user creds in it, this will grab it
            config.read(path)

        try:
            return {k: v for k, v in config["default"].items()}
        except KeyError:
            return {}
909744
def read_config(file_name):
    """"""

    config = {}
    for name in (['.pyspelling.yml', '.spelling.yml'] if not file_name else [file_name]):
        if os.path.exists(name):
            if not file_name and name == '.spelling.yml':
                warn_deprecated(
                    "Using '.spelling.yml' as the default is deprecated. Default config is now '.pyspelling.yml'"
                )
            with codecs.open(name, 'r', encoding='utf-8') as f:
                config = yaml_load(f.read())
            break
    return config
735870
def read_file(self):
        

        # don't try to parse config file if we don't have one set
        if not self._cfg_path:
            return

        try:
            cfg_fp = open(self._cfg_path, 'r')
            self.readfp(cfg_fp)
        except IOError as exc:
            raise NipapConfigError(str(exc))
580739
def read_config_file(filename)
      contents = ""
      File.open(filename, "r") { |f| contents = f.read() } if File.exists?(filename)
      contents
    end
350626
def _getattr_ (self, name):
        """"""
        value = self._config.get(name)

        if type(value) is dict:
            value = AitConfig(self._filename, config=value)

        return value
983790
def get_config(config_file):
    
    config = {}
    tobool = lambda s: True if s.lower() == 'true' else False
    if config_file:
        try:
            f = open(config_file, 'r')
        except:
            print ("Unable to open configuration file '{0}'".format(config_file))
        else:
            for line in f.readlines():
                if len(line.strip()):
                    key, value = line.split("=", 1)
                    key, value = key.strip(), value.strip()
                    if key in ['init2class', 'first_line', 'convert_only']:
                        value = tobool(value)
                    config[key] = value
    return config