CC-2272: Ability to change storage directory location

-done
This commit is contained in:
martin 2011-07-06 14:42:43 -04:00
parent eaba145d6d
commit 67df619c90
6 changed files with 31 additions and 18 deletions

View File

@ -128,8 +128,10 @@ class PreferenceController extends Zend_Controller_Action
if ($bool === true) {
MusicDir::setStorDir($chosen);
$dirId = MusicDir::getStorDir()->getId();
$data = array();
$data["directory"] = $chosen;
$data["dir_id"] = $dirId;
RabbitMq::SendMessageToMediaMonitor("change_stor", $data);
}

View File

@ -43,7 +43,7 @@ function setWatchedDirEvents() {
$('#storageFolder-ok').click(function(){
var url, chosen;
if(confirm("Are you sure you want to change the storage folder?")){
if(confirm("Are you sure you want to change the storage folder?\nThis will remove the files from your Airtime library!")){
url = "/Preference/change-stor-directory";
chosen = $('#storageFolder').val();

View File

@ -63,12 +63,12 @@ try:
wm = WatchManager()
pe = AirtimeProcessEvent(queue=multi_queue, airtime_config=config, wm=wm)
notifier = AirtimeNotifier(wm, pe, read_freq=1, timeout=0, airtime_config=config, api_client=api_client)
notifier.coalesce_events()
bootstrap = AirtimeMediaMonitorBootstrap(logger, multi_queue, pe, config)
bootstrap = AirtimeMediaMonitorBootstrap(logger, multi_queue, pe, api_client)
bootstrap.scan()
notifier = AirtimeNotifier(wm, pe, read_freq=1, timeout=0, airtime_config=config, api_client=api_client, bootstrap=bootstrap)
notifier.coalesce_events()
#create 5 worker processes
wp = MediaMonitorWorkerProcess()
for i in range(5):

View File

@ -2,19 +2,15 @@ import os
import time
from subprocess import Popen, PIPE
from api_clients import api_client
class AirtimeMediaMonitorBootstrap():
def __init__(self, logger, multi_queue, pe, config):
def __init__(self, logger, multi_queue, pe, api_client):
self.logger = logger
self.multi_queue = multi_queue
self.pe = pe
self.airtime_tmp = '/var/tmp/airtime'
self.config = config
self.api_client = api_client.api_client_factory(self.config.cfg)
self.api_client = api_client
"""
on bootup we want to scan all directories and look for files that

View File

@ -15,12 +15,13 @@ from airtimemetadata import AirtimeMetadata
class AirtimeNotifier(Notifier):
def __init__(self, watch_manager, default_proc_fun=None, read_freq=0, threshold=0, timeout=None, airtime_config=None, api_client=None):
def __init__(self, watch_manager, default_proc_fun=None, read_freq=0, threshold=0, timeout=None, airtime_config=None, api_client=None, bootstrap=None):
Notifier.__init__(self, watch_manager, default_proc_fun, read_freq, threshold, timeout)
self.logger = logging.getLogger()
self.config = airtime_config
self.api_client = api_client
self.bootstrap = bootstrap
self.md_manager = AirtimeMetadata()
self.import_processes = {}
self.watched_folders = []
@ -84,6 +85,7 @@ class AirtimeNotifier(Notifier):
elif m['event_type'] == "change_stor":
storage_directory = self.config.storage_directory
new_storage_directory = m['directory'].encode('utf-8')
new_storage_directory_id = str(m['dir_id']).encode('utf-8')
mm = self.proc_fun()
@ -93,17 +95,25 @@ class AirtimeNotifier(Notifier):
mm.set_needed_file_permissions(new_storage_directory, True)
#move everything in old stor directory to the new stor directory.
self.bootstrap.check_for_diff(new_storage_directory_id, new_storage_directory)
self.config.storage_directory = new_storage_directory
self.config.imported_directory = new_storage_directory + '/imported'
self.config.organize_directory = new_storage_directory + '/organize'
mm.watch_directory(new_storage_directory)
"""
old_storage_contents = os.listdir(storage_directory)
for item in old_storage_contents:
fp = "%s/%s" % (storage_directory, item)
nfp = "%s/%s" % (new_storage_directory, item)
self.logger.info("Moving %s to %s", fp, nfp)
mm.move_file(fp, nfp)
self.config.storage_directory = new_storage_directory
mm.watch_directory(new_storage_directory)
"""
elif m['event_type'] == "file_delete":
self.logger.info("Deleting file: %s ", m['filepath'])

View File

@ -284,6 +284,11 @@ class AirtimeProcessEvent(ProcessEvent):
if self.is_audio_file(event.name):
self.cookies_IN_MOVED_FROM[event.cookie] = (event, time.time())
#Some weird thing to note about this event: it seems that if a file is moved to a newly
#created directory, then the IN_MOVED_FROM event will be called, but instead of a corresponding
#IN_MOVED_TO event, a IN_CREATED event will happen instead. However if the directory existed before
#then the IN_MOVED_TO event will be called.
def process_IN_MOVED_TO(self, event):
self.logger.info("process_IN_MOVED_TO: %s", event)
#if stuff dropped in stor via a UI move must change file permissions.