confini

Parse and merge multiple ini files in python3
git clone git://git.defalsify.org/python-confini.git
Log | Files | Refs | README | LICENSE

commit 0d40e02fba787b93a5402f8b56ecf2ef15f7888d
parent b5dbf005b631333f46ba3fdd729dc77d76307f05
Author: nolash <dev@holbrook.no>
Date:   Sun, 11 Jul 2021 18:43:45 +0200

Habilitate all non-pgp configs to multi dir

Diffstat:
Mconfini/config.py | 25+++++++++++++------------
Mtests/test_censor.py | 2+-
2 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/confini/config.py b/confini/config.py @@ -34,7 +34,7 @@ class Config: self.dirs = [] for d in config_dirs: if not os.path.isdir(d): - raise OSError('{} is not a directory'.format(config_dir)) + raise OSError('{} is not a directory'.format(config_dirs)) self.dirs.append(os.path.realpath(d)) self.required = {} self.censored = {} @@ -142,20 +142,21 @@ class Config: c = 0 logg.debug('d {}'.format(d)) for tmp_config_dir in d: - #tmpname = os.path.join(d, tmpname) - #logg.debug('d {}'.format(tmpname)) tmp_config_dir = os.path.join(tmp_dir, tmp_config_dir) logg.debug('>> barrr {}'.format(tmp_config_dir)) - if c == 0: - for tmp_file in os.listdir(os.path.join(tmp_config_dir)): - tmp_config_file_path = os.path.join(tmp_config_dir, tmp_file) - logg.debug('>> fooo {}'.format(tmp_config_file_path)) + for tmp_file in os.listdir(os.path.join(tmp_config_dir)): + tmp_config_file_path = os.path.join(tmp_config_dir, tmp_file) + if c == 0: self.parser.read(tmp_config_file_path) - else: - local_parser = configparser.ConfigParser(strict=True) - local_parser.read(tmpname) - for s in local_parser.sections(): - logg.debug('seciont {}'.format(s)) + else: + local_parser = configparser.ConfigParser(strict=True) + local_parser.read(tmp_config_file_path) + for s in local_parser.sections(): + for so in local_parser.options(s): + k = self.to_constant_name(so, s) + v = local_parser.get(s, so) + logg.debug('multi config file override: {} -> {}'.format(k, v)) + self.add(v, k, exists_ok=True) c += 1 self._sections_override(os.environ, 'environment variable') if set_as_current: diff --git a/tests/test_censor.py b/tests/test_censor.py @@ -17,7 +17,7 @@ class TestCensor(unittest.TestCase): def test_censor(self): inidir = os.path.join(self.wd, 'files/translate') - c = Config(inidir) + c = Config([inidir]) c.process() c.censor('foo', 'bar') v = c.apply_censor('BAR_FOO')