4 from PyQt4
.QtCore
import QCoreApplication
5 from PyQt4
.QtCore
import QThread
6 from PyQt4
.QtCore
import QEvent
7 from PyQt4
.QtCore
import SIGNAL
8 from pyinotify
import ProcessEvent
9 from pyinotify
import WatchManager
, Notifier
, EventsCodes
14 class FileSysEvent(ProcessEvent
):
15 def __init__(self
, parent
):
16 ProcessEvent
.__init
__(self
)
18 self
.last_event_time
= time
.time()
19 def process_default(self
, event
):
20 # Prevent notificaiton floods
21 if time
.time() - self
.last_event_time
> 1.0:
23 self
.last_event_time
= time
.time()
25 class GitNotifier(QThread
):
26 def __init__(self
, receiver
, path
):
27 QThread
.__init
__(self
)
29 self
.receiver
= receiver
34 EventsCodes
.IN_CREATE |
35 EventsCodes
.IN_DELETE |
36 EventsCodes
.IN_MODIFY |
37 EventsCodes
.IN_MOVED_TO
42 event_type
= QEvent
.Type(defaults
.INOTIFY_EVENT
)
43 event
= QEvent(event_type
)
44 QCoreApplication
.postEvent(self
.receiver
, event
)
46 def watch_directory(self
, directory
):
47 directory
= os
.path
.realpath(directory
)
48 if directory
not in self
.dirs_seen
:
49 self
.wm
.add_watch(directory
, self
.mask
)
50 self
.dirs_seen
[directory
] = True
53 # Only capture those events that git cares about
54 self
.wm
= WatchManager()
55 notifier
= Notifier(self
.wm
, FileSysEvent(self
))
56 self
.notifier
= notifier
61 self
.watch_directory(self
.path
)
62 # Register files/directories known to git
63 for file in self
.git
.ls_files().splitlines():
64 directory
= os
.path
.dirname(file)
65 self
.watch_directory(directory
)
67 notifier
.process_events()
68 if notifier
.check_events(timeout
=250):
69 notifier
.read_events()