Exemplo n.º 1
0
def read_config(
    user_config: Optional[str] = None,
    cli_options: Optional[Dict[str, Union[bool, str]]] = None
) -> configparser.ConfigParser:
    """Read configuration data.

    Args:
        user_config: User defined config file
        cli_options: Command line options

    Returns:
        Parsed configuration data

    """
    # Only base *must* exist
    conf = configparser.ConfigParser()
    # No, it *really* must
    conf.read_string(resources.read_text('rdial', 'config'), 'pkg config')
    conf['DEFAULT'] = {'xdg_data_location': xdg_basedir.user_data('rdial')}
    for f in xdg_basedir.get_configs('rdial'):
        conf.read(f)
    conf.read(os.path.abspath('.rdialrc'))
    if user_config:
        conf.read(user_config)

    if cli_options:
        conf.read_dict({
            'rdial': {k: v
                      for k, v in cli_options.items()
                      if v is not None}
        })

    return conf
Exemplo n.º 2
0
def read_config(user_config: Optional[str] = None,
                cli_options: Optional[Dict[str, Union[bool, str]]] = None
                ) -> configparser.ConfigParser:
    """Read configuration data.

    Args:
        user_config: User defined config file
        cli_options: Command line options

    Returns:
        Parsed configuration data

    """
    # Only base *must* exist
    conf = configparser.ConfigParser()
    # No, it *really* must
    conf.read_string(resources.read_text('rdial', 'config'), 'pkg config')
    conf['DEFAULT'] = {'xdg_data_location': xdg_basedir.user_data('rdial')}
    for f in xdg_basedir.get_configs('rdial'):
        conf.read(f)
    conf.read(os.path.abspath('.rdialrc'))
    if user_config:
        conf.read(user_config)

    if cli_options:
        conf.read_dict({
            'rdial': {k: v
                      for k, v in cli_options.items() if v is not None}
        })

    return conf
Exemplo n.º 3
0
def test_get_configs_macos(monkeypatch, path_exists_force):
    monkeypatch.setattr('sys.platform', 'darwin')
    assert '/Library/' in xdg_basedir.get_configs('jnrbase')[-1]
Exemplo n.º 4
0
def test_get_configs_custom_dirs(monkeypatch, path_exists_force):
    monkeypatch.setenv('XDG_CONFIG_DIRS', 'test1:test2')
    assert len(xdg_basedir.get_configs('jnrbase')) == 3
Exemplo n.º 5
0
def test_get_configs(path_exists_force):
    assert len(xdg_basedir.get_configs('jnrbase')) == 2
Exemplo n.º 6
0
def test_get_configs_all_missing(path_exists_force):
    assert xdg_basedir.get_configs('jnrbase') == []
Exemplo n.º 7
0
def test_get_configs_macos():
    expect(xdg_basedir.get_configs('jnrbase')[-1]).contains('/Library/')
Exemplo n.º 8
0
def test_get_configs_custom_dirs():
    with patch_env({'XDG_CONFIG_DIRS': 'test1:test2'}):
        expect(len(xdg_basedir.get_configs('jnrbase'))) == 3
Exemplo n.º 9
0
def test_get_configs():
    expect(len(xdg_basedir.get_configs('jnrbase'))) == 2
Exemplo n.º 10
0
def test_get_configs_all_missing():
    expect(xdg_basedir.get_configs('jnrbase')) == []