-
Notifications
You must be signed in to change notification settings - Fork 11
/
change_handler.py
56 lines (44 loc) · 1.89 KB
/
change_handler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import os
from watchdog.events import FileSystemEventHandler
class SignalFileChangeHandler(FileSystemEventHandler):
"""Logs all the events captured."""
def __init__(self, callback, filename):
super(SignalFileChangeHandler, self).__init__()
self.callback = callback
self.filename = filename
self.latest_timestamp = 0
def on_modified(self, event):
super(SignalFileChangeHandler, self).on_modified(event)
if os.path.basename(event.src_path) == self.filename:
tstamp = os.path.getmtime(event.src_path)
if self.latest_timestamp != tstamp:
self.callback()
self.latest_timestamp = tstamp
class RasterChangeHandler(FileSystemEventHandler):
"""Logs all the events captured."""
def __init__(self, callback, data):
super(RasterChangeHandler, self).__init__()
self.callback = callback
self.data = data
self.latest_timestamp = 0
def on_created(self, event):
super(RasterChangeHandler, self).on_created(event)
if os.path.basename(event.src_path) == self.data["scan"] + "tmp":
tstamp = os.path.getmtime(event.src_path)
if self.latest_timestamp != tstamp:
self.callback()
self.latest_timestamp = tstamp
class DrawingChangeHandler(FileSystemEventHandler):
"""Logs all the events captured."""
def __init__(self, callback, data):
super(DrawingChangeHandler, self).__init__()
self.callback = callback
self.data = data
self.latest_timestamp = 0
def on_created(self, event):
super(DrawingChangeHandler, self).on_created(event)
if os.path.basename(event.src_path) == self.data:
tstamp = os.path.getmtime(event.src_path)
if self.latest_timestamp != tstamp:
self.callback()
self.latest_timestamp = tstamp