Commit 18b66839fb085a70efb3aa1448ab881d8b2add39
1 parent
e7bb0d7b
Exists in
master
and in
39 other branches
Reading settings from /etc/colab/settings.d
Showing
1 changed file
with
22 additions
and
7 deletions
Show diff stats
colab/utils/conf.py
| ... | ... | @@ -11,13 +11,7 @@ class InaccessibleYAMLSettings(ImproperlyConfigured): |
| 11 | 11 | Check if the file exists and if you have read permissions.""" |
| 12 | 12 | |
| 13 | 13 | |
| 14 | -def load_yaml_settings(): | |
| 15 | - yaml_path = os.getenv('COLAB_SETTINGS', '/etc/colab/settings.yaml') | |
| 16 | - | |
| 17 | - if not os.path.exists(yaml_path): | |
| 18 | - msg = "The yaml file {} does not exist".format(yaml_path) | |
| 19 | - raise InaccessibleYAMLSettings(msg) | |
| 20 | - | |
| 14 | +def _load_yaml_file(yaml_path): | |
| 21 | 15 | try: |
| 22 | 16 | with open(yaml_path) as yaml_file: |
| 23 | 17 | yaml_settings = yaml.load(yaml_file.read()) |
| ... | ... | @@ -27,6 +21,27 @@ def load_yaml_settings(): |
| 27 | 21 | 'has read rights.').format(yaml_path) |
| 28 | 22 | raise InaccessibleYAMLSettings(msg) |
| 29 | 23 | |
| 24 | + return yaml_settings | |
| 25 | + | |
| 26 | + | |
| 27 | +def load_yaml_settings(): | |
| 28 | + settings_dir = '/etc/colab/settings.d' | |
| 29 | + yaml_path = os.getenv('COLAB_SETTINGS', '/etc/colab/settings.yaml') | |
| 30 | + | |
| 31 | + if not os.path.exists(yaml_path): | |
| 32 | + msg = "The yaml file {} does not exist".format(yaml_path) | |
| 33 | + raise InaccessibleYAMLSettings(msg) | |
| 34 | + | |
| 35 | + yaml_settings = _load_yaml_file(yaml_path) | |
| 36 | + | |
| 37 | + # Try to read settings from settings.d | |
| 38 | + if os.path.exists(settings_dir): | |
| 39 | + for file_name in os.listdir(settings_dir): | |
| 40 | + if file_name.endswith('.yaml') or file_name.endswith('yml'): | |
| 41 | + file_path = os.path.join(settings_dir, file_name) | |
| 42 | + yaml_settings_d = _load_yaml_file(file_path) | |
| 43 | + yaml_settings.update(yaml_settings_d) | |
| 44 | + | |
| 30 | 45 | return yaml_settings or {} |
| 31 | 46 | |
| 32 | 47 | yaml_settings = load_yaml_settings() | ... | ... |