예제 #1
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()
예제 #2
0
파일: commands.py 프로젝트: xlisci02/perun
def turn_off_paging_wrt_config(paged_function):
    """Helper function for checking if the function should be paged or not according to the config
    setting ``general.paging``.

    If in global config the ``genera.paging`` is set to ``always``, then any function should be
    paged. Otherwise we check if ``general.paging`` contains either ``only-log`` or ``only-status``.

    :param str paged_function: name of the paged function, which will be looked up in config
    :return: true if the function should be paged (unless --no-pager is set)
    """
    try:
        paging_option = perun_config.shared().get('general.paging')
    # Test for backward compatibility with old instances of Perun and possible issues
    except MissingConfigSectionException:
        perun_log.warn(
            """corrupted shared configuration file: missing ``general.paging`` option.

Run ``perun config --shared --edit`` and set the ``general.paging`` to one of following:
    always, only-log, only-status, never

Consult the documentation (Configuration and Logs) for more information about paging of
output of status, log and others.
        """)
        return True
    return paging_option == 'always' or \
        (paging_option.startswith('only-') and paging_option.endswith(paged_function))
예제 #3
0
파일: pcs.py 프로젝트: petr-muller/perun
    def global_config():
        """Get global config

        Returns:
            Config: global config object, that can be passed to function of config module
        """
        return config.shared()
예제 #4
0
def get_global_config():
    """Function for loading shared (global) Perun settings
    :return: dictionary containing global settings
    """
    try:
        global_settings = config.shared()
    except Exception as e:
        return create_response(e, 404)

    output = { 
        'general': [], 
        'format': [], 
    }

    items = {
        'general': ['paging','editor'],
        'format': ['status','log','output_profile_template'],
    }

    for section, item in items.items():
        for subsection in item:
            try:
                value = global_settings.get(section + '.' + subsection)
            except:
                value = ''
            finally:
                output[section].append(formatter.format_configuration(subsection, value, '', '', 'edit'))

    return jsonify({'globalSettings': output})   
예제 #5
0
파일: pcs.py 프로젝트: xlisci02/perun
def global_config():
    """Get global config for the current Perun context

    :returns Config: global config object, that can be passed to function of config module
    """
    return config.shared()