diff --git a/python_apps/media-monitor2/media/monitor/bootstrap.py b/python_apps/media-monitor2/media/monitor/bootstrap.py index 65c12afde..507bc7230 100644 --- a/python_apps/media-monitor2/media/monitor/bootstrap.py +++ b/python_apps/media-monitor2/media/monitor/bootstrap.py @@ -21,6 +21,8 @@ class Bootstrapper(Loggable): def flush_all(self, last_ran): """ bootstrap every single watched directory. only useful at startup + note that because of the way list_directories works we also flush + the import directory as well I think """ for d in self.db.list_directories(): self.flush_watch(d, last_ran) diff --git a/python_apps/media-monitor2/media/monitor/manager.py b/python_apps/media-monitor2/media/monitor/manager.py index 67e2a1ec4..cb6949176 100644 --- a/python_apps/media-monitor2/media/monitor/manager.py +++ b/python_apps/media-monitor2/media/monitor/manager.py @@ -10,6 +10,7 @@ class Manager(Loggable): adding watched,store, organize directories, etc. Basically composes over WatchManager from pyinotify """ + global_inst = None all_signals = set(['add_watch', 'remove_watch']) def __init__(self): self.wm = pyinotify.WatchManager() @@ -35,7 +36,7 @@ class Manager(Loggable): # The following set isn't really necessary anymore. should be # removed... self.watched_directories = set([]) - + Manager.global_inst = self def watch_signal(self): return self.watch_listener.self.signal diff --git a/python_apps/media-monitor2/media/monitor/organizer.py b/python_apps/media-monitor2/media/monitor/organizer.py index fd02ead83..e70160359 100644 --- a/python_apps/media-monitor2/media/monitor/organizer.py +++ b/python_apps/media-monitor2/media/monitor/organizer.py @@ -7,7 +7,7 @@ from media.monitor.exceptions import BadSongFile class Organizer(ReportHandler,Loggable): """ - Organizer is responsible to to lisenting to OrganizeListener events and + Organizer is responsible to to listening to OrganizeListener events and committing the appropriate changes to the filesystem. It does not in any interact with WatchSyncer's even when the the WatchSyncer is a "storage directory". The "storage" directory picks up all of its events through diff --git a/python_apps/media-monitor2/media/monitor/syncdb.py b/python_apps/media-monitor2/media/monitor/syncdb.py index 840998bd1..87effb4b8 100644 --- a/python_apps/media-monitor2/media/monitor/syncdb.py +++ b/python_apps/media-monitor2/media/monitor/syncdb.py @@ -6,6 +6,7 @@ class SyncDB(Loggable): def __init__(self, apc): self.apc = apc dirs = self.apc.list_all_watched_dirs() + directories = None try: directories = dirs['dirs'] @@ -19,9 +20,23 @@ class SyncDB(Loggable): # Just in case anybody wants to lookup a directory by its id we haev self.id_lookup = directories + def reload_directories(self): + # dirs_setup is a dict with keys: + # u'watched_dirs' and u'stor' which point to lists of corresponding + # dirs + dirs_setup = self.apc.setup_media_monitor() + self.base_storage = dirs_setup[u'stor'] + self.watched_directories = set(dirs_setup[u'watched_dirs']) + + def organize_path(self): return os.path.join(self.base_storage, 'organize') + def problem_path(self): return os.path.join(self.base_storage, 'problem_files') + def import_path(self): return os.path.join(self.base_storage, 'imported') + def recorded_path(self): return os.path.join(self.base_storage, 'recorded') + def list_directories(self): """ returns a list of all the watched directories in the datatabase. + (Includes the imported directory) """ return self.directories.keys() diff --git a/python_apps/media-monitor2/mm2.py b/python_apps/media-monitor2/mm2.py index 487815238..6aad8c123 100644 --- a/python_apps/media-monitor2/mm2.py +++ b/python_apps/media-monitor2/mm2.py @@ -65,14 +65,13 @@ sdb = SyncDB(apiclient) manager = Manager() store = apiclient.setup_media_monitor() -store = store[u'stor'] - -organize_dir, import_dir = mmp.import_organize(store) +organize_dir, import_dir = mmp.import_organize(store[u'stor']) # Order matters here: +# TODO : add flushing manager.set_store_path(import_dir) manager.set_organize_path(organize_dir) -for watch_dir in sdb.list_directories(): +for watch_dir in store[u'watched_dirs']: if not os.path.exists(watch_dir): # Create the watch_directory here try: os.makedirs(watch_dir)