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:
parent
57020b6e3b
commit
7d29379b07
|
@ -130,7 +130,7 @@ class UpgradeCommon{
|
||||||
echo "Copying configs:\n";
|
echo "Copying configs:\n";
|
||||||
foreach ($config_copy as $path_part => $destination) {
|
foreach ($config_copy as $path_part => $destination) {
|
||||||
$full_path = OsPath::normpath(OsPath::join(__DIR__,
|
$full_path = OsPath::normpath(OsPath::join(__DIR__,
|
||||||
"$path_part.$suffix"));
|
"$path_part.$suffix"));
|
||||||
echo "'$full_path' --> '$destination'\n";
|
echo "'$full_path' --> '$destination'\n";
|
||||||
if(!copy($full_path, $destination)) {
|
if(!copy($full_path, $destination)) {
|
||||||
echo "Failed on the copying operation above\n";
|
echo "Failed on the copying operation above\n";
|
||||||
|
|
|
@ -54,6 +54,10 @@ class Manager(Loggable):
|
||||||
def dummy(sender, event): self.watch_move( event.path, sender=sender )
|
def dummy(sender, event): self.watch_move( event.path, sender=sender )
|
||||||
dispatcher.connect(dummy, signal='watch_move', sender=dispatcher.Any,
|
dispatcher.connect(dummy, signal='watch_move', sender=dispatcher.Any,
|
||||||
weak=False)
|
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
|
# A private mapping path => watch_descriptor
|
||||||
# we use the same dictionary for organize, watch, store wd events.
|
# 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
|
# this is a little hacky because we are unable to have multiple wd's
|
||||||
|
|
|
@ -5,7 +5,9 @@ import media.monitor.owners as owners
|
||||||
from media.monitor.handler import ReportHandler
|
from media.monitor.handler import ReportHandler
|
||||||
from media.monitor.log import Loggable
|
from media.monitor.log import Loggable
|
||||||
from media.monitor.exceptions import BadSongFile
|
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):
|
class Organizer(ReportHandler,Loggable):
|
||||||
"""
|
"""
|
||||||
|
@ -55,7 +57,16 @@ class Organizer(ReportHandler,Loggable):
|
||||||
else self.target_path
|
else self.target_path
|
||||||
new_path = mmp.organized_path(event.path, target_path,
|
new_path = mmp.organized_path(event.path, target_path,
|
||||||
event.metadata.extract())
|
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) )
|
owners.add_file_owner(new_path, mmp.owner_id(event.path) )
|
||||||
self.logger.info('Organized: "%s" into "%s"' %
|
self.logger.info('Organized: "%s" into "%s"' %
|
||||||
(event.path, new_path))
|
(event.path, new_path))
|
||||||
|
|
|
@ -145,13 +145,17 @@ def walk_supported(directory, clean_empties=False):
|
||||||
for fp in full_paths: yield fp
|
for fp in full_paths: yield fp
|
||||||
if clean_empties: clean_empty_dirs(directory)
|
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
|
Moves path old to new and constructs the necessary to directories for new
|
||||||
along the way
|
along the way
|
||||||
"""
|
"""
|
||||||
new_dir = os.path.dirname(new)
|
new_dir = os.path.dirname(new)
|
||||||
if not os.path.exists(new_dir): os.makedirs(new_dir)
|
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)
|
shutil.move(old,new)
|
||||||
|
|
||||||
def move_to_dir(dir_path,file_path):
|
def move_to_dir(dir_path,file_path):
|
||||||
|
|
Loading…
Reference in New Issue