Commit 63765165 by Arjun Singh

Adding script that restarts django when content in the data directories changes.

parent dde48f12
#! ../python/bin/python
# This script requires that you have watchdog installed. You can install
# watchdog via 'pip install watchdog'
import sys
import time
import logging
import os
from subprocess import Popen
from signal import SIGTERM
from watchdog.observers import Observer
from watchdog.events import LoggingEventHandler, FileSystemEventHandler
# To watch more (or more specific) directories, change WATCH_DIRS to include the
# directories you want to watch. Note that this is recursive. If you want to
# watch fewer or more extensions, you can change EXTENSIONS.
WATCH_DIRS = ["../data"]
EXTENSIONS = ["xml", "js", "css", "coffee", "scss", "html"]
WATCH_DIRS = [os.path.abspath(os.path.normpath(dir)) for dir in WATCH_DIRS]
class DjangoEventHandler(FileSystemEventHandler):
def __init__(self, process):
FileSystemEventHandler.__init__(self)
self.process = process
def on_any_event(self, event):
for extension in EXTENSIONS:
if event.src_path.endswith(extension):
print "%s changed: restarting server." % event.src_path
self.process.terminate()
os.system("ps aux | grep 'django' | grep -v grep | awk '{print $2}' | xargs kill")
time.sleep(0.25)
self.process = Popen(['rake', 'lms'])
if __name__ == "__main__":
event_handler = DjangoEventHandler(Popen(['rake', 'lms']))
observer = Observer()
for dir in WATCH_DIRS:
observer.schedule(event_handler, dir, recursive=True)
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment