Пример #1
0
 def test_env_path(self):
     os.environ['HELLO_WORLD_PATH'] = 'testdata:testdata/a:testdata/b'
     cfg = Config('hello', 'world')
     expected = [
         'testdata/app.ini', 'testdata/a/app.ini', 'testdata/b/app.ini'
     ]
     self.assertEqual(cfg.active_path, expected)
Пример #2
0
 def test_search_path(self):
     cfg = Config('hello',
                  'world',
                  search_path='testdata:testdata/a:testdata/b')
     self.assertTrue(cfg.has_section('section3'))
     self.assertEqual(cfg.get('section1', 'var1'), 'frob')
     self.assertEqual(
         cfg.loaded_files,
         ['testdata/app.ini', 'testdata/a/app.ini', 'testdata/b/app.ini'])
Пример #3
0
 def test_env_name(self):
     os.environ['HELLO_WORLD_CONFIG'] = 'test.ini'
     cfg = Config('hello', 'world')
     expected = [
         '/etc/hello/world/test.ini',
         expanduser('~/.hello/world/test.ini'),
         '{}/test.ini'.format(os.getcwd())
     ]
     self.assertEqual(cfg.active_path, expected)
Пример #4
0
 def test_env_path_add(self):
     os.environ['HELLO_WORLD_PATH'] = '+testdata:testdata/a:testdata/b'
     cfg = Config('hello', 'world')
     expected = [
         '/etc/hello/world/app.ini',
         expanduser('~/.hello/world/app.ini'),
         '{}/app.ini'.format(os.getcwd()), 'testdata/app.ini',
         'testdata/a/app.ini', 'testdata/b/app.ini'
     ]
     self.assertEqual(cfg.active_path, expected)
Пример #5
0
    def __init__(self, conf=None):
        try:
            self.conf = conf or Config('gefoo', 'ubiety', require_load=True)
            self.pingers = self.create_pingers()

            # Setup restapi
            self.restapi = Bottle()
            self.restapi.get(
                path="/pinger/<pinger_name>",
                callback=self.get_pinger,
                name="get_pinger"
            )
            self.restapi.get(
                path="/pinger",
                callback=self.get_pingers,
                name="get_pingers"
            )
            self.restapi.install(
                JSONPlugin(
                    json_dumps=lambda s: jsonify(s, cls=PingerJSONEncoder)
                )
            )
        except OSError as exc:
            raise OSError(exc)
Пример #6
0
 def setUp(self):
     self.cfg = Config('hello', 'world', search_path='testdata')
Пример #7
0
 def test_app_group_name(self):
     cfg = Config('hello', 'world')
     self.assertEqual(cfg.group_name, 'hello')
     self.assertEqual(cfg.app_name, 'world')
Пример #8
0
 def test_filename(self):
     cfg = Config('hello',
                  'world',
                  filename='test.ini',
                  search_path='testdata')
     self.assertEqual(cfg.get('section2', 'var1'), 'baz')
Пример #9
0
import logging.handlers

from config_resolver import Config

LOG = logging.getLogger(__name__)
LOG.setLevel(logging.DEBUG)

FORMATTER = logging.Formatter(
    "%(asctime)s - %(name)s - %(levelname)s - %(message)s")
CONSOLE_HANDLER = logging.StreamHandler()
CONSOLE_HANDLER.setLevel(logging.INFO)
CONSOLE_HANDLER.setFormatter(FORMATTER)
logging.getLogger().setLevel(logging.DEBUG)
logging.getLogger().addHandler(CONSOLE_HANDLER)

CONF = Config('wicked', 'metafilter')

from metafilter.model import Session, CONFIG, set_dsn
from metafilter.model.nodes import update_nodes_from_path, remove_orphans, calc_md5

error_log = expanduser(CONFIG.get('cli_logging', 'error_log', None))
if error_log:
    if not exists(dirname(error_log)):
        LOG.info('Creating logging folder: %s' % dirname(error_log))
        makedirs(dirname(error_log))
    ERROR_HANDLER = logging.handlers.RotatingFileHandler(filename=error_log,
                                                         maxBytes=102400,
                                                         backupCount=5)
    ERROR_HANDLER.setLevel(logging.WARNING)
    ERROR_HANDLER.setFormatter(FORMATTER)
    logging.getLogger().addHandler(ERROR_HANDLER)
Пример #10
0
def load_cfg():
    '''
    return config
    '''
    config = Config('mds', 'onewire')
    return config
Пример #11
0
def load_config():
    return Config('mds', 'pystrip')