use pyinotify to watch for config changes if installed

This commit is contained in:
j 2013-01-31 08:44:30 +00:00
parent 31652fe3d8
commit c576e347a8
2 changed files with 26 additions and 13 deletions

View file

@ -96,6 +96,18 @@ check the README for further details.
def reloader_thread(): def reloader_thread():
_config_mtime = 0 _config_mtime = 0
try:
import pyinotify
INOTIFY = True
except:
INOTIFY = False
if INOTIFY:
wm = pyinotify.WatchManager()
name = os.path.realpath(settings.SITE_CONFIG)
wm.add_watch(name, pyinotify.IN_CLOSE_WRITE, lambda event: load_config())
notifier = pyinotify.Notifier(wm)
notifier.loop()
else:
while RUN_RELOADER: while RUN_RELOADER:
try: try:
stat = os.stat(settings.SITE_CONFIG) stat = os.stat(settings.SITE_CONFIG)
@ -105,10 +117,10 @@ def reloader_thread():
if mtime > _config_mtime: if mtime > _config_mtime:
load_config() load_config()
_config_mtime = mtime _config_mtime = mtime
time.sleep(1)
except: except:
#sys.stderr.write("reloading config failed\n") #sys.stderr.write("reloading config failed\n")
pass pass
time.sleep(1)
def update_static(): def update_static():
oxjs_build = os.path.join(settings.STATIC_ROOT, 'oxjs/tools/build/build.py') oxjs_build = os.path.join(settings.STATIC_ROOT, 'oxjs/tools/build/build.py')

View file

@ -34,6 +34,7 @@ sudo vmbuilder vbox ubuntu --suite=precise \
--addpkg python-imaging \ --addpkg python-imaging \
--addpkg python-numpy \ --addpkg python-numpy \
--addpkg python-psycopg2 \ --addpkg python-psycopg2 \
--addpkg python-pyinotify \
--addpkg python-simplejson \ --addpkg python-simplejson \
--addpkg python-lxml \ --addpkg python-lxml \
--addpkg python-html5lib \ --addpkg python-html5lib \