cc-4105: added handling for recorded files

This commit is contained in:
Rudi Grinberg 2012-08-02 12:09:58 -04:00
parent 01c44e32d1
commit 6e2e7d83ad
5 changed files with 20 additions and 9 deletions

View File

@ -58,7 +58,6 @@ class AirtimeNotifier(Loggable):
m = json.loads(message.body)
self.handler.message(m)
class AirtimeMessageReceiver(Loggable):
def __init__(self, cfg, manager):
self.dispatch_table = {

View File

@ -53,8 +53,8 @@ class Bootstrapper(Loggable):
dispatcher.send(signal=self.watch_signal, sender=self, event=DeleteFile(to_delete))
deleted += 1
for to_add in songs.difference(db_songs):
if len(songs.difference(db_songs)) > 100:
import ipdb; ipdb.set_trace()
#if len(songs.difference(db_songs)) > 100:
#import ipdb; ipdb.set_trace()
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)"

View File

@ -58,13 +58,13 @@ class Manager(Loggable):
proc_fun=listener)
self.__wd_path[path] = wd.values()[0]
def __create_organizer(self, target_path):
def __create_organizer(self, target_path, recorded_path):
"""
private constructor for organizer so that we don't have to repeat
adding the channel/signal as a parameter to the original constructor
every time
"""
return Organizer(channel=self.organize_channel,target_path=target_path)
return Organizer(channel=self.organize_channel,target_path=target_path, recorded_path=recorded_path)
def get_problem_files_path(self):
return self.organize['problem_files_path']
@ -79,6 +79,7 @@ class Manager(Loggable):
def set_recorded_path(self, new_path):
self.__remove_watch(self.organize['recorded_path'])
self.organize['recorded_path'] = new_path
self.organize['organizer'] = self.__create_organizer(self.organize['imported_path'], new_path)
self.__add_watch(new_path, self.watch_listener)
def get_organize_path(self):
@ -106,11 +107,11 @@ class Manager(Loggable):
def set_imported_path(self,new_path):
"""
set the directory where organized files go to
set the directory where organized files go to.
"""
self.__remove_watch(self.organize['imported_path'])
self.organize['imported_path'] = new_path
self.organize['organizer'] = self.__create_organizer(new_path)
self.organize['organizer'] = self.__create_organizer(new_path, self.organize['recorded_path'])
self.__add_watch(new_path, self.watch_listener)
def change_storage_root(self, store):

View File

@ -92,6 +92,9 @@ def truncate_to_length(item, length):
else: return item
class Metadata(Loggable):
# TODO : refactor the way metadata is being handled. Right now things are a
# little bit messy. Some of the handling is in m.m.pure while the rest is
# here. Also interface is not very consistent
@staticmethod
def write_unsafe(path,md):
@ -146,6 +149,9 @@ class Metadata(Loggable):
# Now we must load the md5:
self.__metadata['MDATA_KEY_MD5'] = mmp.file_md5(fpath)
def is_recorded(self):
return mmp.is_airtime_recorded( self.__metadata )
def extract(self):
return copy.deepcopy(self.__metadata)

View File

@ -13,9 +13,10 @@ class Organizer(ReportHandler,Loggable):
directory". The "storage" directory picks up all of its events through
pyinotify. (These events are fed to it through StoreWatchListener)
"""
def __init__(self, channel, target_path):
def __init__(self, channel, target_path, recorded_path):
self.channel = channel
self.target_path = target_path
self.recorded_path = recorded_path
super(Organizer, self).__init__(signal=self.channel)
def handle(self, sender, event):
"""
@ -23,7 +24,11 @@ class Organizer(ReportHandler,Loggable):
directory and place it in the correct path (starting with self.target_path)
"""
try:
new_path = mmp.organized_path(event.path, self.target_path, event.metadata.extract())
# We must select the target_path based on whether file was recorded
# by airtime or not.
# Do we need to "massage" the path using mmp.organized_path?
target_path = self.recorded_path if event.metadata.is_recorded() else self.target_path
new_path = mmp.organized_path(event.path, target_path, event.metadata.extract())
mmp.magic_move(event.path, new_path)
self.logger.info('Organized: "%s" into "%s"' % (event.path, new_path))
except BadSongFile as e: