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

This commit is contained in:
martin 2011-07-14 16:39:27 -04:00
commit 1aa1500d0c
8 changed files with 93 additions and 67 deletions

View File

@ -124,23 +124,10 @@ class PreferenceController extends Zend_Controller_Action
$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);
// it has error checking in two part. It checks is_dir above, and
// check uniqueness in DB below. We should put is_dir checking into
// MusicDir class.
if ($bool === true) {
$res = MusicDir::setStorDir($chosen);
if($res['code'] == 0){
$dirId = MusicDir::getStorDir()->getId();
$data = array();
$data["directory"] = $chosen;
$data["dir_id"] = $dirId;
RabbitMq::SendMessageToMediaMonitor("change_stor", $data);
}else{
if($res['code'] != 0){
$watched_dirs_form->getElement($element)->setErrors(array($res['error']));
}
}
$this->view->subform = $watched_dirs_form->render();
}
@ -151,21 +138,10 @@ class PreferenceController extends Zend_Controller_Action
$element = $this->getRequest()->getParam("element");
$watched_dirs_form = new Application_Form_WatchedDirPreferences();
$watched_dirs_form->populate(array('watchedFolder' => $chosen));
$bool = $watched_dirs_form->verifyChosenFolder($element);
// it has error checking in two part. It checks is_dir above, and
// check uniqueness in DB below. We should put is_dir checking into
// MusicDir class.
if ($bool === true) {
$res = MusicDir::addWatchedDir($chosen);
if($res['code'] == 0){
$data = array();
$data["directory"] = $chosen;
RabbitMq::SendMessageToMediaMonitor("new_watch", $data);
}else{
if($res['code'] != 0){
$watched_dirs_form->getElement($element)->setErrors(array($res['error']));
}
}
$this->view->subform = $watched_dirs_form->render();
}
@ -174,12 +150,7 @@ class PreferenceController extends Zend_Controller_Action
{
$chosen = $this->getRequest()->getParam("dir");
$dir = MusicDir::getDirByPath($chosen);
$dir->remove();
$data = array();
$data["directory"] = $chosen;
RabbitMq::SendMessageToMediaMonitor("remove_watch", $data);
$dir = MusicDir::removeWatchedDir($chosen);
$watched_dirs_form = new Application_Form_WatchedDirPreferences();
$this->view->subform = $watched_dirs_form->render();

View File

@ -12,7 +12,7 @@ class Application_Form_GeneralPreferences extends Zend_Form_SubForm
//Station name
$this->addElement('text', 'stationName', array(
'class' => 'input_text',
'label' => 'Station Name:',
'label' => 'Station Name',
'required' => true,
'filters' => array('StringTrim'),
'validators' => array('NotEmpty'),

View File

@ -45,6 +45,9 @@ class MusicDir {
public static function addDir($p_path, $p_type)
{
if(!is_dir($p_path)){
return array("code"=>2, "error"=>"'$p_path' is not a valid directory.");
}
$dir = new CcMusicDirs();
$dir->setType($p_type);
$p_path = realpath($p_path)."/";
@ -55,14 +58,20 @@ class MusicDir {
}
catch(Exception $e){
//echo $e->getMessage();
return array("code"=>1, "error"=>"$p_path is already set as the current storage dir or in the watched folders list");
return array("code"=>1, "error"=>"'$p_path' is already set as the current storage dir or in the watched folders list");
}
}
public static function addWatchedDir($p_path)
{
return self::addDir($p_path, "watched");
$res = self::addDir($p_path, "watched");
if($res['code'] == 0){
$data = array();
$data["directory"] = $p_path;
RabbitMq::SendMessageToMediaMonitor("new_watch", $data);
}
return $res;
}
public static function getDirByPK($pk)
@ -118,15 +127,23 @@ class MusicDir {
public static function setStorDir($p_dir)
{
if(!is_dir($p_dir)){
return array("code"=>2, "error"=>"'$p_dir' is not a valid directory.");
}
$dir = self::getStorDir();
// if $p_dir doesn't exist in DB
$p_dir = realpath($p_dir)."/";
$exist = $dir->getDirByPath($p_dir);
if($exist == NULL){
$dir->setDirectory($p_dir);
$dirId = $dir->getId();
$data = array();
$data["directory"] = $p_dir;
$data["dir_id"] = $dirId;
RabbitMq::SendMessageToMediaMonitor("change_stor", $data);
return array("code"=>0);
}else{
return array("code"=>1, "error"=>"$p_dir is already set as the current storage dir or in the watched folders list");
return array("code"=>1, "error"=>"'$p_dir' is already set as the current storage dir or in the watched folders list.");
}
}
@ -150,9 +167,12 @@ class MusicDir {
$p_dir = realpath($p_dir)."/";
$dir = MusicDir::getDirByPath($p_dir);
if($dir == NULL){
return array("code"=>1,"error"=>"$p_dir doesn't exist in the watched list");
return array("code"=>1,"error"=>"'$p_dir' doesn't exist in the watched list.");
}else{
$dir->remove();
$data = array();
$data["directory"] = $p_dir;
RabbitMq::SendMessageToMediaMonitor("remove_watch", $data);
return array("code"=>0);
}
}

View File

@ -2,7 +2,9 @@
<dl class="zend_form">
<dt id="stationName-label" class="block-display">
<label class="required" for="stationName"><?php echo $this->element->getElement('stationName')->getLabel() ?></label>
<label class="required" for="stationName"><?php echo $this->element->getElement('stationName')->getLabel() ?>
<span class="info-text-small">(Required)</span> :
</label>
</dt>
<dd id="stationName-element" class="block-display">
<?php echo $this->element->getElement('stationName') ?>

View File

@ -36,6 +36,7 @@
<dl id="public-info" style="display:none;">
<dt id="Phone-label" class="block-display">
<label class="optional" for="Phone"><?php echo $this->element->getElement('Phone')->getLabel() ?></label>
<span class="info-text-small">(for verification purposes only, will not be published)</span>
</dt>
<dd id="Phone-element" class="block-display">
<?php echo $this->element->getElement('Phone') ?>
@ -49,6 +50,7 @@
</dd>
<dt id="Email-label" class="block-display">
<label class="optional" for="Email"><?php echo $this->element->getElement('Email')->getLabel() ?></label>
<span class="info-text-small">(for verification purposes only, will not be published)</span>
</dt>
<dd id="Email-element" class="block-display">
<?php echo $this->element->getElement('Email') ?>

View File

@ -33,6 +33,6 @@ class Version20110629143017 extends AbstractMigration
public function down(Schema $schema)
{
$schema->dropTable('cc_music_dirs');
}
}

View File

@ -21,6 +21,6 @@ class Version20110713161043 extends AbstractMigration
public function down(Schema $schema)
{
$schema->dropTable('cc_country');
}
}

View File

@ -76,8 +76,11 @@ def checkOtherOption(args):
if('-' in i):
return True
def errorIfMultipleOption(args):
def errorIfMultipleOption(args, msg=''):
if(checkOtherOption(args)):
if(msg != ''):
raise OptionValueError(msg)
else:
raise OptionValueError("This option cannot be combined with other options")
def printHelp():
@ -130,6 +133,8 @@ def WatchAddAction(option, opt, value, parser):
errorIfMultipleOption(parser.rargs)
if(len(parser.rargs) > 1):
raise OptionValueError("Too many arguments. This option need exactly one argument.")
elif(len(parser.rargs) == 0 ):
raise OptionValueError("No argument found. This option need exactly one argument.")
path = parser.rargs[0]
if(os.path.isdir(path)):
res = api_client.add_watched_dir(path)
@ -163,6 +168,8 @@ def WatchRemoveAction(option, opt, value, parser):
errorIfMultipleOption(parser.rargs)
if(len(parser.rargs) > 1):
raise OptionValueError("Too many arguments. This option need exactly one argument.")
elif(len(parser.rargs) == 0 ):
raise OptionValueError("No argument found. This option need exactly one argument.")
path = parser.rargs[0]
if(os.path.isdir(path)):
res = api_client.remove_watched_dir(path)
@ -177,27 +184,51 @@ def WatchRemoveAction(option, opt, value, parser):
print "Given path is not a directory: %s" % path
def StorageSetAction(option, opt, value, parser):
errorIfMultipleOption(parser.rargs)
bypass = False
isF = '-f' in parser.rargs
isForce = '--force' in parser.rargs
if(isF or isForce ):
bypass = True
if(isF):
parser.rargs.remove('-f')
if(isForce):
parser.rargs.remove('--force')
if(not bypass):
errorIfMultipleOption(parser.rargs, "Only [-f] and [--force] option is allowed with this option.")
confirm = raw_input("Are you sure you want to change the storage direcory? (Y/n)")
confirm = confirm or 'Y'
if(confirm != 'Y'):
sys.exit(1)
if(len(parser.rargs) > 1):
raise OptionValueError("Too many arguments. This option need exactly one argument.")
if(os.path.isdir(values)):
res = api_client.set_storage_dir(values)
elif(len(parser.rargs) == 0 ):
raise OptionValueError("No argument found. This option need exactly one argument.")
path = parser.rargs[0]
if(os.path.isdir(path)):
res = api_client.set_storage_dir(path)
if(res is None):
exit("Unable to connect to the server.")
# sucess
if(res['msg']['code'] == 0):
print "Successfully set storage folder to %s" % values
print "Successfully set storage folder to %s" % path
else:
print "Setting storage folder to failed.: %s" % res['msg']['error']
else:
print "Given path is not a directory: %s" % values
print "Given path is not a directory: %s" % path
def StorageGetAction(option, opt, value, parser):
errorIfMultipleOption(parser.rargs)
if(len(parser.rargs) > 0):
raise OptionValueError("This option doesn't take any argument.")
print helper_get_stor_dir()
parser = OptionParser(add_help_option=False)
usage = """[-c|--copy FILE/DIR [FILE/DIR...]] [-m|--move FILE/DIR [FILE/DIR...]]
[--watch-add DIR] [--watch-list] [--watch-remve DIR]
[--storage-dir-set DIR] [--storage-dir-get]"""
parser = OptionParser(usage=usage, add_help_option=False)
parser.add_option('-c','--copy', action='callback', callback=CopyAction, metavar='FILE', help='Copy FILE(s) into the storage directory.\nYou can specify multiple files or directories.')
parser.add_option('-m','--move', action='callback', callback=MoveAction, metavar='FILE', help='Move FILE(s) into the storage directory.\nYou can specify multiple files or directories.')
parser.add_option('--watch-add', action='callback', callback=WatchAddAction, help='Add DIR to the watched folders list.')