Skip to content

Commit 5234feb

Browse files
committed
Allow overriding the confd_path from an entry in the main config
1 parent d2bc899 commit 5234feb

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

conf_d/__init__.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77

88
class Configuration():
99

10-
def __init__(self, name, path, parse=True, confd_path=None, conf_ext=None, main_defaults={}, section_defaults={}, main_parser=None, section_parser=None):
10+
def __init__(self, name, path, parse=True, confd_path=None, conf_ext=None, main_defaults={}, section_defaults={}, main_parser=None, section_parser=None, path_from_main=None):
1111
self._conf_ext = conf_ext
1212
self._config_sections = {}
1313
self._confd_path = confd_path
14+
self._path_from_main = path_from_main
1415
self._main_config = {}
1516
self._main_defaults = main_defaults
1617
self._main_parser = main_parser
@@ -73,8 +74,20 @@ def parse(self):
7374
self._main_config = configs.get(self._name)
7475

7576
self._config_sections = self._parse_section(path=self._path, defaults=self._section_defaults, parser=self._section_parser, remove_section=self._name)
77+
78+
if self._path_from_main:
79+
self._confd_path = self._main_config.get(self._path_from_main, self._confd_path)
80+
7681
if self._confd_path:
77-
for f in sorted(os.listdir(self._confd_path)):
82+
try:
83+
paths = os.listdir(self._confd_path)
84+
except OSError:
85+
paths = None
86+
87+
if not paths:
88+
return
89+
90+
for f in sorted(paths):
7891
path = os.path.realpath(os.path.join(self._confd_path, f))
7992
if not os.path.isfile(path):
8093
continue

0 commit comments

Comments
 (0)