cc-4105: slightly improved handling of paths

This commit is contained in:
Rudi Grinberg 2012-07-31 12:06:18 -04:00
parent 9d5f50d1f8
commit ad12926af2
5 changed files with 23 additions and 6 deletions

View File

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

View File

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

View File

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

View File

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

View File

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