44
44
InsufficientConfiguration.'''
45
45
has_queue = True
46
46
try :
47
- import pyinotify
47
+ import inotify_simple
48
48
except ImportError :
49
49
has_queue = False
50
50
51
- class FakePyinotify (object ):
52
-
53
- class ProcessEvent (object ):
54
- pass
55
-
56
- pyinotify = FakePyinotify
57
-
58
51
59
52
def requires_queue (f ):
60
53
def wrapped (* args , ** kwargs ):
@@ -124,32 +117,19 @@ def __init__(self, archive, queue_dir, callback=None):
124
117
self ._archive = archive
125
118
self ._callback = callback
126
119
127
- class EventHandler (pyinotify .ProcessEvent ):
128
-
129
- def __init__ (self , callback ):
130
- super (Uploader .EventHandler , self ).__init__ ()
131
- self .callback = callback
132
-
133
- def process_IN_CLOSE_WRITE (self , event ):
134
- self .callback (event .pathname )
135
-
136
- def process_IN_MOVED_TO (self , event ):
137
- self .callback (event .pathname )
120
+ self .inotify = inotify_simple .INotify ()
138
121
139
122
def _setup_watch_manager (self , timeout ):
140
- if timeout is not None :
141
- timeout = int (timeout * 1000 )
142
- self ._wm = pyinotify .WatchManager ()
143
- self ._handler = Uploader .EventHandler (self ._push )
144
- self ._notifier = pyinotify .Notifier (self ._wm , self ._handler ,
145
- timeout = timeout )
146
- self ._wm .add_watch (self .queue_dir ,
147
- pyinotify .IN_CLOSE_WRITE | pyinotify .IN_MOVED_TO )
123
+ flags = inotify_simple .flags
124
+ watch_flags = flags .CLOSE_WRITE | flags .MOVED_TO
125
+ self .inotify .add_watch (self .queue_dir , watch_flags )
148
126
149
127
def _push (self , filename ):
128
+ if not os .path .isabs (filename ):
129
+ filename = os .path .join (self .queue_dir , filename )
150
130
if os .path .basename (filename ).startswith ('.' ):
151
131
return
152
- if self ._workers == [] :
132
+ if not self ._workers :
153
133
self ._synchronous_push (filename )
154
134
else :
155
135
self ._threaded_push (filename )
@@ -205,7 +185,7 @@ def _listen(self, timeout=None, workers=1):
205
185
msg = 'number of upload workers cannot be zero or negative'
206
186
raise InsufficientConfiguration (msg )
207
187
if workers > 1 :
208
- # when multipe workers are requested, the main thread monitors the
188
+ # when multiple workers are requested, the main thread monitors the
209
189
# queue directory and puts the files in a Queue that is serviced by
210
190
# the worker threads. So the word queue is a bit overloaded in this
211
191
# module.
@@ -229,12 +209,16 @@ def _create_worker(self, worker_number):
229
209
def _run (self , timeout ):
230
210
231
211
self ._prepare_to_track_run_time (timeout )
232
- self ._notifier .process_events ()
233
- while self ._notifier .check_events ():
234
- self ._notifier .read_events ()
235
- self ._notifier .process_events ()
236
- if self ._update_time_remaining () == 0 :
237
- break
212
+ if timeout is not None :
213
+ timeout = int (timeout * 1000 )
214
+
215
+ while self ._update_time_remaining () > 0 :
216
+ for event in self .inotify .read (timeout = timeout ):
217
+ if event .name is None :
218
+ continue
219
+ self ._push (event .name )
220
+ if self ._update_time_remaining () == 0 :
221
+ break
238
222
239
223
def _update_time_remaining (self ):
240
224
if self ._run_time_remaining is self .INFINITY :
0 commit comments