Read configuration file, perform sanity check and return configuration
        dictionary used by other functions.
188005
def read_config(config_file=CONFIG_FILE_DEFAULT, override_url=None):
    ''' '''
    config = ConfigParser()
    config.read_dict(DEFAULT_SETTINGS)

    try:
        config.readfp(open(config_file))
        logger.debug("Using config file at " + config_file)
    except:
        logger.error(
            "Could not find {0}, running with defaults.".format(config_file))

    if not logger.handlers:
        # Before doing anything else, configure logging
        # Handlers might be already registered in repeated test suite runs
        # In production, this should never happen
        if config.getboolean("Logging", "to_file"):
            handler = logging.FileHandler(config.get("Logging", "file"))
        else:
            handler = logging.StreamHandler()
        handler.setFormatter(logging.Formatter(
            config.get("Logging", "format")))
        logger.addHandler(handler)
    logger.setLevel(config.get("Logging", "level"))

    if override_url:
        config['Server']['url'] = override_url

    return config
1248865
def read_file(self, file_path):
        '''  '''
        getLogger().info("Loading app config from {} file: {}".format(self.__mode, file_path))
        if self.__mode == AppConfig.JSON:
            return json.loads(FileHelper.read(file_path), object_pairs_hook=OrderedDict)
        elif self.__mode == AppConfig.INI:
            config = configparser.ConfigParser(allow_no_value=True)
            config.read(file_path)
            return config
1155853
def read_settings(filename=None, defs=None):
    
    # READ SETTINGS
    defs = listwrap(defs)
    defs.append({
        "name": ["--config", "--settings", "--settings-file", "--settings_file"],
        "help": "path to JSON file with settings",
        "type": str,
        "dest": "filename",
        "default": None,
        "required": False
    })
    args = argparse(defs)

    args.filename = coalesce(filename, args.filename, "./config.json")
    settings_file = File(args.filename)
    if not settings_file.exists:
        Log.error("Can not read configuration file {{filename}}", {
            "filename": settings_file.abspath
        })
    settings = mo_json_config.get_file(settings_file)
    settings.args = args
    return settings
140973
def configurations(self):
        """"""

        if self._confs is not None:
            return self._confs

        with output_capturing():
            module = self.load(self.fpath)
            confs = getattr(module, CONFIGS_MODULE_ATTR)
            confs = listify(confs)

        self._confs = confs

        return confs
662417
def get_config():
    
    config_path = find_config_file()
    if not config_path:
        return CONFIG_NOT_FOUND, None

    try:
        config_data = read_config_file(config_path)
    except Exception as error:
        return CONFIG_NOT_VALID, error

    return CONFIG_VALID, config_data
372683
def check_config(filename):
    
    conf = configparser.SafeConfigParser(allow_no_value=False)
    conf.read(filename)
    try:
        server = conf.get('global', 'server')
    except configparser.NoSectionError:
        server = False
    except configparser.NoOptionError:
        server = False
    try:
        username = conf.get('auth', 'username')
    except configparser.NoSectionError:
        username = False
    except configparser.NoOptionError:
        username = False
    try:
        password = conf.get('auth', 'password')
    except configparser.NoSectionError:
        password = False
    except configparser.NoOptionError:
        password = False
    try:
        auto_update_soa = conf.get('global', 'soa_update')
    except configparser.NoSectionError:
        auto_update_soa = False
    except configparser.NoOptionError:
        auto_update_soa = False

    return server, username, password, auto_update_soa
701305
def config_read():
    """"""
    config_file = (u"{0}config.ini".format(CONFIG_DIR))
    if not os.path.isfile(config_file):
        config_make(config_file)
    config = configparser.ConfigParser(allow_no_value=True)
    try:
        config.read(config_file, encoding='utf-8')
    except IOError:
        print("Error reading config file: {}".format(config_file))
        sys.exit()
    # De-duplicate provider-list
    providers = config_prov(config)
    # Read credentials for listed providers
    (cred, to_remove) = config_cred(config, providers)
    # remove unsupported and credential-less providers
    for item in to_remove:
        providers.remove(item)
    return cred, providers
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
122094
def _read_file(file_name):
    
    with open(file_name) as config_file:
        data = json.load(config_file)
    return data
1368888
def read(self, filename):
        

        try:
            conf_file = open(filename, 'r')
            config = conf_file.read()
            config_keys = re.findall(r'\[.*\]', config)
            self.section_keys = [key[1:-1] for key in config_keys]
        except IOError as e:
            # Pass if file not found
            if e.errno != 2:
                raise

        return self.config_parser.read(filename)
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
580739
def read_config_file(filename)
      contents = ""
      File.open(filename, "r") { |f| contents = f.read() } if File.exists?(filename)
      contents
    end
757928
def _load_config_file(self):
        
        LOGGER.info('Loading configuration from %s', self._file_path)
        if self._file_path.endswith('json'):
            config = self._load_json_config()
        else:
            config = self._load_yaml_config()
        for key, value in [(k, v) for k, v in config.items()]:
            if key.title() != key:
                config[key.title()] = value
                del config[key]
        return flatdict.FlatDict(config)
282408
def load_configuration(self) -> None:
        
        config_file = self.default_config_file
        if self.config_file:
            config_file = self.config_file
        self.config = ConfigParser()
        self.config.read(config_file)
97210
def _read_configuration_file(self, path):
        
        parser = RawConfigParser(inline_comment_prefixes=('#', ';'))
        options = None
        should_inherit = True

        if parser.read(path) and self._get_section_name(parser):
            all_options = self._parser.option_list[:]
            for group in self._parser.option_groups:
                all_options.extend(group.option_list)

            option_list = {o.dest: o.type or o.action
                                for o in all_options}

            # First, read the default values
            new_options, _ = self._parse_args([])

            # Second, parse the configuration
            section_name = self._get_section_name(parser)
            for opt in parser.options(section_name):
                if opt == 'inherit':
                    should_inherit = parser.getboolean(section_name, opt)
                    continue

                if opt.replace('_', '-') not in self.CONFIG_FILE_OPTIONS:
                    log.warning("Unknown option '{}' ignored".format(opt))
                    continue

                normalized_opt = opt.replace('-', '_')
                opt_type = option_list[normalized_opt]
                if opt_type in ('int', 'count'):
                    value = parser.getint(section_name, opt)
                elif opt_type == 'string':
                    value = parser.get(section_name, opt)
                else:
                    assert opt_type in ('store_true', 'store_false')
                    value = parser.getboolean(section_name, opt)
                setattr(new_options, normalized_opt, value)

            # Third, fix the set-options
            options = self._fix_set_options(new_options)

        if options is not None:
            if not self._validate_options(options):
                raise IllegalConfiguration('in file: {}'.format(path))

        return options, should_inherit
703407
def _parse_conf(conf_file=default_conf):
    '''
    
    '''
    ret = {}
    with salt.utils.files.fopen(conf_file, 'r') as ifile:
        for line in ifile:
            line = salt.utils.stringutils.to_unicode(line).strip()
            if not line:
                continue
            if line.startswith('#'):
                continue
            splitline = line.split(' ', 1)
            ret[splitline[0]] = splitline[1]
    return ret
278169
def read_config(cls, configparser):
        """"""
        config = dict()
        config[cls._filename_re_key] = configparser.get(cls.__name__, cls._filename_re_key) \
            if configparser.has_option(cls.__name__, cls._filename_re_key) else None
        return config