trigger autoreload from config files

This commit is contained in:
Jens Langhammer 2019-04-10 18:48:55 +02:00
parent 35b6bb6b3f
commit d8585eb872
2 changed files with 14 additions and 0 deletions

View File

@ -8,6 +8,7 @@ from typing import Any
import yaml
from django.conf import ImproperlyConfigured
from django.utils.autoreload import autoreload_started
SEARCH_PATHS = [
'passbook/lib/default.yml',
@ -21,6 +22,8 @@ ENVIRONMENT = os.getenv('PASSBOOK_ENV', 'local')
class ConfigLoader:
"""Search through SEARCH_PATHS and load configuration"""
loaded_file = []
__config = {}
__context_default = None
__sub_dicts = []
@ -69,6 +72,8 @@ class ConfigLoader:
with open(path) as file:
try:
self.update(self.__config, yaml.safe_load(file))
LOGGER.debug("Loaded %s", path)
self.loaded_file.append(path)
except yaml.YAMLError as exc:
raise ImproperlyConfigured from exc
except PermissionError as exc:
@ -126,3 +131,10 @@ class ConfigLoader:
CONFIG = ConfigLoader()
# pylint: disable=unused-argument
def signal_handler(sender, **kwargs):
"""Add all loaded config files to autoreload watcher"""
for path in CONFIG.loaded_file:
sender.watch_file(path)
autoreload_started.connect(signal_handler)

View File

@ -35,6 +35,8 @@ redis: localhost/0
error_report_enabled: true
secret_key: 9$@r!d^1^jrn#fk#1#@ks#9&i$^s#1)_13%$rwjrhd=e8jfi_s
domains:
- passbook.local
primary_domain: 'localhost'
passbook: