Created
September 2, 2012 03:49
-
-
Save jonathansick/3594679 to your computer and use it in GitHub Desktop.
Run make whenever a LaTeX file is modified (using Python watchdog)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import os | |
import time | |
from watchdog.observers import Observer | |
from watchdog.events import FileSystemEventHandler | |
class ChangeHandler(FileSystemEventHandler): | |
"""React to modified .tex files.""" | |
def on_any_event(self, event): | |
"""If a file or folder is changed.""" | |
if event.is_directory: | |
return | |
if os.path.splitext(event.src_path)[-1].lower() == ".tex": | |
subprocess.call("make", shell=True) | |
def main(): | |
handler = ChangeHandler() | |
observer = Observer() | |
observer.schedule(handler, '.') | |
observer.start() | |
try: | |
while True: | |
time.sleep(1) | |
except KeyboardInterrupt: | |
observer.stop() | |
observer.join() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment