trigger autoreload from config files
This commit is contained in:
parent
35b6bb6b3f
commit
d8585eb872
|
@ -8,6 +8,7 @@ from typing import Any
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
from django.conf import ImproperlyConfigured
|
from django.conf import ImproperlyConfigured
|
||||||
|
from django.utils.autoreload import autoreload_started
|
||||||
|
|
||||||
SEARCH_PATHS = [
|
SEARCH_PATHS = [
|
||||||
'passbook/lib/default.yml',
|
'passbook/lib/default.yml',
|
||||||
|
@ -21,6 +22,8 @@ ENVIRONMENT = os.getenv('PASSBOOK_ENV', 'local')
|
||||||
class ConfigLoader:
|
class ConfigLoader:
|
||||||
"""Search through SEARCH_PATHS and load configuration"""
|
"""Search through SEARCH_PATHS and load configuration"""
|
||||||
|
|
||||||
|
loaded_file = []
|
||||||
|
|
||||||
__config = {}
|
__config = {}
|
||||||
__context_default = None
|
__context_default = None
|
||||||
__sub_dicts = []
|
__sub_dicts = []
|
||||||
|
@ -69,6 +72,8 @@ class ConfigLoader:
|
||||||
with open(path) as file:
|
with open(path) as file:
|
||||||
try:
|
try:
|
||||||
self.update(self.__config, yaml.safe_load(file))
|
self.update(self.__config, yaml.safe_load(file))
|
||||||
|
LOGGER.debug("Loaded %s", path)
|
||||||
|
self.loaded_file.append(path)
|
||||||
except yaml.YAMLError as exc:
|
except yaml.YAMLError as exc:
|
||||||
raise ImproperlyConfigured from exc
|
raise ImproperlyConfigured from exc
|
||||||
except PermissionError as exc:
|
except PermissionError as exc:
|
||||||
|
@ -126,3 +131,10 @@ class ConfigLoader:
|
||||||
|
|
||||||
|
|
||||||
CONFIG = 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)
|
||||||
|
|
|
@ -35,6 +35,8 @@ redis: localhost/0
|
||||||
error_report_enabled: true
|
error_report_enabled: true
|
||||||
secret_key: 9$@r!d^1^jrn#fk#1#@ks#9&i$^s#1)_13%$rwjrhd=e8jfi_s
|
secret_key: 9$@r!d^1^jrn#fk#1#@ks#9&i$^s#1)_13%$rwjrhd=e8jfi_s
|
||||||
|
|
||||||
|
domains:
|
||||||
|
- passbook.local
|
||||||
primary_domain: 'localhost'
|
primary_domain: 'localhost'
|
||||||
|
|
||||||
passbook:
|
passbook:
|
||||||
|
|
Reference in New Issue