Exclude a line from inclusion in a diff if the selection only contains its trailing...
[ugit.git] / ugitlibs / inotify.py
blob41f798180c53dd65b0db5e767d4b957c759576cb
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
7 import time
9 class FileSysEvent(ProcessEvent):
10 def __init__(self, parent):
11 ProcessEvent.__init__(self)
12 self.parent = parent
13 self.last_event_time = time.time()
14 def process_default(self, event):
15 # Prevent notificaiton floods
16 if time.time() - self.last_event_time >= 1.0:
17 self.parent.notify()
18 self.last_event_time = time.time()
20 class GitNotifier(QThread):
21 def __init__(self, path):
22 QThread.__init__(self)
23 self.path = path
24 self.abort = False
26 def notify(self):
27 if not self.abort:
28 self.emit( SIGNAL('timeForRescan()') )
30 def run(self):
31 # Only capture those events that git cares about
32 mask =( EventsCodes.IN_CREATE
33 | EventsCodes.IN_DELETE
34 | EventsCodes.IN_MOVED_TO
35 | EventsCodes.IN_MODIFY )
37 wm = WatchManager()
38 notifier = Notifier(wm, FileSysEvent(self))
39 self.notifier = notifier
41 dirs_seen = {}
42 added_flag = False
43 while not self.abort:
45 if not added_flag:
46 wm.add_watch(self.path, mask)
47 # Register files/directories known to git
48 for file in cmds.git_ls_files():
49 wm.add_watch(file, mask)
50 directory = os.path.dirname(file)
51 if directory not in dirs_seen:
52 wm.add_watch(directory, mask)
53 dirs_seen[directory] = True
54 added_flag = True
56 notifier.process_events()
58 if notifier.check_events():
59 notifier.read_events()
61 self.msleep(200)
63 notifier.stop()