How to use the vaping.Config function in vaping

To help you get started, we’ve selected a few vaping examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github 20c / vaping / tests / test_daemon.py View on Github external
def test_config_object(this_dir):
    config_dir = os.path.join(this_dir, "data", "config", "fping")
    vaping.daemon.Vaping(config=vaping.Config(read=config_dir))
github 20c / vaping / tests / test_daemon.py View on Github external
def test_empty_config_object():
    with pytest.raises(ValueError) as excinfo:
        vaping.daemon.Vaping(config=vaping.Config())
    assert 'config was not specified' in str(excinfo.value)
github 20c / vaping / tests / test_daemon.py View on Github external
def test_plugin_context():
    data = {
        '1': 'two'
        }
    cfg = vaping.Config(data=data)
    ctx = vaping.daemon.PluginContext(cfg)
    assert data == ctx.config.data

    # test immutable
    ctx.config.data['1'] = 'three'
    assert data != ctx.config.data
github 20c / vaping / vaping / daemon.py View on Github external
def __init__(self, config=None, config_dir=None):
        """
        must either pass config as a dict or vaping.config.Config
        or config_dir as a path to where the config dir is located
        """
        if config:
            if isinstance(config, dict):
                self.config = vaping.Config(data=config)
            else:
                if not config.meta:
                    raise ValueError("config was not specified or empty")
                self.config = config
        elif config_dir:
            self.config = vaping.Config(read=config_dir)
        else:
            raise ValueError("config was not specified or empty")

        self.joins = []
        self._logger = None
        self.plugin_context = PluginContext(self.config)

        vcfg = self.config.get('vaping', None)
        if not vcfg:
            vcfg = dict()
github 20c / vaping / vaping / cli.py View on Github external
import os

import click
import munge
import munge.click

import vaping
import vaping.daemon


class Context(munge.click.Context):
    """
    Extended `click` context to use for vaping cli
    """
    app_name = 'vaping'
    config_class = vaping.Config


def update_context(ctx, kwargs):
    ctx.update_options(kwargs)

    if not isinstance(ctx.config['vaping']['plugin_path'], list):
        raise ValueError('config item vaping.plugin_path must be a list')
    # set plugin search path to defined + home/plugins
    searchpath = ctx.config['vaping']['plugin_path']
    if ctx.home:
        searchpath.append(os.path.join(ctx.home, 'plugins'))
    vaping.plugin.searchpath = searchpath


def mk_daemon(ctx):
    """
github 20c / vaping / vaping / daemon.py View on Github external
def __init__(self, config=None, config_dir=None):
        """
        must either pass config as a dict or vaping.config.Config
        or config_dir as a path to where the config dir is located
        """
        if config:
            if isinstance(config, dict):
                self.config = vaping.Config(data=config)
            else:
                if not config.meta:
                    raise ValueError("config was not specified or empty")
                self.config = config
        elif config_dir:
            self.config = vaping.Config(read=config_dir)
        else:
            raise ValueError("config was not specified or empty")

        self.joins = []
        self._logger = None
        self.plugin_context = PluginContext(self.config)

        vcfg = self.config.get('vaping', None)
        if not vcfg:
            vcfg = dict()

        # get either home_dir from config, or use config_dir
        self.home_dir = vcfg.get('home_dir', None)
        if not self.home_dir:
            self.home_dir = self.config.meta['config_dir']