cc-4105: refactored a few routines, added more comments

This commit is contained in:
Rudi Grinberg 2012-07-25 15:13:04 -04:00
parent b3fea71916
commit 6214ac961d
6 changed files with 30 additions and 30 deletions

View File

@ -4,7 +4,7 @@ from kombu.connection import BrokerConnection
import json
import copy
from media.monitor.exception import BadSongFile
from media.monitor.exceptions import BadSongFile
from media.monitor.metadata import Metadata
from media.monitor.log import Loggable
@ -98,6 +98,7 @@ class AirtimeMessageReceiver(Loggable):
except Exception as e:
# TODO : add md_path to problem path or something?
self.logger.info("Unknown error when writing metadata to: '%s'" % md_path)
def new_watch(self, msg):
# TODO : add new watched directory by bootstrapping it with an empty
# database?
@ -108,6 +109,8 @@ class AirtimeMessageReceiver(Loggable):
# TODO : basically a bootstrap on the directory
pass
def change_storage(self, msg):
pass
new_storage_directory = msg['directory']
new_storage_directory_id = str(msg['dir_id'])
def file_delete(self, msg):
pass

View File

@ -1,6 +1,6 @@
import os
from pydispatch import dispatcher
from media.monitor.events import OrganizeFile, NewFile, DeleteFile
from media.monitor.events import NewFile, DeleteFile
from media.monitor.log import Loggable
import media.monitor.pure as mmp
@ -15,18 +15,6 @@ class Bootstrapper(Loggable):
self.watch_channels = watch_channels
self.last_ran = last_ran
def flush_organize(self):
"""
walks the organize directories and sends an organize event for every file manually
"""
flushed = 0
for pc in self.org_channels:
for f in mmp.walk_supported(pc.path, clean_empties=True):
self.logger.info("Bootstrapping: File in 'organize' directory: '%s'" % f)
dispatcher.send(signal=pc.signal, sender=self, event=OrganizeFile(f))
flushed += 1
self.logger.info("Flushed organized directory with %d files" % flushed)
def flush_watch(self):
"""
Syncs the file system into the database. Walks over deleted/new/modified files since

View File

@ -5,6 +5,7 @@ from pydispatch import dispatcher
import media.monitor.pure as mmp
from media.monitor.pure import IncludeOnly
from media.monitor.events import OrganizeFile, NewFile, DeleteFile
from media.monitor.log import Loggable
# We attempt to document a list of all special cases and hacks that the
# following classes should be able to handle.
@ -26,19 +27,17 @@ from media.monitor.events import OrganizeFile, NewFile, DeleteFile
# signature?. Of course that's not possible for some modification events
# because the md5 signature will change...
# Note: Because of the way classes that inherit from pyinotify.ProcessEvent
# interact with constructors. you should only instantiate objects from them
# using keyword arguments. For example:
# Wrong: OrganizeListener('watch_signal') <= wrong
# Right: OrganizeListener(signal='watch_signal') <= right
# OrganizeListener('watch_signal') <= wrong
# OrganizeListener(signal='watch_signal') <= right
class BaseListener(object):
def my_init(self, signal):
self.signal = signal
class OrganizeListener(BaseListener, pyinotify.ProcessEvent):
class OrganizeListener(BaseListener, pyinotify.ProcessEvent, Loggable):
# this class still don't handle the case where a dir was copied recursively
def process_IN_CLOSE_WRITE(self, event): self.process_to_organize(event)
@ -48,14 +47,18 @@ class OrganizeListener(BaseListener, pyinotify.ProcessEvent):
def flush_events(self, path):
"""organize the whole directory at path. (pretty much by doing what
handle does to every file"""
# TODO : implement me
pass
flushed = 0
for f in mmp.walk_supported(path, clean_empties=True):
self.logger.info("Bootstrapping: File in 'organize' directory: '%s'" % f)
dispatcher.send(signal=self.signal, sender=self, event=OrganizeFile(f))
flushed += 1
self.logger.info("Flushed organized directory with %d files" % flushed)
@IncludeOnly(mmp.supported_extensions)
def process_to_organize(self, event):
dispatcher.send(signal=self.signal, sender=self, event=OrganizeFile(event))
class StoreWatchListener(BaseListener, pyinotify.ProcessEvent):
class StoreWatchListener(BaseListener, Loggable, pyinotify.ProcessEvent):
def process_IN_CLOSE_WRITE(self, event): self.process_create(event)
def process_IN_MOVED_TO(self, event): self.process_create(event)
@ -72,9 +75,15 @@ class StoreWatchListener(BaseListener, pyinotify.ProcessEvent):
def flush_events(self, path):
"""
walk over path and send a NewFile event for every file in this directory
walk over path and send a NewFile event for every file in this directory.
Not to be confused with bootstrapping which is a more careful process that
involved figuring out what's in the database first.
"""
# TODO : implement me
pass
# Songs is a dictionary where every key is the watched the directory
# and the value is a set with all the files in that directory.
added = 0
for f in mmp.walk_supported(path, clean_empties=False):
added += 1
dispatcher.send(signal=self.signal, sender=self, event=NewFile(f))
self.logger.info( "Flushed watch directory. added = %d" % added )

View File

@ -128,7 +128,7 @@ class Manager(Loggable):
self.__remove_watch(watch_dir)
else:
self.logger.info("'%s' is not being watched, hence cannot be removed"
% watch_dir)
% watch_dir)
def loop(self):
"""

View File

@ -37,6 +37,6 @@ class SyncDB(Loggable):
"""
returns all the files given some dir_id. this method is here for "symmetry". it's not actually used anywhere
"""
return self.directory_get_files(self.id_get_files[dir_id])
return self.directory_get_files(self.id_lookup[dir_id])

View File

@ -19,7 +19,7 @@ class RequestSync(threading.Thread,Loggable):
@LazyProperty
def apiclient(self):
return ac.AirTimeApiClient()
return ac.AirtimeApiClient()
def run(self):
# TODO : implement proper request sending