From 0128c75b055554d6b8c5688fe522df63e2d1f8e0 Mon Sep 17 00:00:00 2001 From: Vasil Taneski Date: Wed, 12 Jun 2013 10:59:21 +0200 Subject: [PATCH] Added autorunner on file modification --- python2/run.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 python2/run.py diff --git a/python2/run.py b/python2/run.py new file mode 100755 index 000000000..b16b57c93 --- /dev/null +++ b/python2/run.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python + +import os +import sys +try: + from watchdog.observers import Observer + from watchdog.events import FileSystemEventHandler + import re + import time +except ImportError: + os.system("python contemplate_koans.py") + +class ModifyHandler(FileSystemEventHandler): + @classmethod + def is_about_file(filename): + is_file = os.path.isfile(filename) + matches_name_pattern = re.match("^.*about_.+\.py", filename) + return is_file and matches_name_pattern + + def on_modified(self, event): + #print event.event_type, event.src_path + if (is_about_file(event.src_path)): + from runner.mountain import Mountain + Mountain().walk_the_path(".") + +if __name__ == "__main__": + observer = Observer() + observer.schedule(ModifyHandler(), ".", recursive=True) + observer.start() + try: + while True: + time.sleep(1) + except KeyboardInterrupt: + observer.stop() + observer.join()