<s> import subprocess <EOL> import sys <EOL> import pyinotify <EOL> class OnWriteHandler ( pyinotify . ProcessEvent ) : <EOL> def my_init ( self , cwd , extension , cmd ) : <EOL> self . cwd = cwd <EOL> self . extensions = extension . split ( '<STR_LIT:U+002C>' ) <EOL> self . cmd = cmd <EOL> def _run_cmd ( self ) : <EOL> print '<STR_LIT>' <EOL> subprocess . call ( self . cmd . split ( '<STR_LIT:U+0020>' ) , cwd = self . cwd ) <EOL> def process_IN_MODIFY ( self , event ) : <EOL> if all ( not event . pathname . endswith ( ext ) for ext in self . extensions ) : <EOL> return <EOL> self . _run_cmd ( ) <EOL> def auto_compile ( path , extension , cmd ) : <EOL> wm = pyinotify . WatchManager ( ) <EOL> handler = OnWriteHandler ( cwd = path , extension = extension , cmd = cmd ) <EOL> notifier = pyinotify . Notifier ( wm , default_proc_fun = handler ) <EOL> wm . add_watch ( path , pyinotify . ALL_EVENTS , rec = True , auto_add = True ) <EOL> print '<STR_LIT>' % path <EOL> notifier . loop ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> if len ( sys . argv ) < <NUM_LIT:3> : <EOL> print >> sys . stderr , "<STR_LIT>" <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> path = sys . argv [ <NUM_LIT:1> ] <EOL> extension = sys . argv [ <NUM_LIT:2> ] <EOL> cmd = '<STR_LIT>' <EOL> if len ( sys . argv ) == <NUM_LIT:4> : <EOL> cmd = sys . argv [ <NUM_LIT:3> ] <EOL> auto_compile ( path , extension , cmd ) </s>
