Added interactive diff gui
[ugit.git] / py / inotify.py
blobe27508988d60df52d970c561842dd25e01a61208
1 #!/usr/bin/env python
2 import os
3 import cmds
4 from PyQt4.QtCore import QThread, SIGNAL
5 from pyinotify import ProcessEvent
6 from pyinotify import WatchManager, Notifier, EventsCodes
8 class FileSysEvent (ProcessEvent):
9 def __init__ (self, parent):
10 ProcessEvent.__init__ (self)
11 self.parent = parent
12 def process_default (self, event):
13 self.parent.notify()
15 class GitNotifier (QThread):
16 def __init__ (self, path):
17 QThread.__init__ (self)
18 self.path = path
19 self.abort = False
21 def notify (self):
22 self.emit ( SIGNAL ('timeForRescan()') )
24 def run (self):
25 # Only capture those events that git cares about
26 mask = ( EventsCodes.IN_CREATE
27 | EventsCodes.IN_DELETE
28 | EventsCodes.IN_MOVED_TO
29 | EventsCodes.IN_MODIFY )
31 wm = WatchManager()
32 notifier = Notifier (wm, FileSysEvent(self))
33 self.notifier = notifier
35 dirs_seen = {}
36 added_flag = False
37 while not self.abort:
39 if not added_flag:
40 wm.add_watch (self.path, mask)
41 # Register files/directories known to git
42 for file in cmds.git_ls_files():
43 wm.add_watch (file, mask)
44 directory = os.path.dirname (file)
45 if directory not in dirs_seen:
46 wm.add_watch (directory, mask)
47 dirs_seen[directory] = True
48 added_flag = True
49 notifier.process_events()
51 if notifier.check_events():
52 notifier.read_events()
54 self.msleep (200)
56 notifier.stop()