Commit 5918cccd by jarv

Merge pull request #293 from MITx/arjun/add_data_watcher

Adding script that restarts django when content in the data directories changes.
parents 94a84211 60365a64
#! /usr/bin/env 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. To watch all
# extensions, add "*" to 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) or extension == "*":
print "%s changed: restarting server." % event.src_path
os.system("touch lms/__init__.py")
break
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