Esempio n. 1
0
class AppConfig:

    dashboard_config_loader: Config

    def load(self, path_like: str):

        path = Path(path_like).expanduser().absolute()

        if not path.parent.is_dir():
            path.parent.mkdir(parents=True)

        self._location = Location(path.parent)

        self.dashboard_config_loader = Config(path.name,
                                              transport=Transport(
                                                  [self._location]))

        return self.dashboard_config_loader.load()

    def save(self):
        self.dashboard_config_loader.dump(self._location)

    def init_logger(self, debug: bool):
        logging.basicConfig(
            level=logging.DEBUG if debug else logging.INFO,
            format=
            '%(asctime)s - %(levelname)s - %(filename)s:%(lineno)s: %(message)s',
        )
Esempio n. 2
0
def test_load_simple_found_cwd():

    cfg = Config(_data_filename)

    assert cfg.load() is True

    assert cfg.data == {"a": 42}
Esempio n. 3
0
def load() -> PabuConfig:
    config_loader = Config('pabu.yaml')

    if not config_loader.load():
        return None

    return tree.load(config_loader.data)
Esempio n. 4
0
def test_load_simple_climber():

    cfg = Config(_data_filename, transport=Transport([ClimberLocation()]))

    assert cfg.load() is True

    assert cfg.data == {"a": 84}
    assert cfg.path == '/home/douglas/teve/' + _data_filename
Esempio n. 5
0
def test_load_simple_found_etc():

    cfg = Config(_data_filename)

    assert cfg.load() is True

    assert cfg.data == {"a": 42}
    assert cfg.path == '/etc/' + _data_filename
Esempio n. 6
0
def test_not_loaded_single_config_dump():

    cfg = Config(_data_filename)

    cfg.data = {"a": 42}

    cfg.dump(Location('/etc'))

    assert os.path.exists('/etc/test1.json')
Esempio n. 7
0
def load() -> AppConfig:
    config_loader = Config('scrat.yaml')

    if not config_loader.load():
        raise Exception("config not loaded")

    app_config: AppConfig = tree.load(config_loader.data)

    logging.config.dictConfig(app_config.logger)

    logger.debug("config loaded from %s", config_loader.path)

    return app_config
Esempio n. 8
0
    def load(self, path_like: str):

        path = Path(path_like).expanduser().absolute()

        if not path.parent.is_dir():
            path.parent.mkdir(parents=True)

        self._location = Location(path.parent)

        self.dashboard_config_loader = Config(path.name,
                                              transport=Transport(
                                                  [self._location]))

        return self.dashboard_config_loader.load()
Esempio n. 9
0
def test_loaded_single_config_dump():

    cfg = Config(_data_filename)

    assert cfg.load()

    cfg.data['a'] = 43

    cfg.dump()

    with open('/etc/' + _data_filename) as f:
        content = f.read()

    assert content == '{"a": 43}'
Esempio n. 10
0
from configpp.soil import Config

cfg = Config('app.json')

cfg.load()

print(cfg.data)
Esempio n. 11
0
def test_load_simple_not_found():
    cfg = Config(_data_filename)

    assert cfg.load() is False
Esempio n. 12
0
def test_load_simple_location_order():

    cfg = Config(_data_filename)

    assert cfg.load() is True
    assert cfg.data == {"a": 84}
Esempio n. 13
0
def test_guessing_in_ctors(filename, transform):

    assert isinstance(Config(filename).transform, transform)
    assert isinstance(GroupMember(filename).transform, transform)