diff --git a/python_apps/media-monitor2/media/monitor/handler.py b/python_apps/media-monitor2/media/monitor/handler.py index 78d954b99..2dc4c0a47 100644 --- a/python_apps/media-monitor2/media/monitor/handler.py +++ b/python_apps/media-monitor2/media/monitor/handler.py @@ -24,7 +24,6 @@ class ReportHandler(Handles): weak=weak) def report_problem_file(self, event, exception=None): - import ipdb; ipdb.set_trace() dispatcher.send(signal=self.report_signal, sender=self, event=event, exception=exception) diff --git a/python_apps/media-monitor2/media/monitor/listeners.py b/python_apps/media-monitor2/media/monitor/listeners.py index 9fa75ba78..ded376242 100644 --- a/python_apps/media-monitor2/media/monitor/listeners.py +++ b/python_apps/media-monitor2/media/monitor/listeners.py @@ -71,6 +71,7 @@ def mediate_ignored(fn): for s_check in skip_events: FileMediator.skip_checks.remove( s_check ) # Only process skip_checks one at a time + FileMediator.logger.info("Skip checked: '%s'" % str(event)) return if FileMediator.is_ignored(event.pathname): FileMediator.logger.info("Ignoring: '%s' (once)" % event.pathname) @@ -108,7 +109,6 @@ class OrganizeListener(BaseListener, pyinotify.ProcessEvent, Loggable): @mediate_ignored @IncludeOnly(mmp.supported_extensions) def process_to_organize(self, event): - import ipdb; ipdb.set_trace() dispatcher.send(signal=self.signal, sender=self, event=OrganizeFile(event)) @@ -121,7 +121,7 @@ class StoreWatchListener(BaseListener, Loggable, pyinotify.ProcessEvent): # into file events until we know for sure if we deleted or moved morph = MoveDir(event) if event.dir else MoveFile(event) EventRegistry.matching(event).morph_into(morph) - #else: self.process_create(event) + else: self.process_create(event) def process_IN_MOVED_FROM(self, event): # Is either delete dir or delete file evt = self.process_delete(event) diff --git a/python_apps/media-monitor2/media/monitor/manager.py b/python_apps/media-monitor2/media/monitor/manager.py index b9ef9c8b2..0772c653e 100644 --- a/python_apps/media-monitor2/media/monitor/manager.py +++ b/python_apps/media-monitor2/media/monitor/manager.py @@ -75,12 +75,22 @@ class Manager(Loggable): def __create_organizer(self, target_path, recorded_path): """ - private constructor for organizer so that we don't have to repeat - adding the channel/signal as a parameter to the original constructor - every time + creates an organizer at new destination path or modifies the old one """ - return Organizer(channel=self.organize_channel,target_path=target_path, - recorded_path=recorded_path) + # We avoid creating new instances of organize because of the way it + # interacts with pydispatch. We must be careful to never have more than + # one instance of OrganizeListener but this is not so easy. (The + # singleton hack in Organizer) doesn't work. This is the only thing + # that seems to work. + if self.organize['organizer']: + o = self.organize['organizer'] + o.channel = self.organize_channel + o.target_path = target_path + o.recorded_path = recorded_path + else: + self.organize['organizer'] = Organizer(channel= + self.organize_channel, target_path=target_path, + recorded_path=recorded_path) def get_problem_files_path(self): return self.organize['problem_files_path'] @@ -96,8 +106,7 @@ class Manager(Loggable): def set_recorded_path(self, new_path): self.__remove_watch(self.organize['recorded_path']) self.organize['recorded_path'] = new_path - self.organize['organizer'] = self.__create_organizer( - self.organize['imported_path'], new_path) + self.__create_organizer( self.organize['imported_path'], new_path) self.__add_watch(new_path, self.watch_listener) def get_organize_path(self): @@ -130,8 +139,7 @@ class Manager(Loggable): """ self.__remove_watch(self.organize['imported_path']) self.organize['imported_path'] = new_path - self.organize['organizer'] = self.__create_organizer( - new_path, self.organize['recorded_path']) + self.__create_organizer( new_path, self.organize['recorded_path']) self.__add_watch(new_path, self.watch_listener) def change_storage_root(self, store): diff --git a/python_apps/media-monitor2/media/monitor/organizer.py b/python_apps/media-monitor2/media/monitor/organizer.py index 7cc9ac647..c901082f2 100644 --- a/python_apps/media-monitor2/media/monitor/organizer.py +++ b/python_apps/media-monitor2/media/monitor/organizer.py @@ -14,11 +14,22 @@ class Organizer(ReportHandler,Loggable): pyinotify. (These events are fed to it through StoreWatchListener) """ + _instance = None + def __new__(cls, channel, target_path, recorded_path): + if cls._instance: + cls._instance.channel = channel + cls._instance.target_path = target_path + cls._instance.recorded_path = recorded_path + else: + cls._instance = super(Organizer, cls).__new__( cls, channel, + target_path, recorded_path) + return cls._instance + def __init__(self, channel, target_path, recorded_path): self.channel = channel self.target_path = target_path self.recorded_path = recorded_path - super(Organizer, self).__init__(signal=self.channel, weak=True) + super(Organizer, self).__init__(signal=self.channel, weak=False) def handle(self, sender, event): """