From 99153fdb154c65d0c5ed3c5ff076b42b8df57fe9 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 14 Jul 2011 13:32:45 -0400 Subject: [PATCH 1/5] CC-2546:Airtime-import does not confirm to change the storage dir - fixed --- utils/airtime-import/airtime-import.py | 41 +++++++++++++++++++++----- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/utils/airtime-import/airtime-import.py b/utils/airtime-import/airtime-import.py index 6a5c433f6..8ac8ecea3 100644 --- a/utils/airtime-import/airtime-import.py +++ b/utils/airtime-import/airtime-import.py @@ -76,9 +76,12 @@ def checkOtherOption(args): if('-' in i): return True -def errorIfMultipleOption(args): +def errorIfMultipleOption(args, msg=''): if(checkOtherOption(args)): - raise OptionValueError("This option cannot be combined with other options") + if(msg != ''): + raise OptionValueError(msg) + else: + raise OptionValueError("This option cannot be combined with other options") def printHelp(): storage_dir = helper_get_stor_dir() @@ -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,20 +184,40 @@ 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): From 47645a20499bf22bf41636175a85704af6adc33d Mon Sep 17 00:00:00 2001 From: James Date: Thu, 14 Jul 2011 14:03:33 -0400 Subject: [PATCH 2/5] CC-2549:airtime-import should work with pythone 2.6 - enhanced usage text --- utils/airtime-import/airtime-import.py | 36 ++++++++++++++------------ 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/utils/airtime-import/airtime-import.py b/utils/airtime-import/airtime-import.py index 8ac8ecea3..be1a5f9c5 100644 --- a/utils/airtime-import/airtime-import.py +++ b/utils/airtime-import/airtime-import.py @@ -90,26 +90,26 @@ def printHelp(): else: storage_dir += "imported/" print """ - ======================== - Airtime Import Script - ======================== - There are two ways to import audio files into Airtime: +======================== + Airtime Import Script +======================== +There are two ways to import audio files into Airtime: - 1) Copy or move files into the storage folder +1) Copy or move files into the storage folder - Copied or moved files will be placed into the folder: - %s + Copied or moved files will be placed into the folder: + %s - Files will be automatically organized into the structure - "Artist/Album/TrackNumber-TrackName-Bitrate.file_extension". + Files will be automatically organized into the structure + "Artist/Album/TrackNumber-TrackName-Bitrate.file_extension". - 2) Add a folder to the Airtime library("watch" a folder) +2) Add a folder to the Airtime library("watch" a folder) - All the files in the watched folder will be imported to Airtime and the - folder will be monitored to automatically detect any changes. Hence any - changes done in the folder(add, delete, edit a file) will trigger - updates in Airtime libarary. - """ % storage_dir + All the files in the watched folder will be imported to Airtime and the + folder will be monitored to automatically detect any changes. Hence any + changes done in the folder(add, delete, edit a file) will trigger + updates in Airtime libarary. +""" % storage_dir parser.print_help() print "" @@ -223,8 +223,12 @@ def StorageGetAction(option, opt, value, parser): if(len(parser.rargs) > 0): raise OptionValueError("This option doesn't take any argument.") print helper_get_stor_dir() + +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(add_help_option=False) +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.') From 2b1a0b4f72b47dc31e3fa169a94a21328307d9d9 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 14 Jul 2011 15:43:38 -0400 Subject: [PATCH 3/5] CC-2551:airtime-import:Script doesnot send msg to media monitor - move all error checking and RabitMq calls into MusicDir functions - fix in PreferenceController.php so it works with new functions from MusicDir --- .../controllers/PreferenceController.php | 43 +++---------------- airtime_mvc/application/models/MusicDir.php | 28 ++++++++++-- 2 files changed, 31 insertions(+), 40 deletions(-) diff --git a/airtime_mvc/application/controllers/PreferenceController.php b/airtime_mvc/application/controllers/PreferenceController.php index 7b366140b..5452401ae 100644 --- a/airtime_mvc/application/controllers/PreferenceController.php +++ b/airtime_mvc/application/controllers/PreferenceController.php @@ -124,22 +124,9 @@ 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{ - $watched_dirs_form->getElement($element)->setErrors(array($res['error'])); - } + $res = MusicDir::setStorDir($chosen); + if($res['code'] != 0){ + $watched_dirs_form->getElement($element)->setErrors(array($res['error'])); } $this->view->subform = $watched_dirs_form->render(); @@ -151,20 +138,9 @@ 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{ - $watched_dirs_form->getElement($element)->setErrors(array($res['error'])); - } + $res = MusicDir::addWatchedDir($chosen); + 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(); diff --git a/airtime_mvc/application/models/MusicDir.php b/airtime_mvc/application/models/MusicDir.php index 54c27f4b7..2c66c5ffd 100644 --- a/airtime_mvc/application/models/MusicDir.php +++ b/airtime_mvc/application/models/MusicDir.php @@ -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); } } From 4601852eed3bf1bd3138cb50a2b175138ac9dd29 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 14 Jul 2011 15:58:15 -0400 Subject: [PATCH 4/5] CC-2538:Upgrade script for Phone home metrics-DB changes - implemented drop() for both music_dirs and country tables --- install/DoctrineMigrations/Version20110629143017.php | 2 +- install/DoctrineMigrations/Version20110713161043.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/install/DoctrineMigrations/Version20110629143017.php b/install/DoctrineMigrations/Version20110629143017.php index 273bb503e..8660c899d 100644 --- a/install/DoctrineMigrations/Version20110629143017.php +++ b/install/DoctrineMigrations/Version20110629143017.php @@ -32,6 +32,6 @@ class Version20110629143017 extends AbstractMigration public function down(Schema $schema) { - + $schema->dropTable('cc_music_dirs'); } } diff --git a/install/DoctrineMigrations/Version20110713161043.php b/install/DoctrineMigrations/Version20110713161043.php index 58625d2e6..db44a0270 100644 --- a/install/DoctrineMigrations/Version20110713161043.php +++ b/install/DoctrineMigrations/Version20110713161043.php @@ -21,6 +21,6 @@ class Version20110713161043 extends AbstractMigration public function down(Schema $schema) { - + $schema->dropTable('cc_country'); } } \ No newline at end of file From f95e881ec534f43ce6a4039e7d6cc5d62372cd15 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 14 Jul 2011 16:06:13 -0400 Subject: [PATCH 5/5] CC-2501:Registration:wording changes - fixed --- airtime_mvc/application/forms/GeneralPreferences.php | 2 +- .../application/views/scripts/form/preferences_general.phtml | 4 +++- .../application/views/scripts/form/preferences_support.phtml | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/airtime_mvc/application/forms/GeneralPreferences.php b/airtime_mvc/application/forms/GeneralPreferences.php index 5646f4399..3e5ba710e 100644 --- a/airtime_mvc/application/forms/GeneralPreferences.php +++ b/airtime_mvc/application/forms/GeneralPreferences.php @@ -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'), diff --git a/airtime_mvc/application/views/scripts/form/preferences_general.phtml b/airtime_mvc/application/views/scripts/form/preferences_general.phtml index f5d2761e3..21df5c566 100644 --- a/airtime_mvc/application/views/scripts/form/preferences_general.phtml +++ b/airtime_mvc/application/views/scripts/form/preferences_general.phtml @@ -2,7 +2,9 @@
- +
element->getElement('stationName') ?> diff --git a/airtime_mvc/application/views/scripts/form/preferences_support.phtml b/airtime_mvc/application/views/scripts/form/preferences_support.phtml index a16ed54f6..d0e100f42 100644 --- a/airtime_mvc/application/views/scripts/form/preferences_support.phtml +++ b/airtime_mvc/application/views/scripts/form/preferences_support.phtml @@ -36,6 +36,7 @@