Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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))
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)
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
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()
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):
"""
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']