commit 2f3a45e6c9e3fbfd048218b18035a83483c821de
parent edc8d9e5d761e61c5e4e747f7883bb06c183bd50
Author: nolash <dev@holbrook.no>
Date: Wed, 10 Nov 2021 09:57:56 +0100
implement exclude sections
Diffstat:
4 files changed, 17 insertions(+), 15 deletions(-)
diff --git a/confini/env.py b/confini/env.py
@@ -47,6 +47,8 @@ class ConfigEnvParser:
def export_env(config, prefix=None, empty_all=False, skip_empty=False, doc=False, w=sys.stdout):
for k in config.all():
+ if k[0] == '_':
+ continue
v = config.get(k)
if empty_all or v == None:
v = ''
diff --git a/confini/export.py b/confini/export.py
@@ -55,6 +55,8 @@ class ConfigExporter:
def scan(self):
for k in self.config.all():
(s, v) = k.split('_', maxsplit=1)
+ if s == '':
+ continue
s = s.lower()
v = v.lower()
if self.sections.get(s) == None:
@@ -80,18 +82,28 @@ class ConfigExporter:
except KeyError:
logg.warning('doc missing for section {} option {}'.format(ks, ko))
pass
- w.write(ko + " = " + self.sections[ks][ko] + "\n")
+ v = self.sections[ks][ko]
+ if v == None:
+ v = ''
+ w.write('{} = {}\n'.format(ko, v))
w.write("\n")
- def export(self):
+ def export(self, exclude_sections=[]):
self.scan()
w = None
if self.target_typ == ConfigExporterTarget.HANDLE:
w = self.target
+ for i in range(len(exclude_sections)):
+ exclude_sections[i] = exclude_sections[i].lower()
+
for k in self.sections:
+ if k in exclude_sections:
+ logg.debug('explicit skip section {} in export'.format(k))
+ continue
+
if w != None:
self.export_section(k, w)
continue
diff --git a/confini/runnable/dump.py b/confini/runnable/dump.py
@@ -65,17 +65,5 @@ def main():
export_env(c, prefix=args.prefix, empty_all=args.z, skip_empty=args.skip_empty, doc=args.doc)
-# for k in c.store.keys():
-# v = c.get(k)
-# if args.z or v == None:
-# 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__":
main()
diff --git a/setup.py b/setup.py
@@ -6,7 +6,7 @@ f.close()
setup(
name='confini',
- version='0.5.1',
+ version='0.5.2',
description='Parse, verify and merge all ini files in a single directory',
author='Louis Holbrook',
author_email='dev@holbrook.no',