Merge branch 'devel' of dev.sourcefabric.org:airtime into devel

This commit is contained in:
james 2011-07-06 13:56:51 -04:00
commit f8b8a6bada
5 changed files with 36 additions and 16 deletions

View file

@ -133,6 +133,10 @@ class LibraryController extends Zend_Controller_Action
$this->view->message = "file doesn't exist"; $this->view->message = "file doesn't exist";
return; return;
} }
$data = array("filepath"=>$file->getFilePath());
RabbitMq::SendMessageToMediaMonitor("file_delete", $data);
$res = $file->delete(); $res = $file->delete();

View file

@ -102,11 +102,10 @@ class MusicDir {
->findOne(); ->findOne();
$mus_dir = new MusicDir($dir); $mus_dir = new MusicDir($dir);
$mus_dir->_dir = $dir;
return $mus_dir; return $mus_dir;
} }
public static function setStorDir($p_dir) public static function setStorDir($p_dir)
{ {
$dir = self::getStorDir(); $dir = self::getStorDir();

View file

@ -813,6 +813,8 @@ class StoredFile {
$storDir = MusicDir::getStorDir(); $storDir = MusicDir::getStorDir();
$stor = $storDir->getDirectory(); $stor = $storDir->getDirectory();
$stor .= "/organize";
$audio_stor = $stor . DIRECTORY_SEPARATOR . $fileName; $audio_stor = $stor . DIRECTORY_SEPARATOR . $fileName;
$r = @copy($audio_file, $audio_stor); $r = @copy($audio_file, $audio_stor);

View file

@ -104,6 +104,12 @@ class AirtimeNotifier(Notifier):
self.config.storage_directory = new_storage_directory self.config.storage_directory = new_storage_directory
mm.watch_directory(new_storage_directory) mm.watch_directory(new_storage_directory)
elif m['event_type'] == "file_delete":
self.logger.info("Deleting file: %s ", m['filepath'])
mm = self.proc_fun()
mm.add_filepath_to_ignore(m['filepath'])
os.unlink(m['filepath'])
#update airtime with information about files discovered in our #update airtime with information about files discovered in our

View file

@ -29,6 +29,12 @@ class AirtimeProcessEvent(ProcessEvent):
self.logger = logging.getLogger() self.logger = logging.getLogger()
self.config = airtime_config self.config = airtime_config
#put the file path into this dict if we want to ignore certain
#events. For example, when deleting a file from the web ui, we
#are going to delete it on the server side, so media-monitor doesn't
#need to contact the server and tell it to delete again.
self.ignore_event = set()
self.supported_file_formats = ['mp3', 'ogg'] self.supported_file_formats = ['mp3', 'ogg']
self.temp_files = {} self.temp_files = {}
self.renamed_files = {} self.renamed_files = {}
@ -42,6 +48,9 @@ class AirtimeProcessEvent(ProcessEvent):
self.mask = pyinotify.ALL_EVENTS self.mask = pyinotify.ALL_EVENTS
self.wm = wm self.wm = wm
self.md_manager = AirtimeMetadata() self.md_manager = AirtimeMetadata()
def add_filepath_to_ignore(self, filepath):
self.ignore_event.add(filepath)
#define which directories the pyinotify WatchManager should watch. #define which directories the pyinotify WatchManager should watch.
def watch_directory(self, directory): def watch_directory(self, directory):
@ -202,7 +211,6 @@ class AirtimeProcessEvent(ProcessEvent):
else: else:
filepath = '%s/%s/%s/%s/%s-%s-%s%s' % (storage_directory, "imported".encode('utf-8'), md['MDATA_KEY_CREATOR'], md['MDATA_KEY_SOURCE'], md['MDATA_KEY_TRACKNUMBER'], md['MDATA_KEY_TITLE'], md['MDATA_KEY_BITRATE'], file_ext) filepath = '%s/%s/%s/%s/%s-%s-%s%s' % (storage_directory, "imported".encode('utf-8'), md['MDATA_KEY_CREATOR'], md['MDATA_KEY_SOURCE'], md['MDATA_KEY_TRACKNUMBER'], md['MDATA_KEY_TITLE'], md['MDATA_KEY_BITRATE'], file_ext)
self.logger.info('Created filepath: %s', filepath)
filepath = self.create_unique_filename(filepath, original_path) filepath = self.create_unique_filename(filepath, original_path)
self.logger.info('Unique filepath: %s', filepath) self.logger.info('Unique filepath: %s', filepath)
self.ensure_is_dir(filepath) self.ensure_is_dir(filepath)
@ -216,24 +224,19 @@ class AirtimeProcessEvent(ProcessEvent):
#event.name: filename #event.name: filename
#event.pathname: pathname (str): Concatenation of 'path' and 'name'. #event.pathname: pathname (str): Concatenation of 'path' and 'name'.
def process_IN_CREATE(self, event): def process_IN_CREATE(self, event):
self.logger.debug("PROCESS_IN_CREATE: %s", event)
self.handle_created_file(event.dir, event.name, event.pathname) self.handle_created_file(event.dir, event.name, event.pathname)
def handle_created_file(self, dir, name, pathname): def handle_created_file(self, dir, name, pathname):
self.logger.debug("dir: %s, name: %s, pathname: %s ", dir, name, pathname)
storage_directory = self.config.storage_directory
organize_directory = self.config.organize_directory
if not dir: if not dir:
self.logger.debug("PROCESS_IN_CREATE: %s, name: %s, pathname: %s ", dir, name, pathname)
#event is because of a created file #event is because of a created file
if self.is_temp_file(name) : if self.is_temp_file(name) :
#file created is a tmp file which will be modified and then moved back to the original filename. #file created is a tmp file which will be modified and then moved back to the original filename.
self.temp_files[pathname] = None self.temp_files[pathname] = None
elif self.is_audio_file(pathname): elif self.is_audio_file(pathname):
if self.is_parent_directory(pathname, organize_directory): if self.is_parent_directory(pathname, self.config.organize_directory):
#file was created in /srv/airtime/stor/organize. Need to process and move #file was created in /srv/airtime/stor/organize. Need to process and move
#to /srv/airtime/stor/imported #to /srv/airtime/stor/imported
self.set_needed_file_permissions(pathname, dir)
self.organize_new_file(pathname) self.organize_new_file(pathname)
else: else:
self.set_needed_file_permissions(pathname, dir) self.set_needed_file_permissions(pathname, dir)
@ -241,7 +244,7 @@ class AirtimeProcessEvent(ProcessEvent):
else: else:
#event is because of a created directory #event is because of a created directory
if self.is_parent_directory(pathname, storage_directory): if self.is_parent_directory(pathname, self.config.storage_directory):
self.set_needed_file_permissions(pathname, dir) self.set_needed_file_permissions(pathname, dir)
@ -253,6 +256,8 @@ class AirtimeProcessEvent(ProcessEvent):
#is_recorded_show = 'MDATA_KEY_CREATOR' in file_md and \ #is_recorded_show = 'MDATA_KEY_CREATOR' in file_md and \
# file_md['MDATA_KEY_CREATOR'] == "AIRTIMERECORDERSOURCEFABRIC".encode('utf-8') # file_md['MDATA_KEY_CREATOR'] == "AIRTIMERECORDERSOURCEFABRIC".encode('utf-8')
filepath = self.create_file_path(pathname, file_md) filepath = self.create_file_path(pathname, file_md)
self.logger.debug("Moving from %s to %s", pathname, filepath)
self.move_file(pathname, filepath) self.move_file(pathname, filepath)
else: else:
self.logger.warn("File %s, has invalid metadata", pathname) self.logger.warn("File %s, has invalid metadata", pathname)
@ -274,8 +279,10 @@ class AirtimeProcessEvent(ProcessEvent):
def process_IN_MOVED_FROM(self, event): def process_IN_MOVED_FROM(self, event):
self.logger.info("process_IN_MOVED_FROM: %s", event) self.logger.info("process_IN_MOVED_FROM: %s", event)
if not event.dir: if not event.dir:
if self.is_audio_file(event.name): if not self.is_parent_directory(event.pathname, self.config.organize_directory):
self.cookies_IN_MOVED_FROM[event.cookie] = (event, time.time()) #we don't care about moved_from events from the organize dir.
if self.is_audio_file(event.name):
self.cookies_IN_MOVED_FROM[event.cookie] = (event, time.time())
def process_IN_MOVED_TO(self, event): def process_IN_MOVED_TO(self, event):
self.logger.info("process_IN_MOVED_TO: %s", event) self.logger.info("process_IN_MOVED_TO: %s", event)
@ -304,8 +311,10 @@ class AirtimeProcessEvent(ProcessEvent):
def handle_removed_file(self, dir, pathname): def handle_removed_file(self, dir, pathname):
self.logger.info("Deleting %s", pathname) self.logger.info("Deleting %s", pathname)
if not dir: if not dir:
if self.is_audio_file(event.name): if self.is_audio_file(pathname):
if not self.is_parent_directory(pathname, self.config.organize_directory): if pathname in self.ignore_event:
self.ignore_event.remove(pathname)
elif not self.is_parent_directory(pathname, self.config.organize_directory):
#we don't care if a file was deleted from the organize directory. #we don't care if a file was deleted from the organize directory.
self.file_events.append({'filepath': pathname, 'mode': self.config.MODE_DELETE}) self.file_events.append({'filepath': pathname, 'mode': self.config.MODE_DELETE})