From 54bccb0628f1e925ec5519334aec443902f8c470 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Tue, 17 Mar 2015 10:21:52 +0100 Subject: [PATCH] Restore configuration live reload Closes #94 --- gns3server/config.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/gns3server/config.py b/gns3server/config.py index 8f3c86a1..46f5a3ae 100644 --- a/gns3server/config.py +++ b/gns3server/config.py @@ -92,6 +92,27 @@ class Config(object): self._config = configparser.ConfigParser() self.read_config() + self._watch_config_file() + + def _watch_config_file(self): + asyncio.get_event_loop().call_later(1, self._check_config_file_change) + + def _check_config_file_change(self): + """ + Check if configuration file has changed on the disk + """ + changed = False + for file in self._watched_files: + try: + if os.stat(file).st_mtime != self._watched_files[file]: + changed = True + except OSError: + continue + if changed: + self.read_config() + for section in self._override_config: + self.set_section_config(section, self._override_config[section]) + self._watch_config_file() def reload(self): """