cc-4105: more refactorings, this time so that scan/watch diretories are always handled from one place

This commit is contained in:
Rudi Grinberg 2012-08-01 15:10:54 -04:00
parent 3b1583f620
commit ba78731f99
6 changed files with 83 additions and 62 deletions

View file

@ -1,8 +1,11 @@
import pyinotify
from media.monitor.events import PathChannel
from media.monitor.log import Loggable
from media.monitor.listeners import StoreWatchListener, OrganizeListener
from media.monitor.handler import ProblemFileHandler
from media.monitor.organizer import Organizer
import media.monitor.pure as mmp
class Manager(Loggable):
"""
@ -20,13 +23,16 @@ class Manager(Loggable):
self.watch_listener = StoreWatchListener(signal=self.watch_channel)
self.organize = {
'organize_path' : None,
'store_path' : None,
'imported_path' : None,
'recorded_path' : None,
'problem_files_path' : None,
# This guy doesn't need to be changed, always the same.
# Gets hooked by wm to different directories
'organize_listener' : OrganizeListener(signal=self.organize_channel),
# Also stays the same as long as its target, the directory
# which the "organized" files go to, isn't changed.
'organizer' : None,
'problem_handler' : None,
}
# A private mapping path => watch_descriptor
# we use the same dictionary for organize, watch, store wd events.
@ -60,6 +66,21 @@ class Manager(Loggable):
"""
return Organizer(channel=self.organize_channel,target_path=target_path)
def get_problem_files_path(self):
return self.organize['problem_files_path']
def set_problem_files_path(self, new_path):
self.organize['problem_files_path'] = new_path
self.organize['problem_handler'] = ProblemFileHandler( PathChannel(signal='badfile',path=new_path) )
def get_recorded_path(self):
return self.organize['recorded_path']
def set_recorded_path(self, new_path):
self.__remove_watch(self.organize['recorded_path'])
self.organize['recorded_path'] = new_path
self.__add_watch(new_path, self.watch_listener)
def get_organize_path(self):
"""
returns the current path that is being watched for organization
@ -80,20 +101,15 @@ class Manager(Loggable):
self.organize['organize_listener'].flush_events(new_path)
self.__add_watch(new_path, self.organize['organize_listener'])
organize_path = property(get_organize_path, set_organize_path)
def get_imported_path(self):
return self.organize['imported_path']
def get_store_path(self):
"""
returns the store_path (should be accessed through the property usually)
"""
return self.organize['store_path']
def set_store_path(self,new_path):
def set_imported_path(self,new_path):
"""
set the directory where organized files go to
"""
self.__remove_watch(self.organize['store_path'])
self.organize['store_path'] = new_path
self.__remove_watch(self.organize['imported_path'])
self.organize['imported_path'] = new_path
self.organize['organizer'] = self.__create_organizer(new_path)
# flush all the files in the new store_directory. this is done so that
# new files are added to the database. Note that we are not responsible
@ -102,7 +118,18 @@ class Manager(Loggable):
# self.watch_listener.flush_events(new_path)
self.__add_watch(new_path, self.watch_listener)
store_path = property(get_store_path, set_store_path)
def change_storage_root(self, store):
"""
hooks up all the directories for you. Problem, recorded, imported, organize.
"""
store_paths = mmp.expand_storage(store)
self.set_problem_files_path(store_paths['problem_files'])
self.set_imported_path(store_paths['imported'])
self.set_recorded_path(store_paths['recorded'])
self.set_organize_path(store_paths['organize'])
mmp.create_dir(store)
for p in store_paths.values():
mmp.create_dir(p)
def has_watch(self, path):
"""