Commit c9a36a70 by Arjun Singh

Adding an option to watch all extensions; useful for a VIM user where the…

Adding an option to watch all extensions; useful for a VIM user where the filesystem events aren't triggered when saving a file without disabling backups.
parent 63765165
...@@ -14,10 +14,11 @@ from watchdog.events import LoggingEventHandler, FileSystemEventHandler ...@@ -14,10 +14,11 @@ from watchdog.events import LoggingEventHandler, FileSystemEventHandler
# To watch more (or more specific) directories, change WATCH_DIRS to include the # 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 # directories you want to watch. Note that this is recursive. If you want to
# watch fewer or more extensions, you can change EXTENSIONS. # watch fewer or more extensions, you can change EXTENSIONS. To watch all
# extensions, add "*" to EXTENSIONS.
WATCH_DIRS = ["../data"] WATCH_DIRS = ["../data"]
EXTENSIONS = ["xml", "js", "css", "coffee", "scss", "html"] EXTENSIONS = ["*", "xml", "js", "css", "coffee", "scss", "html"]
WATCH_DIRS = [os.path.abspath(os.path.normpath(dir)) for dir in WATCH_DIRS] WATCH_DIRS = [os.path.abspath(os.path.normpath(dir)) for dir in WATCH_DIRS]
...@@ -30,12 +31,13 @@ class DjangoEventHandler(FileSystemEventHandler): ...@@ -30,12 +31,13 @@ class DjangoEventHandler(FileSystemEventHandler):
def on_any_event(self, event): def on_any_event(self, event):
for extension in EXTENSIONS: for extension in EXTENSIONS:
if event.src_path.endswith(extension): if event.src_path.endswith(extension) or extension == "*":
print "%s changed: restarting server." % event.src_path print "%s changed: restarting server." % event.src_path
self.process.terminate() self.process.terminate()
os.system("ps aux | grep 'django' | grep -v grep | awk '{print $2}' | xargs kill") os.system("ps aux | grep 'django' | grep -v grep | awk '{print $2}' | xargs kill")
time.sleep(0.25) time.sleep(0.25)
self.process = Popen(['rake', 'lms']) self.process = Popen(['rake', 'lms'])
break
if __name__ == "__main__": if __name__ == "__main__":
event_handler = DjangoEventHandler(Popen(['rake', 'lms'])) event_handler = DjangoEventHandler(Popen(['rake', 'lms']))
......
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