Cheers.
# Notification tool
# Run with the directory to watch
# currently hardcoded to use
#
# +
# |- src - contains source code and is monitored
# |- build - assumes build to be here
#
# (c) 2009, Nikhil Marathe
# Licensed under the MIT License
import sys
import os
import subprocess
import re
from pyinotify import WatchManager, Notifier, ProcessEvent, IN_MODIFY
wm = WatchManager()
class Compile( ProcessEvent ):
def process_IN_MODIFY( self, event ):
print event.path, event.name, event.mask & IN_MODIFY
if re.match( '[a-zA-Z]*.cpp', event.name ):
os.chdir( event.path.replace( 'src', 'build' ) )
ex = subprocess.call( 'make' )
subprocess.call( ['notify-send', "Build output", "%s" % ( ex == 0 and "Success" or "Error" )] )
c = Compile()
notifier = Notifier( wm, c )
wm.add_watch( sys.argv[1], IN_MODIFY, rec=True )
notifier.loop()