CC-2272: Ability to change storage directory location
-done
This commit is contained in:
parent
eaba145d6d
commit
67df619c90
|
@ -128,8 +128,10 @@ class PreferenceController extends Zend_Controller_Action
|
||||||
|
|
||||||
if ($bool === true) {
|
if ($bool === true) {
|
||||||
MusicDir::setStorDir($chosen);
|
MusicDir::setStorDir($chosen);
|
||||||
|
$dirId = MusicDir::getStorDir()->getId();
|
||||||
$data = array();
|
$data = array();
|
||||||
$data["directory"] = $chosen;
|
$data["directory"] = $chosen;
|
||||||
|
$data["dir_id"] = $dirId;
|
||||||
RabbitMq::SendMessageToMediaMonitor("change_stor", $data);
|
RabbitMq::SendMessageToMediaMonitor("change_stor", $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ function setWatchedDirEvents() {
|
||||||
$('#storageFolder-ok').click(function(){
|
$('#storageFolder-ok').click(function(){
|
||||||
var url, chosen;
|
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";
|
url = "/Preference/change-stor-directory";
|
||||||
chosen = $('#storageFolder').val();
|
chosen = $('#storageFolder').val();
|
||||||
|
|
||||||
|
|
|
@ -63,12 +63,12 @@ try:
|
||||||
wm = WatchManager()
|
wm = WatchManager()
|
||||||
pe = AirtimeProcessEvent(queue=multi_queue, airtime_config=config, wm=wm)
|
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)
|
bootstrap = AirtimeMediaMonitorBootstrap(logger, multi_queue, pe, api_client)
|
||||||
notifier.coalesce_events()
|
|
||||||
|
|
||||||
bootstrap = AirtimeMediaMonitorBootstrap(logger, multi_queue, pe, config)
|
|
||||||
bootstrap.scan()
|
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
|
#create 5 worker processes
|
||||||
wp = MediaMonitorWorkerProcess()
|
wp = MediaMonitorWorkerProcess()
|
||||||
for i in range(5):
|
for i in range(5):
|
||||||
|
|
|
@ -2,19 +2,15 @@ import os
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from subprocess import Popen, PIPE
|
from subprocess import Popen, PIPE
|
||||||
from api_clients import api_client
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class AirtimeMediaMonitorBootstrap():
|
class AirtimeMediaMonitorBootstrap():
|
||||||
|
|
||||||
def __init__(self, logger, multi_queue, pe, config):
|
def __init__(self, logger, multi_queue, pe, api_client):
|
||||||
self.logger = logger
|
self.logger = logger
|
||||||
self.multi_queue = multi_queue
|
self.multi_queue = multi_queue
|
||||||
self.pe = pe
|
self.pe = pe
|
||||||
self.airtime_tmp = '/var/tmp/airtime'
|
self.airtime_tmp = '/var/tmp/airtime'
|
||||||
self.config = config
|
self.api_client = api_client
|
||||||
self.api_client = api_client.api_client_factory(self.config.cfg)
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
on bootup we want to scan all directories and look for files that
|
on bootup we want to scan all directories and look for files that
|
||||||
|
|
|
@ -15,12 +15,13 @@ from airtimemetadata import AirtimeMetadata
|
||||||
|
|
||||||
class AirtimeNotifier(Notifier):
|
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)
|
Notifier.__init__(self, watch_manager, default_proc_fun, read_freq, threshold, timeout)
|
||||||
|
|
||||||
self.logger = logging.getLogger()
|
self.logger = logging.getLogger()
|
||||||
self.config = airtime_config
|
self.config = airtime_config
|
||||||
self.api_client = api_client
|
self.api_client = api_client
|
||||||
|
self.bootstrap = bootstrap
|
||||||
self.md_manager = AirtimeMetadata()
|
self.md_manager = AirtimeMetadata()
|
||||||
self.import_processes = {}
|
self.import_processes = {}
|
||||||
self.watched_folders = []
|
self.watched_folders = []
|
||||||
|
@ -84,6 +85,7 @@ class AirtimeNotifier(Notifier):
|
||||||
elif m['event_type'] == "change_stor":
|
elif m['event_type'] == "change_stor":
|
||||||
storage_directory = self.config.storage_directory
|
storage_directory = self.config.storage_directory
|
||||||
new_storage_directory = m['directory'].encode('utf-8')
|
new_storage_directory = m['directory'].encode('utf-8')
|
||||||
|
new_storage_directory_id = str(m['dir_id']).encode('utf-8')
|
||||||
|
|
||||||
mm = self.proc_fun()
|
mm = self.proc_fun()
|
||||||
|
|
||||||
|
@ -93,17 +95,25 @@ class AirtimeNotifier(Notifier):
|
||||||
|
|
||||||
mm.set_needed_file_permissions(new_storage_directory, True)
|
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)
|
old_storage_contents = os.listdir(storage_directory)
|
||||||
for item in old_storage_contents:
|
for item in old_storage_contents:
|
||||||
fp = "%s/%s" % (storage_directory, item)
|
fp = "%s/%s" % (storage_directory, item)
|
||||||
nfp = "%s/%s" % (new_storage_directory, item)
|
nfp = "%s/%s" % (new_storage_directory, item)
|
||||||
self.logger.info("Moving %s to %s", fp, nfp)
|
self.logger.info("Moving %s to %s", fp, nfp)
|
||||||
mm.move_file(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":
|
elif m['event_type'] == "file_delete":
|
||||||
self.logger.info("Deleting file: %s ", m['filepath'])
|
self.logger.info("Deleting file: %s ", m['filepath'])
|
||||||
|
|
|
@ -284,6 +284,11 @@ class AirtimeProcessEvent(ProcessEvent):
|
||||||
if self.is_audio_file(event.name):
|
if self.is_audio_file(event.name):
|
||||||
self.cookies_IN_MOVED_FROM[event.cookie] = (event, time.time())
|
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):
|
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)
|
||||||
#if stuff dropped in stor via a UI move must change file permissions.
|
#if stuff dropped in stor via a UI move must change file permissions.
|
||||||
|
|
Loading…
Reference in New Issue