pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

Python pastebin - collaborative debugging tool View Help


Posted by wilkes on Fri 1 Feb 01:05 (modification of post by view diff)
report spam | View followups from wilkes | download | new post

  1. from FSEvents import *
  2. import objc
  3. import os, sys
  4.  
  5. class Autotester(object):
  6.     def __init__(self):
  7.         self.snapshot = {}
  8.         self.target = os.path.abspath(os.curdir)
  9.  
  10.     def run(self):
  11.         if self.__check_changes():
  12.             self.__run_nose()
  13.  
  14.     def __remove_from(self, l, items):
  15.         for i in items:
  16.             l.remove(i)
  17.  
  18.     def __check_changes(self):
  19.         changes = []
  20.         for root, dirs, files in os.walk(self.target):
  21.             self.__remove_from(dirs, [d for d in dirs if d.startswith('.')])
  22.             self.__remove_from(files, [f for f in files if not f.endswith('.py')])
  23.             for name in files:
  24.                 f = os.path.join(root, name)
  25.                 last_update = os.path.getmtime(f)
  26.                 last_known = self.snapshot.setdefault(f, last_update)
  27.                 if last_update != last_known:
  28.                     changes.append(f)
  29.                     self.snapshot[f] = last_update
  30.         return changes
  31.  
  32.     def __run_nose(self):
  33.         try:
  34.             if os.system('nosetests ' + self.target):
  35.                 os.system('growlnotify -n autotest -p 0 -m "what the hell dude?"')
  36.             else:
  37.                 os.system('growlnotify -n autotest -p 0 -m "yeah, boi"')
  38.         except:
  39.             pass
  40. tester = Autotester()
  41.  
  42. def timer_callback(timer, stream):
  43.     FSEventStreamFlushAsync(stream)
  44.    
  45. def fsevents_callback(stream, clientInfo, numEvents, eventPaths, eventMasks, eventIDs):
  46.     tester.run()
  47.    
  48. def createStream(full_path):
  49.     allocator = kCFAllocatorDefault
  50.     callback = fsevents_callback
  51.     path      = full_path
  52.     since_when = kFSEventStreamEventIdSinceNow
  53.     latency   = 1.0
  54.     flags     = 0
  55.  
  56.     stream = FSEventStreamCreate(kCFAllocatorDefault,
  57.                                   callback,
  58.                                   path,
  59.                                   [path],
  60.                                   since_when,
  61.                                   latency,
  62.                                   flags)
  63.  
  64.     assert stream, "ERROR: FSEVentStreamCreate() => NULL"
  65.     return stream
  66.  
  67. def run_loop(stream):
  68.     FSEventStreamScheduleWithRunLoop(stream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode)
  69.     assert FSEventStreamStart(stream), "Failed to start stream"
  70.     timer = CFRunLoopTimerCreate(kCFAllocatorDefault,
  71.                                 CFAbsoluteTimeGetCurrent() + 1.0,
  72.                                 1.0,
  73.                                 0,
  74.                                 0,
  75.                                 timer_callback,
  76.                                 stream)
  77.     CFRunLoopAddTimer(CFRunLoopGetCurrent(), timer, kCFRunLoopDefaultMode)
  78.     try:
  79.         CFRunLoopRun()
  80.     finally:
  81.         FSEventStreamStop(stream)
  82.         FSEventStreamInvalidate(stream)
  83.         FSEventStreamRelease(stream)
  84.  
  85. def main():
  86.     tester.target = sys.argv[1]
  87.     tester.run()
  88.     abspath = os.path.join(os.path.abspath(os.curdir), tester.target)
  89.     run_loop(createStream(abspath))
  90.  
  91. if __name__ == '__main__':
  92.     main()

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me