4 from PyQt4
.QtCore
import QThread
, SIGNAL
5 from pyinotify
import ProcessEvent
6 from pyinotify
import WatchManager
, Notifier
, EventsCodes
9 class FileSysEvent(ProcessEvent
):
10 def __init__(self
, parent
):
11 ProcessEvent
.__init
__(self
)
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:
18 self
.last_event_time
= time
.time()
20 class GitNotifier(QThread
):
21 def __init__(self
, path
):
22 QThread
.__init
__(self
)
28 self
.emit( SIGNAL('timeForRescan()') )
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
)
38 notifier
= Notifier(wm
, FileSysEvent(self
))
39 self
.notifier
= notifier
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
56 notifier
.process_events()
58 if notifier
.check_events():
59 notifier
.read_events()