예제 #1
0
파일: commands.py 프로젝트: xlisci02/perun
def config_reset(store_type, config_template):
    """Resets the given store_type to a default type (or to a selected configuration template)

    For more information about configuration templates see :ref:`config-templates`.

    :param str store_type: name of the store (local or global) which we are resetting
    :param str config_template: name of the template that we are resetting to
    :raises NotPerunRepositoryException: raised when we are outside of any perun scope
    """
    if store_type in ('shared', 'global'):
        shared_location = perun_config.lookup_shared_config_dir()
        perun_config.init_shared_config_at(shared_location)
    else:
        vcs_config = {
            'vcs': {
                'url': pcs.get_vcs_path(),
                'type': pcs.get_vcs_type()
            }
        }
        perun_config.init_local_config_at(pcs.get_path(), vcs_config,
                                          config_template)
    perun_log.info("{} configuration reset{}".format(
        'global' if store_type in ('shared', 'global') else 'local',
        " to {}".format(config_template) if store not in ("shared",
                                                          "global") else ""))
예제 #2
0
파일: pcs.py 프로젝트: xlisci02/perun
def get_config_file(config_type):
    """Returns the config file for the given config type

    :returns str: path of the config of the given type
    """
    if config_type in ('shared', 'global'):
        return os.path.join(config.lookup_shared_config_dir(), 'shared.yml')
    else:
        return os.path.join(get_path(), 'local.yml')
예제 #3
0
def test_shared_dir_lookup(monkeypatch, capsys):
    """Test lookup of the shared dir for various platforms"""
    monkeypatch.setattr('sys.platform', 'win32')
    win_dir = config.lookup_shared_config_dir()
    assert 'AppData' in win_dir
    assert 'Local' in win_dir
    assert win_dir.endswith('perun')

    monkeypatch.setattr('sys.platform', 'linux')
    assert config.lookup_shared_config_dir().endswith(('.config/perun'))

    monkeypatch.setattr('sys.platform', 'sun')
    monkeypatch.setenv('PERUN_CONFIG_DIR', '')
    with pytest.raises(SystemExit):
        config.lookup_shared_config_dir()
    _, err = capsys.readouterr()
    assert "unsupported" in err

    monkeypatch.setenv('PERUN_CONFIG_DIR', '/mnt/g/d')
    assert config.lookup_shared_config_dir() == '/mnt/g/d'
예제 #4
0
파일: pcs.py 프로젝트: petr-muller/perun
 def get_config_dir(self, config_type):
     """
     Returns:
         str: path of to the directory of with the config
     """
     if config_type in ('local', 'recursive'):
         return self.path
     elif config_type in ('shared', 'global'):
         return config.lookup_shared_config_dir()
     else:
         log.error("wrong configuration type for self.get_config_dir: '{}'".
                   format(config_type))
예제 #5
0
def test_inits(capsys, tmpdir):
    """Test initializing various types of config"""
    temp_dir = tmpdir.mkdir('.perun')

    # First try to init local config
    config.init_local_config_at(str(temp_dir),
                                {'vcs': {
                                    'type': 'git',
                                    'url': str(temp_dir)
                                }})

    # Now try loading the local config
    local_config = config.local(str(temp_dir))
    assert local_config.type == 'local'
    assert local_config.path == os.path.join(str(temp_dir), 'local.yml')
    assert local_config.data['vcs']['type'] == 'git'
    assert local_config.data['vcs']['url'] == str(temp_dir)

    # Try local, when the local was not initialized at all
    other_dir = tmpdir.mkdir('.perun2')
    other_config = other_dir.join('local.yml')
    other_local_config = config.local(str(other_config))

    out, _ = capsys.readouterr()
    assert "warn" in out
    assert other_local_config.data == {}
    assert other_local_config.path == str(other_config)
    assert other_local_config.type == 'local'

    # Try that local behaves like singleton
    assert local_config == config.local(str(temp_dir))

    # Try to init global config
    save = config.lookup_shared_config_dir
    config.lookup_shared_config_dir = lambda: str(temp_dir)
    assert config.lookup_shared_config_dir() == str(temp_dir)

    config.init_config_at(str(temp_dir), 'shared')

    # Now try loading the global config
    global_config = config.load_config(str(other_dir), 'shared')
    assert global_config.type == 'shared'
    assert global_config.path == os.path.join(str(other_dir), 'shared.yml')
    assert global_config.data['general']['editor'] == 'vim'
    assert global_config.data['general']['paging'] == 'only-log'
    assert 'status' in global_config.data['format'].keys()
    assert 'shortlog' in global_config.data['format'].keys()

    # Assert that global behaves like singleton
    config.lookup_shared_config_dir = save
    assert config.shared() == config.shared()
예제 #6
0
파일: pcs.py 프로젝트: petr-muller/perun
 def get_config_file(self, config_type):
     """
     Returns:
         str: path of the config of the given type
     """
     if config_type in ('local', 'recursive'):
         return os.path.join(self.path, 'local.yml')
     elif config_type in ('shared', 'global'):
         return os.path.join(config.lookup_shared_config_dir(),
                             'shared.yml')
     else:
         log.error(
             "wrong configuration type for self.get_config_file: '{}'".
             format(config_type))