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
)
12 def process_default(self
, event
):
15 class GitNotifier(QThread
):
16 def __init__(self
, path
):
17 QThread
.__init
__(self
)
23 self
.emit( SIGNAL('timeForRescan()') )
26 # Only capture those events that git cares about
27 mask
=( EventsCodes
.IN_CREATE
28 | EventsCodes
.IN_DELETE
29 | EventsCodes
.IN_MOVED_TO
30 | EventsCodes
.IN_MODIFY
)
33 notifier
= Notifier(wm
, FileSysEvent(self
))
34 self
.notifier
= notifier
41 wm
.add_watch(self
.path
, mask
)
42 # Register files/directories known to git
43 for file in cmds
.git_ls_files():
44 wm
.add_watch(file, mask
)
45 directory
= os
.path
.dirname(file)
46 if directory
not in dirs_seen
:
47 wm
.add_watch(directory
, mask
)
48 dirs_seen
[directory
] = True
51 notifier
.process_events()
53 if notifier
.check_events():
54 notifier
.read_events()