cc-4105: slightly improved handling of paths
This commit is contained in:
parent
9d5f50d1f8
commit
ad12926af2
|
@ -21,6 +21,8 @@ class Bootstrapper(Loggable):
|
||||||
def flush_all(self, last_ran):
|
def flush_all(self, last_ran):
|
||||||
"""
|
"""
|
||||||
bootstrap every single watched directory. only useful at startup
|
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():
|
for d in self.db.list_directories():
|
||||||
self.flush_watch(d, last_ran)
|
self.flush_watch(d, last_ran)
|
||||||
|
|
|
@ -10,6 +10,7 @@ class Manager(Loggable):
|
||||||
adding watched,store, organize directories, etc. Basically composes over
|
adding watched,store, organize directories, etc. Basically composes over
|
||||||
WatchManager from pyinotify
|
WatchManager from pyinotify
|
||||||
"""
|
"""
|
||||||
|
global_inst = None
|
||||||
all_signals = set(['add_watch', 'remove_watch'])
|
all_signals = set(['add_watch', 'remove_watch'])
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.wm = pyinotify.WatchManager()
|
self.wm = pyinotify.WatchManager()
|
||||||
|
@ -35,7 +36,7 @@ class Manager(Loggable):
|
||||||
# The following set isn't really necessary anymore. should be
|
# The following set isn't really necessary anymore. should be
|
||||||
# removed...
|
# removed...
|
||||||
self.watched_directories = set([])
|
self.watched_directories = set([])
|
||||||
|
Manager.global_inst = self
|
||||||
|
|
||||||
def watch_signal(self):
|
def watch_signal(self):
|
||||||
return self.watch_listener.self.signal
|
return self.watch_listener.self.signal
|
||||||
|
|
|
@ -7,7 +7,7 @@ from media.monitor.exceptions import BadSongFile
|
||||||
|
|
||||||
class Organizer(ReportHandler,Loggable):
|
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
|
committing the appropriate changes to the filesystem. It does not in any
|
||||||
interact with WatchSyncer's even when the the WatchSyncer is a "storage
|
interact with WatchSyncer's even when the the WatchSyncer is a "storage
|
||||||
directory". The "storage" directory picks up all of its events through
|
directory". The "storage" directory picks up all of its events through
|
||||||
|
|
|
@ -6,6 +6,7 @@ class SyncDB(Loggable):
|
||||||
def __init__(self, apc):
|
def __init__(self, apc):
|
||||||
self.apc = apc
|
self.apc = apc
|
||||||
dirs = self.apc.list_all_watched_dirs()
|
dirs = self.apc.list_all_watched_dirs()
|
||||||
|
|
||||||
directories = None
|
directories = None
|
||||||
try:
|
try:
|
||||||
directories = dirs['dirs']
|
directories = dirs['dirs']
|
||||||
|
@ -19,9 +20,23 @@ class SyncDB(Loggable):
|
||||||
# Just in case anybody wants to lookup a directory by its id we haev
|
# Just in case anybody wants to lookup a directory by its id we haev
|
||||||
self.id_lookup = directories
|
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):
|
def list_directories(self):
|
||||||
"""
|
"""
|
||||||
returns a list of all the watched directories in the datatabase.
|
returns a list of all the watched directories in the datatabase.
|
||||||
|
(Includes the imported directory)
|
||||||
"""
|
"""
|
||||||
return self.directories.keys()
|
return self.directories.keys()
|
||||||
|
|
||||||
|
|
|
@ -65,14 +65,13 @@ sdb = SyncDB(apiclient)
|
||||||
manager = Manager()
|
manager = Manager()
|
||||||
|
|
||||||
store = apiclient.setup_media_monitor()
|
store = apiclient.setup_media_monitor()
|
||||||
store = store[u'stor']
|
organize_dir, import_dir = mmp.import_organize(store[u'stor'])
|
||||||
|
|
||||||
organize_dir, import_dir = mmp.import_organize(store)
|
|
||||||
# Order matters here:
|
# Order matters here:
|
||||||
|
# TODO : add flushing
|
||||||
manager.set_store_path(import_dir)
|
manager.set_store_path(import_dir)
|
||||||
manager.set_organize_path(organize_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):
|
if not os.path.exists(watch_dir):
|
||||||
# Create the watch_directory here
|
# Create the watch_directory here
|
||||||
try: os.makedirs(watch_dir)
|
try: os.makedirs(watch_dir)
|
||||||
|
|
Loading…
Reference in New Issue