Load config from the associated .ini file
482629
def load_from_ini(self):
        
        try:
            if PY2:
                # Python 2
                fname = self.filename()
                if osp.isfile(fname):
                    try:
                        with codecs.open(fname, encoding='utf-8') as configfile:
                            self.readfp(configfile)
                    except IOError:
                        print("Failed reading file", fname)  # spyder: test-skip
            else:
                # Python 3
                self.read(self.filename(), encoding='utf-8')
        except cp.MissingSectionHeaderError:
            print("Warning: File contains no section headers.")
1268572
def load_yaml_config(self, conf):
        """"""
        with open(conf) as fd:
            self.config = recursive_dict_update(self.config, yaml.load(fd, Loader=UnsafeLoader))
157006
def load_config(cls, configfile="logging.yaml"):
        
        configfile = getenv(cls.CONFIGFILE_ENV_KEY, configfile)
        if isfile(configfile):
            with open(configfile, "r") as cf:
                # noinspection PyBroadException
                try:
                    dictConfig(load(cf))
                except ValueError:
                    debug("Learn to config foooo! Improper config at %s", configfile)
                except Exception:
                    exception("Something went wrong while reading %s.", configfile)
        else:
            raise ValueError("Invalid configfile specified: {}".format(configfile))
1059270
def get_config():
  """"""
  # TODO(hanuszczak): See comment in `setup.py` for `grr-response-proto`.
  ini_path = os.path.join(THIS_DIRECTORY, "version.ini")
  if not os.path.exists(ini_path):
    ini_path = os.path.join(THIS_DIRECTORY, "../../version.ini")
    if not os.path.exists(ini_path):
      raise RuntimeError("Couldn't find version.ini")

  config = configparser.SafeConfigParser()
  config.read(ini_path)
  return config
187733
def _load_config(initial_namespace=None, defaults=None):
    # type: (Optional[str], Optional[str]) -> ConfigLoader
    
    # load defaults
    if defaults:
        config = ConfigLoader()
        config.update_from_object(defaults)

    namespace = getattr(config, 'CONFIG_NAMESPACE', initial_namespace)
    app_config = getattr(config, 'APP_CONFIG', None)

    # load customised config
    if app_config:
        if namespace is None:
            config.update_from_object(app_config)
        else:
            _temp = ConfigLoader()
            _temp.update_from_object(app_config, lambda key: key.startswith(namespace))
            config.update(_temp.namespace(namespace))

    return config
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
1154607
def load_env():
    """"""
    # environment variables take precedence over conf file
    for key, envvar in [['cache_dir', 'INTAKE_CACHE_DIR'],
                        ['catalog_path', 'INTAKE_PATH'],
                        ['persist_path', 'INTAKE_PERSIST_PATH']]:
        if envvar in os.environ:
            conf[key] = make_path_posix(os.environ[envvar])
    conf['catalog_path'] = intake_path_dirs(conf['catalog_path'])
    for key, envvar in [['cache_disabled', 'INTAKE_DISABLE_CACHING'],
                        ['cache_download_progress', 'INTAKE_CACHE_PROGRESS']]:
        if envvar in os.environ:
            conf[key] = os.environ[envvar].lower() in ['true', 't', 'y', 'yes']
    if 'INTAKE_LOG_LEVEL' in os.environ:
        conf['logging'] = os.environ['INTAKE_LOG_LEVEL']
1259136
def load_configuration(self):
        """"""
        filename = os.path.join(os.path.dirname(__file__), 'templates/spline-loc.yml.j2')
        with open(filename) as handle:
            return Adapter(safe_load(handle)).configuration
343877
def _load_from_ini_py3(ini, default_section=_DEFAULT_SECTION):
    

    cf = configparser.ConfigParser(default_section=default_section)
    cf.read(ini, encoding="UTF8")
    settings = OrderedDict()
    for item in cf.items():
        logger.debug(item[0])
        settings[item[0].upper()] = OrderedDict(item[1])

    logger.debug(settings)
    for k, v in cf.items(default_section):
    # for k, v in cf.items():
        logger.debug(v)
        logger.debug(settings)
        logger.debug(settings.get(k))
        settings[k.upper()] = convert_value(v)
        logger.debug(settings)
        if k.lower() in settings:
            del settings[k.lower()]

    if default_section in settings:
        del settings[default_section]

    logger.debug(settings)
    return settings
1197072
def _load_values(self):
        """"""
        path = self._config_path()
        if path is not None and os.path.isfile(path):
            self._load_file(path)
869490
def _load_config_file(self):
        """"""
        with open(self._config_file) as f:
            config = yaml.safe_load(f)
            patch_config(config, self.__environment_configuration)
            return config
723776
def from_ini(cls, ic, folder='.', ini_file='star.ini'):
        
        if not os.path.isabs(ini_file):
            ini_file = os.path.join(folder,ini_file)

        config = ConfigObj(ini_file)
        kwargs = {}
        for kw in config.keys():
            try:
                kwargs[kw] = float(config[kw])
            except:
                kwargs[kw] = (float(config[kw][0]), float(config[kw][1]))

        return cls(ic, **kwargs)
1065104
def init():
    ''''''
    # Load values from config file
    config_file = os.path.realpath(os.path.join(os.getcwd(), 'swaggery.ini'))
    config = configparser.RawConfigParser(allow_no_value=True)
    config.read(config_file)
    log_level = config.get('application', 'logging_level').upper()
    api_dirs = list(config['apis'])
    do_checks = config.get('application',
                           'disable_boot_checks').lower() == 'false'
    # Set logging level
    log.setLevel(getattr(logging, log_level))
    log.debug('Log level set to {}'.format(log_level))
    # Bootstrap application
    log.debug('Exploring directories: {}'.format(api_dirs))
    application = Swaggery(api_dirs=api_dirs, do_checks=do_checks)
    return application
271857
def load_ini(self, ini_file):
        
        if ini_file and not os.path.exists(ini_file):
            self.log.critical(f"Settings file specified but not found. {ini_file}")
            sys.exit(1)
        if not ini_file:
            ini_file = f"{self.cwd}/settings.ini"
        if os.path.exists(ini_file):
            config = configparser.RawConfigParser(allow_no_value=True)
            config.read(ini_file)
            for key, value in self.spec.items():
                entry = None
                if value['type'] == str:
                    entry = config.get("settings", option=key.lower(), fallback=None)
                elif value['type'] == bool:
                    entry = config.getboolean("settings", option=key.lower(), fallback=None)
                elif value['type'] == int:
                    entry = config.getint("settings", option=key.lower(), fallback=None)
                elif value['type'] == float:
                    entry = config.getfloat("settings", option=key.lower(), fallback=None)
                elif value['type'] in [list, dict]:
                    entries = config.get("settings", option=key.lower(), fallback=None)
                    if entries:
                        try:
                            entry = json.loads(entries)
                        except json.decoder.JSONDecodeError as _err:  #pragma: no cover
                            self.log.critical(f"Error parsing json from ini file. {entries}")
                            sys.exit(1)
                if entry is not None:
                    setattr(self, key.upper(), entry)
174545
def convert_ini(config_dict):
    
    config_lines = []

    for env, configs in sorted(config_dict.items()):
        for resource, app_properties in sorted(configs.items()):
            try:
                for app_property, value in sorted(app_properties.items()):
                    variable = '{env}_{resource}_{app_property}'.format(
                        env=env, resource=resource, app_property=app_property).upper()

                    if isinstance(value, (dict, DeepChainMap)):
                        safe_value = "'{0}'".format(json.dumps(dict(value)))
                    else:
                        safe_value = json.dumps(value)

                    line = "{variable}={value}".format(variable=variable, value=safe_value)

                    LOG.debug('INI line: %s', line)
                    config_lines.append(line)
            except AttributeError:
                resource = resource.upper()
                app_properties = "'{}'".format(json.dumps(app_properties))
                line = '{0}={1}'.format(resource, app_properties)

                LOG.debug('INI line: %s', line)
                config_lines.append(line)
    return config_lines
1155317
def _load_config(self):
        ""
        
        config = SafeConfigParser()
        config_file = os.path.join(self.config_path, 'settings.ini')
        config.read(config_file)

        for option, type in list(AVAILABLE_OPTIONS.items()):
            if config.has_option('DEFAULT', option):
                if type == 'int':
                    value = config.getint('DEFAULT', option)
                if type == 'float':
                    value = config.getfloat('DEFAULT', option)
                if type == 'bool':
                    value = config.getboolean('DEFAULT', option)
                if type == 'str':
                    value = config.get('DEFAULT', option)

                self.livestreamer.set_option(option, value)
623834
def load_config(force_default=False):
    '''
    '''
    def _load(cdir, recurse=False):
      confl = os.path.join(cdir, CONFIG_FNAME)
      try:
        with open(confl, 'r') as fp:
          conf = yaml.safe_load(fp)
          if type(conf) is not dict:
            raise InvalidConfiguration('Configuration at %s is not a dictionary.' % confl)
          return conf
      except EnvironmentError:
        parent = os.path.dirname(cdir)
        if recurse and parent != cdir:
          return _load(parent, recurse=True)
        else:
          return dict()
      except yaml.YAMLError:
        raise InvalidConfiguration('Configuration at %s is an invalid YAML file.' % confl)

    def _update(prev, next):
      for k, v in next.items():
        if isinstance(v, dict):
          prev[k] = _update(prev.get(k, {}), v)
        else:
          prev[k] = v
      return prev

    conf = _load(os.path.dirname(__file__))

    if not force_default:
      home_conf = _load(os.path.expanduser('~'))
      local_conf = _load(os.path.abspath(os.curdir), recurse=True)

      _update(conf, home_conf)
      _update(conf, local_conf)
    return conf