commit c43917479ad2f5c8fc545bc51a208e1ae4f1c881
parent f16b21becf4beefa0e11a2226cd2da91201cc36f
Author: nolash <dev@holbrook.no>
Date: Tue, 26 Oct 2021 10:06:05 +0200
Allow string override dir, add options to dump client
Diffstat:
3 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/confini/config.py b/confini/config.py
@@ -20,8 +20,6 @@ def set_current(conf, description=''):
current_config = conf
-
-
class Config:
parser = configparser.ConfigParser(strict=True)
@@ -35,6 +33,10 @@ class Config:
self.collect_from_dirs(default_dir)
else:
self.dirs = [default_dir]
+ if isinstance(override_dirs, str):
+ override_dirs = [override_dirs]
+ elif override_dirs == None:
+ override_dirs = []
for d in override_dirs:
if not os.path.isdir(d):
raise OSError('{} is not a directory'.format(override_dirs))
@@ -49,6 +51,7 @@ class Config:
logg.info('using prefix {} for environment variable override matches'.format(env_prefix))
self.env_prefix = '{}_'.format(env_prefix)
+
def collect_from_dirs(self, dirs):
self.__target_tmpdir = tempfile.TemporaryDirectory()
self.dirs = [self.__target_tmpdir.name]
diff --git a/confini/runnable/dump.py b/confini/runnable/dump.py
@@ -16,6 +16,8 @@ logg = logging.getLogger()
argparser = argparse.ArgumentParser()
argparser.add_argument('-z', action='store_true', help='Truncate values in output')
argparser.add_argument('-v', action='store_true', help='Be verbose')
+argparser.add_argument('--prefix', type=str, help='Prefix every line with given string')
+argparser.add_argument('--skip-empty', action='store_true', dest='skip_empty', help='Skip defined directives that are missing a value')
argparser.add_argument('--schema-dir', dest='schema_dir', action='append', type=str, help='Configuation directory to merge with schema definitions')
argparser.add_argument('--schema-module', dest='schema_module', action='append', type=str, default=[], help='Module path to merge with schema definitions')
argparser.add_argument('config_dir', nargs='*', type=str, help='Configuation directories to parse')
@@ -24,6 +26,8 @@ args = argparser.parse_args()
if args.v:
logg.setLevel(logging.DEBUG)
+if args.z and args.skip_empty:
+ logg.warning('Both -z and --skip-empty are defined, this will produce no output')
def main():
schema_dirs = []
@@ -53,7 +57,12 @@ def main():
v = c.get(k)
if args.z or v == None:
v = ''
- print('{}={}'.format(k, v))
+ if v == '' and args.skip_empty:
+ logg.debug('skipping empty directive {}'.format(k))
+ continue
+ if args.prefix != None:
+ sys.stdout.write(args.prefix + ' ')
+ sys.stdout.write('{}={}\n'.format(k, v))
if __name__ == "__main__":
diff --git a/setup.py b/setup.py
@@ -6,7 +6,7 @@ f.close()
setup(
name='confini',
- version='0.4.2rc1',
+ version='0.4.2rc4',
description='Parse, verify and merge all ini files in a single directory',
author='Louis Holbrook',
author_email='dev@holbrook.no',