Attempt to load settings from various praw.ini files.
323923
def _load_configuration():
    """"""
    config = configparser.RawConfigParser()
    module_dir = os.path.dirname(sys.modules[__name__].__file__)
    if 'APPDATA' in os.environ:  # Windows
        os_config_path = os.environ['APPDATA']
    elif 'XDG_CONFIG_HOME' in os.environ:  # Modern Linux
        os_config_path = os.environ['XDG_CONFIG_HOME']
    elif 'HOME' in os.environ:  # Legacy Linux
        os_config_path = os.path.join(os.environ['HOME'], '.config')
    else:
        os_config_path = None
    locations = [os.path.join(module_dir, 'praw.ini'), 'praw.ini']
    if os_config_path is not None:
        locations.insert(1, os.path.join(os_config_path, 'praw.ini'))
    if not config.read(locations):
        raise Exception('Could not find config file in any of: {0}'
                        .format(locations))
    return config
779667
def load_preset(self):
        
        if 'preset' in self.settings.preview:
            with open(os.path.join(os.path.dirname(__file__), 'presets.yaml')) as f:
                presets = yaml.load(f.read())

            if self.settings.preview['preset'] in presets:
                self.preset = presets[self.settings.preview['preset']]
            return self.preset
1176075
def _load_config(self):
        
        if not os.path.exists(self._path):
            sys.exit("Config path %s does not exist" % self._path)
        # create empty config object
        self._config_dict = {}
        # read file and marshal yaml
        with open(self._path, 'r') as f:
            self._raw = f.read()
            self._config_dict = yaml.load(self._raw)
933261
def load_configuration(settings)
      configuration = settings.with_indifferent_access
      self.options = configuration[:options]
      self.clients = configuration[:clients]
      set_log_levels
    end
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
536954
def load(self):
    
    try:
      if not self.__in_memory:
        self._json = json.loads(self._load_from_configs(self._main_config))
        # ToDo: make this via extension for root logger
        # self._log = aLogger.getLogger(__name__, cfg=self)  # reload logger using loaded configuration
        self._load_modules()
      else:
        self._json = {}
      # parse command line, currently used for re-assign settings in configuration, but can't be used as replacement
      self._load_from_commandline()
    except Exception as err:
      self._json = None
      raise
123361
def get_settings():
    '''
    
    '''
    settings = {}
    for config_file in config_files():
        config_contents = load_config(config_file)
        if config_contents is not None:
            settings = deep_merge(settings, config_contents)
    return settings
566879
def load_config(self, settings=None):
        
        self._load_defaults()
        if settings:
            self.update(settings)
        else:
            config_paths = _get_config_files()
            for p in config_paths:
                conf = _process_config_file([p])
                self.update(conf)
        self._loaded = True
        self._validate()
15876
def set_api_from_config_path(self) -> None:
        """"""
        config = ConfigParser(allow_no_value=False)
        # TODO: Remove this after this issue https://github.com/python/mypy/issues/2427 is closed
        config.optionxform = str  # type:ignore
        config.read(self.config_path, "utf-8")
        if config.has_option("defaults", "dynamic_loading"):
            dynamic_loading = config.get("defaults", "dynamic_loading")
        else:
            dynamic_loading = "infura"
        self._set_rpc(dynamic_loading)
638930
def load(obj, settings_module, identifier="py", silent=False, key=None):
    """"""
    mod, loaded_from = get_module(obj, settings_module, silent)

    if mod and loaded_from:
        obj.logger.debug("py_loader: {}".format(mod))
    else:
        obj.logger.debug(
            "py_loader: %s (Ignoring, Not Found)", settings_module
        )
        return

    for setting in dir(mod):
        if setting.isupper():
            if key is None or key == setting:
                setting_value = getattr(mod, setting)
                obj.logger.debug(
                    "py_loader: loading %s: %s (%s)",
                    setting,
                    "*****" if "secret" in settings_module else setting_value,
                    identifier,
                )
                obj.set(setting, setting_value, loader_identifier=identifier)

    obj._loaded_files.append(mod.__file__)
635101
def process_settings(self, settings):
        """"""
        logging.debug("Using configuration from: %s", settings.name)
        exec(compile(settings.read(), settings.name, 'exec'), globals(), locals())
1347880
def handle_django_settings(filename):
    '''
    '''
    old_sys_path = sys.path[:]
    dirpath = os.path.dirname(filename)
    project = os.path.basename(dirpath)
    cwd = os.getcwd()
    project_path = os.path.normpath(os.path.join(dirpath, '..'))
    if project_path not in sys.path:
        sys.path.insert(0, project_path)
    os.chdir(project_path)

    project_settings = '{}.settings'.format(project)
    os.environ['DJANGO_SETTINGS_MODULE'] = project_settings

    try:
        import django
        # Sanity
        django.setup = lambda: False
    except ImportError:
        log.error('Found Django settings, but Django is not installed.')
        return

    log.warn('Loading Django Settings (Using {}): {}'
                    .format(django.get_version(), filename))

    from django.conf import LazySettings

    installed_apps = set()
    settings_imports = set()

    try:
        settings = LazySettings()
        settings._setup()
        for k, v in vars(settings._wrapped).items():
            if k not in _excluded_settings and re.match(r'^[A-Z_]+$', k):
                # log.debug('Scanning Django setting: %s', k)
                scan_django_settings(v, settings_imports)

        # Manually scan INSTALLED_APPS since the broad scan won't include
        # strings without a period in it .
        for app in getattr(settings, 'INSTALLED_APPS', []):
            if hasattr(app, '__file__') and getattr(app, '__file__'):
                imp, _ = utils.import_path_from_file(getattr(app, '__file__'))
                installed_apps.add(imp)
            else:
                installed_apps.add(app)
    except Exception as e:
        log.error('Could not load Django settings: %s', e)
        log.debug('', exc_info=True)
        return

    if not installed_apps or not settings_imports:
        log.error('Got empty settings values from Django settings.')

    try:
        from django.apps.registry import apps, Apps, AppRegistryNotReady
        # Django doesn't like it when the initial instance of `apps` is reused,
        # but it has to be populated before other instances can be created.
        if not apps.apps_ready:
            apps.populate(installed_apps)
        else:
            apps = Apps(installed_apps)

        start = time.time()
        while True:
            try:
                for app in apps.get_app_configs():
                    installed_apps.add(app.name)
            except AppRegistryNotReady:
                if time.time() - start > 10:
                    raise Exception('Bail out of waiting for Django')
                log.debug('Waiting for apps to load...')
                continue
            break
    except Exception as e:
        log.debug('Could not use AppConfig: {}'.format(e))

    # Restore before sub scans can occur
    sys.path[:] = old_sys_path
    os.chdir(cwd)

    for item in settings_imports:
        need_scan = item.startswith(_filescan_modules)
        yield ('django', item, project_path if need_scan else None)

    for app in installed_apps:
        need_scan = app.startswith(project)
        yield ('django', app, project_path if need_scan else None)
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
1013099
def load_settings(self, settings):
        """"""
        with open(settings) as settings_file:
            settings_dict = simplejson.load(settings_file)
        for key, value in settings_dict.items():
            self.__setattr__(key, value)
921315
def load_writer_configs(writer_configs, ppp_config_dir,
                        **writer_kwargs):
    """"""
    try:
        writer_info = read_writer_config(writer_configs)
        writer_class = writer_info['writer']
    except (ValueError, KeyError, yaml.YAMLError):
        raise ValueError("Invalid writer configs: "
                         "'{}'".format(writer_configs))
    init_kwargs, kwargs = writer_class.separate_init_kwargs(writer_kwargs)
    writer = writer_class(ppp_config_dir=ppp_config_dir,
                          config_files=writer_configs,
                          **init_kwargs)
    return writer, kwargs
398410
def _prepare_settings(pspath, settings):
    '''
    
    '''
    prepared_settings = []
    for setting in settings:
        match = re.search(r'Collection\[(\{.*\})\]', setting['name'])
        if match:
            name = setting['name'][:match.start(1)-1]
            match_dict = yaml.load(match.group(1))
            index = _collection_match_to_index(pspath, setting['filter'], name, match_dict)
            if index != -1:
                setting['name'] = setting['name'].replace(match.group(1), str(index))
                prepared_settings.append(setting)
        else:
            prepared_settings.append(setting)
    return prepared_settings
1279553
def load_ini(self):
        
        if not self.config_file:
            return

        # Load INI file
        ini_file = ConfigParser.SafeConfigParser()
        if not ini_file.read(self.config_file):
            raise ConfigParser.ParsingError("Global configuration file %r not found!" % (
                self.config_file,
            ))

        """
        # Make sure there's our global settings section
        if not ini_file.has_section(self.SECTION):
            raise ConfigParser.ParsingError("%r needs to have a [%s] section!" % (
                self.config_file, self.SECTION,
            ))

        # Get the given values
        for key, val in ini_file.items(self.SECTION):
            # Ensure that all names are known (to prevent uncaught typos)
            if key not in self.KEYS:
                raise ConfigParser.ParsingError("%r has an unknown key %s in the [%s] section!" % (
                    self.config_file, key, self.SECTION,
                ))

            # Do some shell-like path expansion
            val = os.path.expanduser(os.path.expandvars(val))

            # Set as attribute for easy access
            setattr(self, key, val)
        """

        self._validate()