CC-1799 Put Airtime Storage into a Human Readable File Naming Convention

adding ability to move stor directory.
This commit is contained in:
Naomi Aro 2011-06-21 14:58:38 +02:00
parent f1893cebe6
commit 6adce1ba45
6 changed files with 132 additions and 32 deletions

View file

@ -10,6 +10,7 @@ class PreferenceController extends Zend_Controller_Action
$ajaxContext->addActionContext('register', 'json')
->addActionContext('remindme', 'json')
->addActionContext('server-browse', 'json')
->addActionContext('change-stor-directory', 'json')
->addActionContext('reload-watch-directory', 'json')
->addActionContext('remove-watch-directory', 'json')
->initContext();
@ -175,12 +176,33 @@ class PreferenceController extends Zend_Controller_Action
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()
{
$chosen = $this->getRequest()->getParam("dir");
$element = $this->getRequest()->getParam("element");
$watched_dirs_form = new Application_Form_WatchedDirPreferences();
$watched_dirs_form->populate(array('watchedFolder' => $chosen));
$bool = $watched_dirs_form->verifyChosenFolder();
$bool = $watched_dirs_form->verifyChosenFolder($element);
if ($bool === true) {
MusicDir::addWatchedDir($chosen);

View file

@ -9,6 +9,17 @@ class Application_Form_WatchedDirPreferences extends Zend_Form_SubForm
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(
'class' => 'input_text',
'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())) {
$element->setErrors(array('Not a valid Directory'));

View file

@ -35,6 +35,7 @@ class MusicDir {
public function setDirectory($dir)
{
$this->_dir->setDirectory($dir);
$this->_dir->save();
}
public function remove()
@ -112,6 +113,12 @@ class MusicDir {
return $mus_dir;
}
public static function setStorDir($p_dir)
{
$dir = self::getStorDir();
$dir->setDirectory($p_dir);
}
public static function getWatchedDirFromFilepath($p_filepath)
{
$dirs = CcMusicDirsQuery::create()

View file

@ -1,11 +1,29 @@
<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">
<label class="required" for="watchedFolder"><?php echo $this->element->getElement('watchedFolder')->getLabel() ?></label>
</dt>
<dd id="watchedFolder-element">
<?php echo $this->element->getElement('watchedFolder') ?>
<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()) : ?>
<ul class='errors'>
<?php foreach($this->element->getElement('watchedFolder')->getMessages() as $error): ?>
@ -14,9 +32,7 @@
</ul>
<?php endif; ?>
</dd>
<dd>
<input id="watchedFolder-ok" type="button" value="OK"></input>
</dd>
<div id="watchedFolder-table">
<?php $i = 1; ?>
<?php $element = $this->element->getElement("watched_dir_$i"); ?>

View file

@ -1,4 +1,25 @@
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({
onSelect: function(path) {
$('#watchedFolder').val(path);
@ -19,6 +40,22 @@ function setWatchedDirEvents() {
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(){
var url, chosen;
@ -26,7 +63,7 @@ function setWatchedDirEvents() {
chosen = $('#watchedFolder').val();
$.post(url,
{format: "json", dir: chosen},
{format: "json", dir: chosen, element: "watchedFolder"},
function(json) {
$("#watched-folder-section").empty();

View file

@ -215,6 +215,7 @@ class AirtimeNotifier(Notifier):
if m['event_type'] == "md_update":
self.logger.info("AIRTIME NOTIFIER md update event")
self.md_manager.save_md_to_file(m)
elif m['event_type'] == "new_watch":
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.
@ -223,8 +224,23 @@ class AirtimeNotifier(Notifier):
self.import_processes[m['directory']] = p
#add this new folder to our list of watched folders
self.watched_folders.append(m['directory'])
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):
@ -521,15 +537,6 @@ class MediaMonitor(ProcessEvent):
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():
process = notifier.import_processes[watched_directory]
if not process.is_alive():
@ -560,8 +567,8 @@ if __name__ == '__main__':
response = mm.api_client.setup_media_monitor()
time.sleep(5)
storage_directory = response["stor"]
plupload_directory = response["plupload"]
storage_directory = response["stor"].encode('utf-8')
plupload_directory = response["plupload"].encode('utf-8')
wdd = mm.watch_directory(storage_directory)
logger.info("Added watch to %s", storage_directory)