--reload-extra-file option

This commit is contained in:
Rok Garbas 2017-06-14 00:17:05 +02:00
parent 6b44263f77
commit f736909c5d
No known key found for this signature in database
GPG Key ID: A0E01EF44C27BF00
3 changed files with 31 additions and 1 deletions

View File

@ -368,6 +368,14 @@ def validate_string(val):
return val.strip()
def validate_file_exists(val):
if val is None:
return None
if not os.path.exists(val):
raise ValueError("File %s does not exists." % val)
return val
def validate_list_string(val):
if not val:
return []
@ -379,6 +387,10 @@ def validate_list_string(val):
return [validate_string(v) for v in val]
def validate_list_of_existing_files(val):
return [validate_file_exists(v) for v in validate_list_string(val)]
def validate_string_to_list(val):
val = validate_string(val)
@ -857,6 +869,20 @@ class ReloadEngine(Setting):
"""
class ReloadExtraFiles(Setting):
name = "reload_extra_files"
action = "append"
section = "Debugging"
cli = ["--reload-extra-file"]
meta = "FILES"
validator = validate_list_of_existing_files
default = []
desc = """\
Extends --reload option to also watch and reload on additional files
(e.g., templates, configurations, specifications, etc.).
"""
class Spew(Setting):
name = "spew"
section = "Debugging"

View File

@ -81,6 +81,9 @@ if has_inotify:
self._dirs = set()
self._watcher = Inotify()
for extra_file in extra_files:
self.add_extra_file(extra_file)
def add_extra_file(self, filename):
dirname = os.path.dirname(filename)

View File

@ -120,7 +120,8 @@ class Worker(object):
sys.exit(0)
reloader_cls = reloader_engines[self.cfg.reload_engine]
self.reloader = reloader_cls(callback=changed)
self.reloader = reloader_cls(extra_files=self.cfg.reload_extra_files,
callback=changed)
self.reloader.start()
self.load_wsgi()