From 3c82497c34b8767fc5a7caa7f811db542766b19d Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Thu, 9 Aug 2012 11:37:46 -0400 Subject: [PATCH] cc-4105: reformatted bootstrap.py to fit standards --- .../media-monitor2/media/monitor/bootstrap.py | 34 +++++++++++-------- .../media/monitor/watchersyncer.py | 2 ++ 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/python_apps/media-monitor2/media/monitor/bootstrap.py b/python_apps/media-monitor2/media/monitor/bootstrap.py index e87a588b2..556d68343 100644 --- a/python_apps/media-monitor2/media/monitor/bootstrap.py +++ b/python_apps/media-monitor2/media/monitor/bootstrap.py @@ -6,8 +6,8 @@ import media.monitor.pure as mmp class Bootstrapper(Loggable): """ - Bootstrapper reads all the info in the filesystem flushes organize - events and watch events + Bootstrapper reads all the info in the filesystem flushes organize events + and watch events """ def __init__(self,db,watch_signal): """ @@ -20,16 +20,16 @@ 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 + 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_storable_paths(): self.flush_watch(d, last_ran) def flush_watch(self, directory, last_ran): """ - flush a single watch/imported directory. useful when wanting to to rescan, - or add a watched/imported directory + flush a single watch/imported directory. useful when wanting to to + rescan, or add a watched/imported directory """ songs = set([]) added = modded = deleted = 0 @@ -43,18 +43,24 @@ class Bootstrapper(Loggable): # with the filesystem if os.path.getmtime(f) > last_ran: modded += 1 - dispatcher.send(signal=self.watch_signal, sender=self, event=DeleteFile(f)) - dispatcher.send(signal=self.watch_signal, sender=self, event=NewFile(f)) - db_songs = set(( song for song in self.db.directory_get_files(directory) if mmp.sub_path(directory,song) )) + dispatcher.send(signal=self.watch_signal, sender=self, + event=DeleteFile(f)) + dispatcher.send(signal=self.watch_signal, sender=self, + event=NewFile(f)) + db_songs = set(( song for song in self.db.directory_get_files(directory) + if mmp.sub_path(directory,song) )) # Get all the files that are in the database but in the file # system. These are the files marked for deletions for to_delete in db_songs.difference(songs): - dispatcher.send(signal=self.watch_signal, sender=self, event=DeleteFile(to_delete)) + dispatcher.send(signal=self.watch_signal, sender=self, + event=DeleteFile(to_delete)) deleted += 1 for to_add in songs.difference(db_songs): - dispatcher.send(signal=self.watch_signal, sender=self, event=NewFile(to_add)) + dispatcher.send(signal=self.watch_signal, sender=self, + event=NewFile(to_add)) added += 1 - self.logger.info( "Flushed watch directory (%s). (added, modified, deleted) = (%d, %d, %d)" - % (directory, added, modded, deleted) ) + self.logger.info( "Flushed watch directory (%s). \ + (added, modified, deleted) = (%d, %d, %d)" + % (directory, added, modded, deleted) ) diff --git a/python_apps/media-monitor2/media/monitor/watchersyncer.py b/python_apps/media-monitor2/media/monitor/watchersyncer.py index ee8223c17..41584e812 100644 --- a/python_apps/media-monitor2/media/monitor/watchersyncer.py +++ b/python_apps/media-monitor2/media/monitor/watchersyncer.py @@ -184,6 +184,8 @@ class WatchSyncer(ReportHandler,Loggable): self.__requests.append(launch_request) self.__queue = [] + + def __del__(self): # Ideally we would like to do a little more to ensure safe shutdown if self.events_in_queue():