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.
This commit is contained in:
Rudi Grinberg 2012-08-27 16:48:39 -04:00
parent 57020b6e3b
commit 7d29379b07
4 changed files with 23 additions and 4 deletions

View File

@ -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

View File

@ -6,6 +6,8 @@ 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 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))

View File

@ -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):