cc-4235: workaround for this terrible bug

This commit is contained in:
Rudi Grinberg 2012-08-16 12:06:10 -04:00
parent d50c4ded6b
commit 699f9b16c0
2 changed files with 23 additions and 0 deletions

View File

@ -65,9 +65,11 @@ class BaseListener(object):
class OrganizeListener(BaseListener, pyinotify.ProcessEvent, Loggable):
def process_IN_CLOSE_WRITE(self, event):
self.logger.info("===> handling: '%s'" % str(event))
self.process_to_organize(event)
# got cookie
def process_IN_MOVED_TO(self, event):
self.logger.info("===> handling: '%s'" % str(event))
self.process_to_organize(event)
def process_default(self, event):

View File

@ -1,4 +1,6 @@
import pyinotify
import threading
import time
from pydispatch import dispatcher
from os.path import normpath
@ -9,6 +11,17 @@ from media.monitor.handler import ProblemFileHandler
from media.monitor.organizer import Organizer
import media.monitor.pure as mmp
class ManagerTimeout(threading.Thread,Loggable):
def __init__(self, manager):
threading.Thread.__init__(self)
self.manager = manager
def run(self):
while True:
time.sleep(3)
self.manager.flush_organize()
self.logger.info("Force flushed organize...")
class Manager(Loggable):
"""
An abstraction over media monitors core pyinotify functions. These
@ -23,6 +36,10 @@ class Manager(Loggable):
self.watch_channel = 'watch'
self.organize_channel = 'organize'
self.watch_listener = StoreWatchListener(signal = self.watch_channel)
# TODO : change this to a weak ref
self.__timeout_thread = ManagerTimeout(self)
self.__timeout_thread.daemon = True
self.__timeout_thread.start()
self.organize = {
'organize_path' : None,
'imported_path' : None,
@ -140,6 +157,10 @@ class Manager(Loggable):
self.organize['organize_listener'].flush_events(new_path)
self.__add_watch(new_path, self.organize['organize_listener'])
def flush_organize(self):
path = self.organize['organize_path']
self.organize['organize_listener'].flush_events(path)
def get_imported_path(self):
return self.organize['imported_path']