From c576e347a8b643a2b2a4c891518ec75ae8d91a55 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Thu, 31 Jan 2013 08:44:30 +0000 Subject: [PATCH] use pyinotify to watch for config changes if installed --- pandora/app/config.py | 38 +++++++++++++++++++++++++------------- vm/build.sh | 1 + 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/pandora/app/config.py b/pandora/app/config.py index 07d0baf90..909df83e8 100644 --- a/pandora/app/config.py +++ b/pandora/app/config.py @@ -96,19 +96,31 @@ check the README for further details. def reloader_thread(): _config_mtime = 0 - 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 - except: - #sys.stderr.write("reloading config failed\n") - pass - time.sleep(1) + 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: + 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(): oxjs_build = os.path.join(settings.STATIC_ROOT, 'oxjs/tools/build/build.py') diff --git a/vm/build.sh b/vm/build.sh index d102fefaa..f2733d1f2 100755 --- a/vm/build.sh +++ b/vm/build.sh @@ -34,6 +34,7 @@ sudo vmbuilder vbox ubuntu --suite=precise \ --addpkg python-imaging \ --addpkg python-numpy \ --addpkg python-psycopg2 \ + --addpkg python-pyinotify \ --addpkg python-simplejson \ --addpkg python-lxml \ --addpkg python-html5lib \