CC-1799 Put Airtime Storage into a Human Readable File Naming Convention
adding ability to move stor directory.
This commit is contained in:
parent
f1893cebe6
commit
6adce1ba45
6 changed files with 132 additions and 32 deletions
|
@ -10,6 +10,7 @@ class PreferenceController extends Zend_Controller_Action
|
||||||
$ajaxContext->addActionContext('register', 'json')
|
$ajaxContext->addActionContext('register', 'json')
|
||||||
->addActionContext('remindme', 'json')
|
->addActionContext('remindme', 'json')
|
||||||
->addActionContext('server-browse', 'json')
|
->addActionContext('server-browse', 'json')
|
||||||
|
->addActionContext('change-stor-directory', 'json')
|
||||||
->addActionContext('reload-watch-directory', 'json')
|
->addActionContext('reload-watch-directory', 'json')
|
||||||
->addActionContext('remove-watch-directory', 'json')
|
->addActionContext('remove-watch-directory', 'json')
|
||||||
->initContext();
|
->initContext();
|
||||||
|
@ -175,12 +176,33 @@ class PreferenceController extends Zend_Controller_Action
|
||||||
die(json_encode($result));
|
die(json_encode($result));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function changeStorDirectoryAction()
|
||||||
|
{
|
||||||
|
$chosen = $this->getRequest()->getParam("dir");
|
||||||
|
$element = $this->getRequest()->getParam("element");
|
||||||
|
$watched_dirs_form = new Application_Form_WatchedDirPreferences();
|
||||||
|
$watched_dirs_form->populate(array('storageFolder' => $chosen));
|
||||||
|
$bool = $watched_dirs_form->verifyChosenFolder($element);
|
||||||
|
|
||||||
|
if ($bool === true) {
|
||||||
|
MusicDir::setStorDir($chosen);
|
||||||
|
$data = array();
|
||||||
|
$data["directory"] = $chosen;
|
||||||
|
RabbitMq::SendMessageToMediaMonitor("change_stor", $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
$watched_dirs_form->setWatchedDirs();
|
||||||
|
|
||||||
|
$this->view->subform = $watched_dirs_form->render();
|
||||||
|
}
|
||||||
|
|
||||||
public function reloadWatchDirectoryAction()
|
public function reloadWatchDirectoryAction()
|
||||||
{
|
{
|
||||||
$chosen = $this->getRequest()->getParam("dir");
|
$chosen = $this->getRequest()->getParam("dir");
|
||||||
|
$element = $this->getRequest()->getParam("element");
|
||||||
$watched_dirs_form = new Application_Form_WatchedDirPreferences();
|
$watched_dirs_form = new Application_Form_WatchedDirPreferences();
|
||||||
$watched_dirs_form->populate(array('watchedFolder' => $chosen));
|
$watched_dirs_form->populate(array('watchedFolder' => $chosen));
|
||||||
$bool = $watched_dirs_form->verifyChosenFolder();
|
$bool = $watched_dirs_form->verifyChosenFolder($element);
|
||||||
|
|
||||||
if ($bool === true) {
|
if ($bool === true) {
|
||||||
MusicDir::addWatchedDir($chosen);
|
MusicDir::addWatchedDir($chosen);
|
||||||
|
|
|
@ -9,6 +9,17 @@ class Application_Form_WatchedDirPreferences extends Zend_Form_SubForm
|
||||||
array('ViewScript', array('viewScript' => 'form/preferences_watched_dirs.phtml'))
|
array('ViewScript', array('viewScript' => 'form/preferences_watched_dirs.phtml'))
|
||||||
));
|
));
|
||||||
|
|
||||||
|
$this->addElement('text', 'storageFolder', array(
|
||||||
|
'class' => 'input_text',
|
||||||
|
'label' => 'Airtime\'s Storage Folder:',
|
||||||
|
'required' => false,
|
||||||
|
'filters' => array('StringTrim'),
|
||||||
|
'value' => '',
|
||||||
|
'decorators' => array(
|
||||||
|
'ViewHelper'
|
||||||
|
)
|
||||||
|
));
|
||||||
|
|
||||||
$this->addElement('text', 'watchedFolder', array(
|
$this->addElement('text', 'watchedFolder', array(
|
||||||
'class' => 'input_text',
|
'class' => 'input_text',
|
||||||
'label' => 'Choose a Folder to Watch:',
|
'label' => 'Choose a Folder to Watch:',
|
||||||
|
@ -21,9 +32,9 @@ class Application_Form_WatchedDirPreferences extends Zend_Form_SubForm
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function verifyChosenFolder() {
|
public function verifyChosenFolder($p_form_element_id) {
|
||||||
|
|
||||||
$element = $this->getElement('watchedFolder');
|
$element = $this->getElement($p_form_element_id);
|
||||||
|
|
||||||
if (!is_dir($element->getValue())) {
|
if (!is_dir($element->getValue())) {
|
||||||
$element->setErrors(array('Not a valid Directory'));
|
$element->setErrors(array('Not a valid Directory'));
|
||||||
|
|
|
@ -35,6 +35,7 @@ class MusicDir {
|
||||||
public function setDirectory($dir)
|
public function setDirectory($dir)
|
||||||
{
|
{
|
||||||
$this->_dir->setDirectory($dir);
|
$this->_dir->setDirectory($dir);
|
||||||
|
$this->_dir->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function remove()
|
public function remove()
|
||||||
|
@ -112,6 +113,12 @@ class MusicDir {
|
||||||
return $mus_dir;
|
return $mus_dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function setStorDir($p_dir)
|
||||||
|
{
|
||||||
|
$dir = self::getStorDir();
|
||||||
|
$dir->setDirectory($p_dir);
|
||||||
|
}
|
||||||
|
|
||||||
public static function getWatchedDirFromFilepath($p_filepath)
|
public static function getWatchedDirFromFilepath($p_filepath)
|
||||||
{
|
{
|
||||||
$dirs = CcMusicDirsQuery::create()
|
$dirs = CcMusicDirsQuery::create()
|
||||||
|
|
|
@ -1,11 +1,29 @@
|
||||||
<dl class="zend_form">
|
<dl class="zend_form">
|
||||||
|
|
||||||
|
<dt id="storageFolder-label" class="block-display">
|
||||||
|
<label class="required" for="storageFolder"><?php echo $this->element->getElement('storageFolder')->getLabel() ?></label>
|
||||||
|
</dt>
|
||||||
|
<dd id="storageFolder-element">
|
||||||
|
<?php echo $this->element->getElement('storageFolder') ?>
|
||||||
|
<input id="storageFolder-selection" type="button" value="choose folder"></input>
|
||||||
|
<input id="storageFolder-ok" type="button" value="OK"></input>
|
||||||
|
<?php if($this->element->getElement('storageFolder')->hasErrors()) : ?>
|
||||||
|
<ul class='errors'>
|
||||||
|
<?php foreach($this->element->getElement('storageFolder')->getMessages() as $error): ?>
|
||||||
|
<li><?php echo $error; ?></li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</ul>
|
||||||
|
<?php endif; ?>
|
||||||
|
</dd>
|
||||||
|
<div>Current Storage Folder: <?php $stor = MusicDir::getStorDir(); echo $stor->getDirectory(); ?></div>
|
||||||
|
|
||||||
<dt id="watchedFolder-label" class="block-display">
|
<dt id="watchedFolder-label" class="block-display">
|
||||||
<label class="required" for="watchedFolder"><?php echo $this->element->getElement('watchedFolder')->getLabel() ?></label>
|
<label class="required" for="watchedFolder"><?php echo $this->element->getElement('watchedFolder')->getLabel() ?></label>
|
||||||
</dt>
|
</dt>
|
||||||
<dd id="watchedFolder-element">
|
<dd id="watchedFolder-element">
|
||||||
<?php echo $this->element->getElement('watchedFolder') ?>
|
<?php echo $this->element->getElement('watchedFolder') ?>
|
||||||
<input id="watchedFolder-selection" type="button" value="choose folder"></input>
|
<input id="watchedFolder-selection" type="button" value="choose folder"></input>
|
||||||
|
<input id="watchedFolder-ok" type="button" value="OK"></input>
|
||||||
<?php if($this->element->getElement('watchedFolder')->hasErrors()) : ?>
|
<?php if($this->element->getElement('watchedFolder')->hasErrors()) : ?>
|
||||||
<ul class='errors'>
|
<ul class='errors'>
|
||||||
<?php foreach($this->element->getElement('watchedFolder')->getMessages() as $error): ?>
|
<?php foreach($this->element->getElement('watchedFolder')->getMessages() as $error): ?>
|
||||||
|
@ -14,9 +32,7 @@
|
||||||
</ul>
|
</ul>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</dd>
|
</dd>
|
||||||
<dd>
|
|
||||||
<input id="watchedFolder-ok" type="button" value="OK"></input>
|
|
||||||
</dd>
|
|
||||||
<div id="watchedFolder-table">
|
<div id="watchedFolder-table">
|
||||||
<?php $i = 1; ?>
|
<?php $i = 1; ?>
|
||||||
<?php $element = $this->element->getElement("watched_dir_$i"); ?>
|
<?php $element = $this->element->getElement("watched_dir_$i"); ?>
|
||||||
|
|
|
@ -1,4 +1,25 @@
|
||||||
function setWatchedDirEvents() {
|
function setWatchedDirEvents() {
|
||||||
|
|
||||||
|
$('#storageFolder-selection').serverBrowser({
|
||||||
|
onSelect: function(path) {
|
||||||
|
$('#storageFolder').val(path);
|
||||||
|
},
|
||||||
|
onLoad: function() {
|
||||||
|
return $('#storageFolder').val();
|
||||||
|
},
|
||||||
|
width: 500,
|
||||||
|
height: 250,
|
||||||
|
position: ['center', 'center'],
|
||||||
|
//knownPaths: [{text:'Desktop', image:'desktop.png', path:'/home'}],
|
||||||
|
knownPaths: [],
|
||||||
|
imageUrl: 'img/icons/',
|
||||||
|
systemImageUrl: 'img/browser/',
|
||||||
|
handlerUrl: '/Preference/server-browse/format/json',
|
||||||
|
title: 'Choose Storage Folder',
|
||||||
|
basePath: '/home',
|
||||||
|
requestMethod: 'POST',
|
||||||
|
});
|
||||||
|
|
||||||
$('#watchedFolder-selection').serverBrowser({
|
$('#watchedFolder-selection').serverBrowser({
|
||||||
onSelect: function(path) {
|
onSelect: function(path) {
|
||||||
$('#watchedFolder').val(path);
|
$('#watchedFolder').val(path);
|
||||||
|
@ -19,6 +40,22 @@ function setWatchedDirEvents() {
|
||||||
requestMethod: 'POST',
|
requestMethod: 'POST',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#storageFolder-ok').click(function(){
|
||||||
|
var url, chosen;
|
||||||
|
|
||||||
|
url = "/Preference/change-stor-directory";
|
||||||
|
chosen = $('#storageFolder').val();
|
||||||
|
|
||||||
|
$.post(url,
|
||||||
|
{format: "json", dir: chosen, element: "storageFolder"},
|
||||||
|
|
||||||
|
function(json) {
|
||||||
|
$("#watched-folder-section").empty();
|
||||||
|
$("#watched-folder-section").append(json.subform);
|
||||||
|
setWatchedDirEvents();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
$('#watchedFolder-ok').click(function(){
|
$('#watchedFolder-ok').click(function(){
|
||||||
var url, chosen;
|
var url, chosen;
|
||||||
|
|
||||||
|
@ -26,7 +63,7 @@ function setWatchedDirEvents() {
|
||||||
chosen = $('#watchedFolder').val();
|
chosen = $('#watchedFolder').val();
|
||||||
|
|
||||||
$.post(url,
|
$.post(url,
|
||||||
{format: "json", dir: chosen},
|
{format: "json", dir: chosen, element: "watchedFolder"},
|
||||||
|
|
||||||
function(json) {
|
function(json) {
|
||||||
$("#watched-folder-section").empty();
|
$("#watched-folder-section").empty();
|
||||||
|
|
|
@ -215,6 +215,7 @@ class AirtimeNotifier(Notifier):
|
||||||
if m['event_type'] == "md_update":
|
if m['event_type'] == "md_update":
|
||||||
self.logger.info("AIRTIME NOTIFIER md update event")
|
self.logger.info("AIRTIME NOTIFIER md update event")
|
||||||
self.md_manager.save_md_to_file(m)
|
self.md_manager.save_md_to_file(m)
|
||||||
|
|
||||||
elif m['event_type'] == "new_watch":
|
elif m['event_type'] == "new_watch":
|
||||||
self.logger.info("AIRTIME NOTIFIER add watched folder event " + m['directory'])
|
self.logger.info("AIRTIME NOTIFIER add watched folder event " + m['directory'])
|
||||||
#start a new process to walk through this folder and add the files to Airtime.
|
#start a new process to walk through this folder and add the files to Airtime.
|
||||||
|
@ -223,8 +224,23 @@ class AirtimeNotifier(Notifier):
|
||||||
self.import_processes[m['directory']] = p
|
self.import_processes[m['directory']] = p
|
||||||
#add this new folder to our list of watched folders
|
#add this new folder to our list of watched folders
|
||||||
self.watched_folders.append(m['directory'])
|
self.watched_folders.append(m['directory'])
|
||||||
|
|
||||||
elif m['event_type'] == "remove_watch":
|
elif m['event_type'] == "remove_watch":
|
||||||
self.watches_to_remove.append(m['directory'])
|
watched_directory = m['directory'].encode('utf-8')
|
||||||
|
|
||||||
|
mm = self.proc_fun()
|
||||||
|
wd = mm.wm.get_wd(watched_directory)
|
||||||
|
self.logger.info("Removing watch on: %s wd %s", watched_directory, wd)
|
||||||
|
mm.wm.rm_watch(wd, rec=True)
|
||||||
|
|
||||||
|
elif m['event_type'] == "change_stor":
|
||||||
|
global storage_directory
|
||||||
|
new_storage_directory = m['directory'].encode('utf-8')
|
||||||
|
|
||||||
|
mm = self.proc_fun()
|
||||||
|
mm.set_needed_file_permissions(new_storage_directory, True)
|
||||||
|
mm.move_file(storage_directory, new_storage_directory)
|
||||||
|
storage_directory = new_storage_directory
|
||||||
|
|
||||||
|
|
||||||
def update_airtime(self, d):
|
def update_airtime(self, d):
|
||||||
|
@ -521,15 +537,6 @@ class MediaMonitor(ProcessEvent):
|
||||||
|
|
||||||
def notifier_loop_callback(self, notifier):
|
def notifier_loop_callback(self, notifier):
|
||||||
|
|
||||||
#recursively unwatch any directories.
|
|
||||||
for watched_directory in notifier.watches_to_remove:
|
|
||||||
wd = self.wm.get_wd(watched_directory)
|
|
||||||
self.logger.info("Removing watch on: %s wdd %s", watched_directory, wd)
|
|
||||||
self.wm.rm_watch(wd, rec=True)
|
|
||||||
|
|
||||||
notifier.watches_to_remove = []
|
|
||||||
|
|
||||||
|
|
||||||
for watched_directory in notifier.import_processes.keys():
|
for watched_directory in notifier.import_processes.keys():
|
||||||
process = notifier.import_processes[watched_directory]
|
process = notifier.import_processes[watched_directory]
|
||||||
if not process.is_alive():
|
if not process.is_alive():
|
||||||
|
@ -560,8 +567,8 @@ if __name__ == '__main__':
|
||||||
response = mm.api_client.setup_media_monitor()
|
response = mm.api_client.setup_media_monitor()
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
|
||||||
storage_directory = response["stor"]
|
storage_directory = response["stor"].encode('utf-8')
|
||||||
plupload_directory = response["plupload"]
|
plupload_directory = response["plupload"].encode('utf-8')
|
||||||
|
|
||||||
wdd = mm.watch_directory(storage_directory)
|
wdd = mm.watch_directory(storage_directory)
|
||||||
logger.info("Added watch to %s", storage_directory)
|
logger.info("Added watch to %s", storage_directory)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue