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,19 +96,31 @@ check the README for further details.
def reloader_thread(): def reloader_thread():
_config_mtime = 0 _config_mtime = 0
while RUN_RELOADER: try:
try: import pyinotify
stat = os.stat(settings.SITE_CONFIG) INOTIFY = True
mtime = stat.st_mtime except:
if _win: INOTIFY = False
mtime -= stat.st_ctime if INOTIFY:
if mtime > _config_mtime: wm = pyinotify.WatchManager()
load_config() name = os.path.realpath(settings.SITE_CONFIG)
_config_mtime = mtime wm.add_watch(name, pyinotify.IN_CLOSE_WRITE, lambda event: load_config())
except: notifier = pyinotify.Notifier(wm)
#sys.stderr.write("reloading config failed\n") notifier.loop()
pass else:
time.sleep(1) while RUN_RELOADER:
try:
stat = os.stat(settings.SITE_CONFIG)
mtime = stat.st_mtime
if _win:
mtime -= stat.st_ctime
if mtime > _config_mtime:
load_config()
_config_mtime = mtime
time.sleep(1)
except:
#sys.stderr.write("reloading config failed\n")
pass
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 \