From 7d29379b07f00deea62cb2f869a53e8b3fb99fbd Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Mon, 27 Aug 2012 16:48:39 -0400 Subject: [PATCH] cc-3936: Dirty hack to fix issue. We are using pydispatch to add new watch directories and giving the mm.manager another responsiblity it should not have. --- .../airtime-2.2.0/common/UpgradeCommon.php | 2 +- .../media-monitor2/media/monitor/manager.py | 4 ++++ .../media-monitor2/media/monitor/organizer.py | 15 +++++++++++++-- python_apps/media-monitor2/media/monitor/pure.py | 6 +++++- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/install_minimal/upgrades/airtime-2.2.0/common/UpgradeCommon.php b/install_minimal/upgrades/airtime-2.2.0/common/UpgradeCommon.php index 9942945da..1d7183bcc 100644 --- a/install_minimal/upgrades/airtime-2.2.0/common/UpgradeCommon.php +++ b/install_minimal/upgrades/airtime-2.2.0/common/UpgradeCommon.php @@ -130,7 +130,7 @@ class UpgradeCommon{ echo "Copying configs:\n"; foreach ($config_copy as $path_part => $destination) { $full_path = OsPath::normpath(OsPath::join(__DIR__, - "$path_part.$suffix")); + "$path_part.$suffix")); echo "'$full_path' --> '$destination'\n"; if(!copy($full_path, $destination)) { echo "Failed on the copying operation above\n"; diff --git a/python_apps/media-monitor2/media/monitor/manager.py b/python_apps/media-monitor2/media/monitor/manager.py index 03b6142c0..0a0fcfec3 100644 --- a/python_apps/media-monitor2/media/monitor/manager.py +++ b/python_apps/media-monitor2/media/monitor/manager.py @@ -54,6 +54,10 @@ class Manager(Loggable): def dummy(sender, event): self.watch_move( event.path, sender=sender ) dispatcher.connect(dummy, signal='watch_move', sender=dispatcher.Any, weak=False) + def subwatch_add(sender, directory): + self.__add_watch(directory, self.watch_listener) + dispatcher.connect(subwatch_add, signal='add_subwatch', + sender=dispatcher.Any, weak=False) # A private mapping path => watch_descriptor # we use the same dictionary for organize, watch, store wd events. # this is a little hacky because we are unable to have multiple wd's diff --git a/python_apps/media-monitor2/media/monitor/organizer.py b/python_apps/media-monitor2/media/monitor/organizer.py index fc46db537..bf6f672d9 100644 --- a/python_apps/media-monitor2/media/monitor/organizer.py +++ b/python_apps/media-monitor2/media/monitor/organizer.py @@ -5,7 +5,9 @@ import media.monitor.owners as owners from media.monitor.handler import ReportHandler from media.monitor.log import Loggable from media.monitor.exceptions import BadSongFile -from media.monitor.events import OrganizeFile +from media.monitor.events import OrganizeFile +from pydispatch import dispatcher +from os.path import dirname class Organizer(ReportHandler,Loggable): """ @@ -55,7 +57,16 @@ class Organizer(ReportHandler,Loggable): else self.target_path new_path = mmp.organized_path(event.path, target_path, event.metadata.extract()) - mmp.magic_move(event.path, new_path) + + # disgusting stuff... See hack in mmp.magic_move + def new_dir_watch(d): + def cb(): + dispatcher.send(signal="add_subwatch", sender=self, + directory=d) + return cb + + mmp.magic_move(event.path, new_path, + after_dir_make=new_dir_watch(dirname(new_path))) owners.add_file_owner(new_path, mmp.owner_id(event.path) ) self.logger.info('Organized: "%s" into "%s"' % (event.path, new_path)) diff --git a/python_apps/media-monitor2/media/monitor/pure.py b/python_apps/media-monitor2/media/monitor/pure.py index bf6975068..f52871dc0 100644 --- a/python_apps/media-monitor2/media/monitor/pure.py +++ b/python_apps/media-monitor2/media/monitor/pure.py @@ -145,13 +145,17 @@ def walk_supported(directory, clean_empties=False): for fp in full_paths: yield fp if clean_empties: clean_empty_dirs(directory) -def magic_move(old, new): +def magic_move(old, new, after_dir_make=lambda : None): """ Moves path old to new and constructs the necessary to directories for new along the way """ new_dir = os.path.dirname(new) if not os.path.exists(new_dir): os.makedirs(new_dir) + # We need this crusty hack because anytime a directory is created we must + # re-add it with add_watch otherwise putting files in it will not trigger + # pyinotify events + after_dir_make() shutil.move(old,new) def move_to_dir(dir_path,file_path):