Created
March 17, 2012 15:20
-
-
Save methane/2061066 to your computer and use it in GitHub Desktop.
Compile cpp files automatically.
This file contains hidden or 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
| #!/usr/bin/env python | |
| from watchdog import events, observers | |
| from paver.easy import * | |
| import subprocess | |
| class AutoCompile(events.FileSystemEventHandler): | |
| def compile(self, src): | |
| if src.endswith('.cpp'): | |
| src = path(src) | |
| dst = src.splitext()[0] | |
| print src, '=>', dst | |
| ret = subprocess.call(['g++', '-Wall', '-O2', '-g', '-DTEST=1', src, '-o', dst]) | |
| if ret: | |
| return | |
| subprocess.call([dst]) | |
| def on_created(self, event): | |
| self.compile(event.src_path) | |
| def on_modified(self, event): | |
| self.compile(event.src_path) | |
| observer = observers.Observer() | |
| observer.schedule(AutoCompile(), '.', True) | |
| observer.start() | |
| try: | |
| while True: | |
| observer.join(1) | |
| except KeyboaardInterrupt: | |
| observer.stop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment