Get options from config files.
338582
def finalize_options(self) -> None:
        ""
        self.arguments = {}  # type: Dict[str, Any]
        computed_settings = from_path(os.getcwd())
        for key, value in computed_settings.items():
            self.arguments[key] = value
1246237
def get_config_values(config_path, section, default='default'):
    
    values = {}

    if not os.path.isfile(config_path):
        raise IpaUtilsException(
            'Config file not found: %s' % config_path
        )

    config = configparser.ConfigParser()

    try:
        config.read(config_path)
    except Exception:
        raise IpaUtilsException(
            'Config file format invalid.'
        )

    try:
        values.update(config.items(default))
    except Exception:
        pass

    try:
        values.update(config.items(section))
    except Exception:
        pass

    return values
1054561
def load_config(path=None):
    """"""
    if not path or not op.exists(path):
        return Config()
    path = op.realpath(path)
    dirpath, filename = op.split(path)
    file_ext = op.splitext(path)[1]
    logger.debug("Load config file `%s`.", path)
    if file_ext == '.py':
        config = PyFileConfigLoader(filename, dirpath,
                                    log=logger).load_config()
    elif file_ext == '.json':
        config = JSONFileConfigLoader(filename, dirpath,
                                      log=logger).load_config()
    return config
971028
def _read_options(paths,fname_def=None):
    """"""
    def reader_func(fname=fname_def, sect=None, sett=None, default=None):
        """Reads the configuration for trump"""

        cur_dir = os.path.dirname(os.path.realpath(__file__))
        config_dir = os.path.join(cur_dir, *paths)

        config_files = [(f[:-4], f)
                        for f in os.listdir(config_dir) if f[-4:] == ".cfg"]
        sample_files = [(f[:-11], f)
                        for f in os.listdir(config_dir) if f[-11:] == ".cfg_sample"]

        if fname:
            config_files = [f for f in config_files if f[0] == fname]
            sample_files = [f for f in sample_files if f[0] == fname]


        config_files = dict(config_files)
        sample_files = dict(sample_files)

        cfg_files = sample_files
        for fn, f in config_files.iteritems():
            cfg_files[fn] = f

        sample_files_exposed = []

        confg = {}

        for src, fil in cfg_files.iteritems():
            confg[src] = {}
            cfpr = ConfigParser.ConfigParser()
            cfpr.read(os.path.join(config_dir, fil))
            for sec in cfpr.sections():
                confg[src][sec] = dict(cfpr.items(sec))

            if ".cfg_sample" in fil:
                sample_files_exposed.append(fil)


        if len(sample_files_exposed) > 0:
            msg = ", ".join(sample_files_exposed)
            body = "{} sample configuration files have been exposed. " \
                  "Rename *.cfg_sample to *.cfg, and populate the " \
                  "correct settings in the config and settings " \
                  "directories to avoid this warning."
            msg = body.format(msg)
            warnings.warn(msg)

        keys = []

        if fname:
            keys.append(fname)
            if sect:
                keys.append(sect)
                if sett:
                    keys.append(sett)
        try:
            return get_from_nested(keys, confg)
        except KeyError:
            if default is not None:
                return default
            else:
                raise

    return reader_func
755109
def _get_options(ret=None):
    '''
    
    '''
    defaults = {'host': 'salt',
                'user': 'salt',
                'pass': 'salt',
                'db': 'salt',
                'port': 3306,
                'ssl_ca': None,
                'ssl_cert': None,
                'ssl_key': None}

    attrs = {'host': 'host',
             'user': 'user',
             'pass': 'pass',
             'db': 'db',
             'port': 'port',
             'ssl_ca': 'ssl_ca',
             'ssl_cert': 'ssl_cert',
             'ssl_key': 'ssl_key'}

    _options = salt.returners.get_returner_options(__virtualname__,
                                                   ret,
                                                   attrs,
                                                   __salt__=__salt__,
                                                   __opts__=__opts__,
                                                   defaults=defaults)
    # post processing
    for k, v in six.iteritems(_options):
        if isinstance(v, six.string_types) and v.lower() == 'none':
            # Ensure 'None' is rendered as None
            _options[k] = None
        if k == 'port':
            # Ensure port is an int
            _options[k] = int(v)

    return _options
170579
def get_config_for(args, component, prefix=""):
    
    config = {}
    vargs = vars(args)
    for option in component.options:
        if component.options[option].hidden:
            continue
        config[option] = vargs["%s%s" % (prefix, option)]
    return config
260171
def options_from_file(args):
    
    logger.debug("updating options from config files")
    updated_from_file = []
    for config_file in CONFIG_FILES:
        logger.debug("updating from: %s", config_file)
        parser = ConfigParser()
        parser.read(config_file)
        try:
            items = parser.items('fades')
        except NoSectionError:
            continue

        for config_key, config_value in items:
            if config_value in ['true', 'false']:
                config_value = config_value == 'true'
            if config_key in MERGEABLE_CONFIGS:
                current_value = getattr(args, config_key, [])
                if current_value is None:
                    current_value = []
                current_value.append(config_value)
                setattr(args, config_key, current_value)
            if not getattr(args, config_key, False) or config_key in updated_from_file:
                # By default all 'store-true' arguments are False. So we only
                # override them if they are False. If they are True means that the
                # user is setting those on the CLI.
                setattr(args, config_key, config_value)
                updated_from_file.append(config_key)
                logger.debug("updating %s to %s from file settings", config_key, config_value)

    return args
160544
def configured_options(self):
        """"""
        stdout_lines = self._check_output(['config', '--list']).splitlines()
        return {key: value for key, value in [line.split('=') for line in stdout_lines]}
1067399
def _get_config(self, i):
        
        variables = {}
        if not i.get_option('config'):
            raise Exception('The --config|-c option is missing.')

        with open(i.get_option('config')) as fh:
            exec(fh.read(), {}, variables)

        return variables['DATABASES']
676309
def values(self, section=None):
        """"""
        if not section and self.section:
            section = self.section
        config = self.config.get(section, {}) if section else self.config
        return config.values()
1116714
def _config_section(config, section):
    """"""
    path = os.path.join(config.get('config_path'), config.get('config_file'))
    conf = _config_ini(path)
    return conf.get(section)
78626
def parse_options(settings):
    ''''''
    optlist, args = getopt(sys.argv, 'x', [])
    settings['configfile'] = args[1]
    return settings
281004
def config_conf(obj):
    ""
    # If we ever want to add some default options this is where to do that
    cfg = {}
    for name in dir(obj):
        if name in CONFIG_PARSER_CFG: # argument of ConfigParser
            cfg[name] = getattr(obj, name)
    return cfg
1061192
def config():
    ''''''
    if hasattr(current_app, 'settings_file'):
        log.info('Loaded configuration from %s', current_app.settings_file)

    log.info(white('Current configuration'))
    for key in sorted(current_app.config):
        if key.startswith('__') or not key.isupper():
            continue
        echo('{0}: {1}'.format(white(key), current_app.config[key]))
1200486
def _get_value_from_config(self, section, name):
        """"""

        conf = configuration.get_config()

        try:
            value = conf.get(section, name)
        except (NoSectionError, NoOptionError, KeyError):
            return _no_value

        return self.parse(value)
96234
def _gather_configs_in(directory):
    
    try:
        return sorted([
            os.path.join(directory, fname)
            for fname in os.listdir(directory)
            if fname.endswith('.py')
        ])
    except OSError:
        return []
174089
def _get_config(self, unit, filename):
        """"""
        file_contents = unit.file_contents(filename)

        # NOTE(beisner):  by default, ConfigParser does not handle options
        # with no value, such as the flags used in the mysql my.cnf file.
        # https://bugs.python.org/issue7005
        config = configparser.ConfigParser(allow_no_value=True)
        config.readfp(io.StringIO(file_contents))
        return config