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
)
22 self
.emit( SIGNAL('timeForRescan()') )
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
)
32 notifier
= Notifier(wm
, FileSysEvent(self
))
33 self
.notifier
= notifier
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
49 notifier
.process_events()
51 if notifier
.check_events():
52 notifier
.read_events()