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

Conflicts:
	utils/airtime-import/airtime-import.py
This commit is contained in:
James 2011-07-18 15:10:57 -04:00
commit e199c118af
11 changed files with 218 additions and 104 deletions

View file

@ -63,6 +63,9 @@ class LibraryController extends Zend_Controller_Action
$paramsPop = str_replace('#id#', $id, $params); $paramsPop = str_replace('#id#', $id, $params);
$paramsPop = str_replace('#type#', $type, $paramsPop); $paramsPop = str_replace('#type#', $type, $paramsPop);
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
$user = new User($userInfo->id);
$pl_sess = $this->pl_sess; $pl_sess = $this->pl_sess;
if($type === "au") { if($type === "au") {
@ -85,10 +88,13 @@ class LibraryController extends Zend_Controller_Action
$menu[] = array('action' => array('type' => 'gourl', 'url' => $url), $menu[] = array('action' => array('type' => 'gourl', 'url' => $url),
'title' => 'Download'); 'title' => 'Download');
if ($user->isAdmin()) {
$menu[] = array('action' => array('type' => 'fn', $menu[] = array('action' => array('type' => 'fn',
'callback' => "window['confirmDeleteAudioClip']('$paramsPop')"), 'callback' => "window['confirmDeleteAudioClip']('$paramsPop')"),
'title' => 'Delete'); 'title' => 'Delete');
} }
}
else if($type === "pl") { else if($type === "pl") {
if(!isset($pl_sess->id) || $pl_sess->id !== $id) { if(!isset($pl_sess->id) || $pl_sess->id !== $id) {
@ -121,6 +127,10 @@ class LibraryController extends Zend_Controller_Action
public function deleteAction() public function deleteAction()
{ {
$id = $this->_getParam('id'); $id = $this->_getParam('id');
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
$user = new User($userInfo->id);
if ($user->isAdmin()) {
if (!is_null($id)) { if (!is_null($id)) {
$file = StoredFile::Recall($id); $file = StoredFile::Recall($id);
@ -148,6 +158,7 @@ class LibraryController extends Zend_Controller_Action
$this->view->id = $id; $this->view->id = $id;
} }
}
public function contentsAction() public function contentsAction()
{ {

View file

@ -25,9 +25,9 @@ class NowplayingController extends Zend_Controller_Action
$userInfo = Zend_Auth::getInstance()->getStorage()->read(); $userInfo = Zend_Auth::getInstance()->getStorage()->read();
$user = new User($userInfo->id); $user = new User($userInfo->id);
if ($request->isPost()) {
$form = new Application_Form_RegisterAirtime(); $form = new Application_Form_RegisterAirtime();
if ($request->isPost()) {
$values = $request->getPost(); $values = $request->getPost();
if ($values["Publicise"] != 1){ if ($values["Publicise"] != 1){
Application_Model_Preference::SetSupportFeedback($values["SupportFeedback"]); Application_Model_Preference::SetSupportFeedback($values["SupportFeedback"]);
@ -64,6 +64,10 @@ class NowplayingController extends Zend_Controller_Action
//popup if previous page was login //popup if previous page was login
if($refer_sses->referrer == 'login' && Application_Model_Nowplaying::ShouldShowPopUp() if($refer_sses->referrer == 'login' && Application_Model_Nowplaying::ShouldShowPopUp()
&& !Application_Model_Preference::GetSupportFeedback() && $user->isAdmin()){ && !Application_Model_Preference::GetSupportFeedback() && $user->isAdmin()){
$form = new Application_Form_RegisterAirtime();
$logo = Application_Model_Preference::GetStationLogo(); $logo = Application_Model_Preference::GetStationLogo();
if($logo){ if($logo){
$this->view->logoImg = $logo; $this->view->logoImg = $logo;

View file

@ -123,9 +123,10 @@ class PreferenceController extends Zend_Controller_Action
$chosen = $this->getRequest()->getParam("dir"); $chosen = $this->getRequest()->getParam("dir");
$element = $this->getRequest()->getParam("element"); $element = $this->getRequest()->getParam("element");
$watched_dirs_form = new Application_Form_WatchedDirPreferences(); $watched_dirs_form = new Application_Form_WatchedDirPreferences();
$watched_dirs_form->populate(array('storageFolder' => $chosen));
$res = MusicDir::setStorDir($chosen); $res = MusicDir::setStorDir($chosen);
if($res['code'] != 0){ if($res['code'] != 0){
$watched_dirs_form->populate(array('storageFolder' => $chosen));
$watched_dirs_form->getElement($element)->setErrors(array($res['error'])); $watched_dirs_form->getElement($element)->setErrors(array($res['error']));
} }
@ -137,9 +138,10 @@ class PreferenceController extends Zend_Controller_Action
$chosen = $this->getRequest()->getParam("dir"); $chosen = $this->getRequest()->getParam("dir");
$element = $this->getRequest()->getParam("element"); $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));
$res = MusicDir::addWatchedDir($chosen); $res = MusicDir::addWatchedDir($chosen);
if($res['code'] != 0){ if($res['code'] != 0){
$watched_dirs_form->populate(array('watchedFolder' => $chosen));
$watched_dirs_form->getElement($element)->setErrors(array($res['error'])); $watched_dirs_form->getElement($element)->setErrors(array($res['error']));
} }

View file

@ -40,7 +40,23 @@ class MusicDir {
public function remove() public function remove()
{ {
global $CC_DBC;
$music_dir_id = $this->getId();
$sql = "SELECT DISTINCT s.instance_id from cc_music_dirs as md LEFT JOIN cc_files as f on f.directory = md.id
RIGHT JOIN cc_schedule as s on s.file_id = f.id WHERE md.id = $music_dir_id";
$show_instances = $CC_DBC->GetAll($sql);
$this->_dir->delete(); $this->_dir->delete();
foreach ($show_instances as $show_instance_row) {
$temp_show = new ShowInstance($show_instance_row["instance_id"]);
$temp_show->updateScheduledTime();
}
RabbitMq::PushSchedule();
} }
public static function addDir($p_path, $p_type) public static function addDir($p_path, $p_type)

View file

@ -341,19 +341,8 @@ class StoredFile {
return PEAR::raiseError('Cannot delete a file that is scheduled in the future.'); return PEAR::raiseError('Cannot delete a file that is scheduled in the future.');
} }
$storageDir = MusicDir::getStorDir()->getDirectory();
$dirCompare = substr($this->getFilePath(), 0, strlen($storageDir));
//return PEAR::raiseError("({$storageDir} , {$dirCompare})");
// Only delete the file from filesystem if it has been copied to the storage directory
if ($dirCompare === $storageDir) {
return true; return true;
} }
else {
return false;
}
}
/** /**
* Returns true if media file exists * Returns true if media file exists

View file

@ -35,7 +35,7 @@ function deleteAudioClip(json) {
//callbacks called by jjmenu //callbacks called by jjmenu
function confirmDeleteAudioClip(params){ function confirmDeleteAudioClip(params){
if(confirm('Are you sure you want to delete?')){ if(confirm('The file will be deleted from disk, are you sure you want to delete?')){
var url = '/Library/delete' + params; var url = '/Library/delete' + params;
$.ajax({ $.ajax({
url: url, url: url,

View file

@ -3,8 +3,9 @@
namespace DoctrineMigrations; namespace DoctrineMigrations;
/* /*
update cc_files table to include to "directory" column as well as add foreign key relation to 1) update cc_files table to include to "directory" column
cc_music_dirs table. 2) create a foreign key relationship from cc_files to cc_music_dirs
3) create a foreign key relationship from cc_schedule to cc_files
*/ */
use Doctrine\DBAL\Migrations\AbstractMigration, use Doctrine\DBAL\Migrations\AbstractMigration,
@ -14,21 +15,22 @@ class Version20110711161043 extends AbstractMigration
{ {
public function up(Schema $schema) public function up(Schema $schema)
{ {
/* 1) update cc_files table to include to "directory" column */
//CREATE the default value of "/srv/airtime/stor", this can be updated later in the upgrade script.
$this->_addSql("INSERT INTO cc_music_dirs (type, directory) VALUES ('stor', '/srv/airtime/stor');"); $this->_addSql("INSERT INTO cc_music_dirs (type, directory) VALUES ('stor', '/srv/airtime/stor');");
$this->_addSql("INSERT INTO cc_music_dirs (type, directory) VALUES ('upgrade', '');"); $this->_addSql("INSERT INTO cc_music_dirs (type, directory) VALUES ('upgrade', '');");
$cc_music_dirs = $schema->getTable('cc_music_dirs'); $cc_music_dirs = $schema->getTable('cc_music_dirs');
//start cc_files modifications /* 2) create a foreign key relationship from cc_files to cc_music_dirs */
$cc_files = $schema->getTable('cc_files'); $cc_files = $schema->getTable('cc_files');
$cc_files->addColumn('directory', 'integer', array('default'=> 2)); $cc_files->addColumn('directory', 'integer', array('default'=> 2));
$cc_files->addNamedForeignKeyConstraint('cc_music_dirs_folder_fkey', $cc_music_dirs, array('directory'), array('id'), array('onDelete' => 'CASCADE')); $cc_files->addNamedForeignKeyConstraint('cc_music_dirs_folder_fkey', $cc_music_dirs, array('directory'), array('id'), array('onDelete' => 'CASCADE'));
//end cc_files modifications
/* 3) create a foreign key relationship from cc_schedule to cc_files */
$cc_schedule = $schema->getTable('cc_schedule');
$cc_schedule->addNamedForeignKeyConstraint('cc_files_folder_fkey', $cc_files, array('file_id'), array('id'), array('onDelete' => 'CASCADE'));
} }
public function down(Schema $schema) public function down(Schema $schema)

View file

@ -8,7 +8,9 @@
//Pear classes. //Pear classes.
set_include_path(__DIR__.'/../../airtime_mvc/library/pear' . PATH_SEPARATOR . get_include_path()); set_include_path(__DIR__.'/../../airtime_mvc/library/pear' . PATH_SEPARATOR . get_include_path());
require_once('DB.php'); require_once('DB.php');
require_once(__DIR__.'/../../airtime_mvc/application/configs/constants.php');
require_once(dirname(__FILE__).'/AirtimeIni.php'); require_once(dirname(__FILE__).'/AirtimeIni.php');
if(exec("whoami") != "root"){ if(exec("whoami") != "root"){
@ -87,7 +89,9 @@ if (strcmp($version, "1.9.0") < 0){
//set the new version in the database. //set the new version in the database.
$sql = "DELETE FROM cc_pref WHERE keystr = 'system_version'"; $sql = "DELETE FROM cc_pref WHERE keystr = 'system_version'";
$CC_DBC->query($sql); $CC_DBC->query($sql);
$sql = "INSERT INTO cc_pref (keystr, valstr) VALUES ('system_version', '1.9.0-devel')";
$newVersion = AIRTIME_VERSION;
$sql = "INSERT INTO cc_pref (keystr, valstr) VALUES ('system_version', '$newVersion')";
$CC_DBC->query($sql); $CC_DBC->query($sql);

View file

@ -0,0 +1,83 @@
<?php
/* THIS FILE IS NOT MEANT FOR CUSTOMIZING.
* PLEASE EDIT THE FOLLOWING TO CHANGE YOUR CONFIG:
* /etc/airtime/airtime.conf
* /etc/airtime/pypo.cfg
* /etc/airtime/recorder.cfg
*/
global $CC_CONFIG;
$CC_CONFIG = array(
// prefix for table names in the database
'tblNamePrefix' => 'cc_',
/* ================================================ storage configuration */
'soundcloud-client-id' => '2CLCxcSXYzx7QhhPVHN4A',
'soundcloud-client-secret' => 'pZ7beWmF06epXLHVUP1ufOg2oEnIt9XhE8l8xt0bBs',
"rootDir" => __DIR__."/../..",
'pearPath' => dirname(__FILE__).'/../../../airtime_mvc/library/pear',
'zendPath' => dirname(__FILE__).'/../../../airtime_mvc/library/Zend',
'phingPath' => dirname(__FILE__).'/../../../airtime_mvc/library/phing'
);
$CC_CONFIG = Config::loadConfig($CC_CONFIG);
// Add database table names
$CC_CONFIG['playListTable'] = $CC_CONFIG['tblNamePrefix'].'playlist';
$CC_CONFIG['playListContentsTable'] = $CC_CONFIG['tblNamePrefix'].'playlistcontents';
$CC_CONFIG['filesTable'] = $CC_CONFIG['tblNamePrefix'].'files';
$CC_CONFIG['accessTable'] = $CC_CONFIG['tblNamePrefix'].'access';
$CC_CONFIG['permTable'] = $CC_CONFIG['tblNamePrefix'].'perms';
$CC_CONFIG['sessTable'] = $CC_CONFIG['tblNamePrefix'].'sess';
$CC_CONFIG['subjTable'] = $CC_CONFIG['tblNamePrefix'].'subjs';
$CC_CONFIG['smembTable'] = $CC_CONFIG['tblNamePrefix'].'smemb';
$CC_CONFIG['prefTable'] = $CC_CONFIG['tblNamePrefix'].'pref';
$CC_CONFIG['scheduleTable'] = $CC_CONFIG['tblNamePrefix'].'schedule';
$CC_CONFIG['playListTimeView'] = $CC_CONFIG['tblNamePrefix'].'playlisttimes';
$CC_CONFIG['showSchedule'] = $CC_CONFIG['tblNamePrefix'].'show_schedule';
$CC_CONFIG['showDays'] = $CC_CONFIG['tblNamePrefix'].'show_days';
$CC_CONFIG['showTable'] = $CC_CONFIG['tblNamePrefix'].'show';
$CC_CONFIG['showInstances'] = $CC_CONFIG['tblNamePrefix'].'show_instances';
$CC_CONFIG['playListSequence'] = $CC_CONFIG['playListTable'].'_id';
$CC_CONFIG['filesSequence'] = $CC_CONFIG['filesTable'].'_id';
$CC_CONFIG['prefSequence'] = $CC_CONFIG['prefTable'].'_id';
$CC_CONFIG['permSequence'] = $CC_CONFIG['permTable'].'_id';
$CC_CONFIG['subjSequence'] = $CC_CONFIG['subjTable'].'_id';
$CC_CONFIG['smembSequence'] = $CC_CONFIG['smembTable'].'_id';
// Add libs to the PHP path
$old_include_path = get_include_path();
set_include_path('.'.PATH_SEPARATOR.$CC_CONFIG['pearPath']
.PATH_SEPARATOR.$CC_CONFIG['zendPath']
.PATH_SEPARATOR.$old_include_path);
class Config {
public static function loadConfig($CC_CONFIG) {
$values = parse_ini_file('/etc/airtime/airtime.conf', true);
// Name of the web server user
$CC_CONFIG['webServerUser'] = $values['general']['web_server_user'];
$CC_CONFIG['rabbitmq'] = $values['rabbitmq'];
$CC_CONFIG['baseUrl'] = $values['general']['base_url'];
$CC_CONFIG['basePort'] = $values['general']['base_port'];
// Database config
$CC_CONFIG['dsn']['username'] = $values['database']['dbuser'];
$CC_CONFIG['dsn']['password'] = $values['database']['dbpass'];
$CC_CONFIG['dsn']['hostspec'] = $values['database']['host'];
$CC_CONFIG['dsn']['phptype'] = 'pgsql';
$CC_CONFIG['dsn']['database'] = $values['database']['dbname'];
$CC_CONFIG['apiKey'] = array($values['general']['api_key']);
$CC_CONFIG['soundcloud-connection-retries'] = $values['soundcloud']['connection_retries'];
$CC_CONFIG['soundcloud-connection-wait'] = $values['soundcloud']['time_between_retries'];
return $CC_CONFIG;
}
}

View file

@ -57,6 +57,9 @@ class AirtimeProcessEvent(ProcessEvent):
#file created is a tmp file which will be modified and then moved back to the original filename. #file created is a tmp file which will be modified and then moved back to the original filename.
#Easy Tag creates this when changing metadata of ogg files. #Easy Tag creates this when changing metadata of ogg files.
self.temp_files[pathname] = None self.temp_files[pathname] = None
#file is being overwritten/replaced in GUI.
elif "goutputstream" in pathname:
self.temp_files[pathname] = None
elif self.mmc.is_audio_file(pathname): elif self.mmc.is_audio_file(pathname):
if self.mmc.is_parent_directory(pathname, self.config.organize_directory): if self.mmc.is_parent_directory(pathname, self.config.organize_directory):
#file was created in /srv/airtime/stor/organize. Need to process and move #file was created in /srv/airtime/stor/organize. Need to process and move

View file

@ -47,10 +47,10 @@ def copy_or_move_files_to(paths, dest, flag):
if( 'mp3' in ext or 'ogg' in ext ): if( 'mp3' in ext or 'ogg' in ext ):
destfile = dest+os.path.basename(path) destfile = dest+os.path.basename(path)
if(flag == 'copy'): if(flag == 'copy'):
print "Copying %(src)s to %(dest)s....." % {'src':path, 'dest':destfile} print "Copying %(src)s to %(dest)s..." % {'src':path, 'dest':destfile}
shutil.copy2(path, destfile) shutil.copy2(path, destfile)
elif(flag == 'move'): elif(flag == 'move'):
print "Moving %(src)s to %(dest)s....." % {'src':path, 'dest':destfile} print "Moving %(src)s to %(dest)s..." % {'src':path, 'dest':destfile}
shutil.move(path, destfile) shutil.move(path, destfile)
else: else:
print "Cannot find file or path: %s" % path print "Cannot find file or path: %s" % path
@ -95,7 +95,7 @@ def printHelp():
======================== ========================
There are two ways to import audio files into Airtime: There are two ways to import audio files into Airtime:
1) Copy or move files into the storage folder 1) Use airtime-import to copy or move files into the storage folder.
Copied or moved files will be placed into the folder: Copied or moved files will be placed into the folder:
%s %s
@ -103,12 +103,12 @@ There are two ways to import audio files into Airtime:
Files will be automatically organized into the structure Files will be automatically organized into the structure
"Artist/Album/TrackNumber-TrackName-Bitrate.file_extension". "Artist/Album/TrackNumber-TrackName-Bitrate.file_extension".
2) Add a folder to the Airtime library("watch" a folder) 2) Use airtime-import to add a folder to the Airtime library ("watch" a folder).
All the files in the watched folder will be imported to Airtime and the 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 folder will be monitored to automatically detect any changes. Hence any
changes done in the folder(add, delete, edit a file) will trigger changes done in the folder(add, delete, edit a file) will trigger
updates in Airtime libarary. updates in Airtime library.
""" % storage_dir """ % storage_dir
parser.print_help() parser.print_help()
print "" print ""
@ -117,7 +117,7 @@ def CopyAction(option, opt, value, parser):
errorIfMultipleOption(parser.rargs) errorIfMultipleOption(parser.rargs)
stor = helper_get_stor_dir() stor = helper_get_stor_dir()
if(stor is None): if(stor is None):
exit("Unable to connect to the server.") exit("Unable to connect to the Airtime server.")
dest = stor+"organize/" dest = stor+"organize/"
copy_or_move_files_to(parser.rargs, dest, 'copy') copy_or_move_files_to(parser.rargs, dest, 'copy')
@ -125,16 +125,16 @@ def MoveAction(option, opt, value, parser):
errorIfMultipleOption(parser.rargs) errorIfMultipleOption(parser.rargs)
stor = helper_get_stor_dir() stor = helper_get_stor_dir()
if(stor is None): if(stor is None):
exit("Unable to connect to the server.") exit("Unable to connect to the Airtime server.")
dest = stor+"organize/" dest = stor+"organize/"
copy_or_move_files_to(parser.rargs, dest, 'move') copy_or_move_files_to(parser.rargs, dest, 'move')
def WatchAddAction(option, opt, value, parser): def WatchAddAction(option, opt, value, parser):
errorIfMultipleOption(parser.rargs) errorIfMultipleOption(parser.rargs)
if(len(parser.rargs) > 1): if(len(parser.rargs) > 1):
raise OptionValueError("Too many arguments. This option need exactly one argument.") raise OptionValueError("Too many arguments. This option requires exactly one argument.")
elif(len(parser.rargs) == 0 ): elif(len(parser.rargs) == 0 ):
raise OptionValueError("No argument found. This option need exactly one argument.") raise OptionValueError("No argument found. This option requires exactly one argument.")
path = parser.rargs[0] path = parser.rargs[0]
if(os.path.isdir(path)): if(os.path.isdir(path)):
res = api_client.add_watched_dir(path) res = api_client.add_watched_dir(path)
@ -144,17 +144,17 @@ def WatchAddAction(option, opt, value, parser):
if(res['msg']['code'] == 0): if(res['msg']['code'] == 0):
print "%s added to watched folder list successfully" % path print "%s added to watched folder list successfully" % path
else: else:
print "Adding a watched folder failed. : %s" % res['msg']['error'] print "Adding a watched folder failed: %s" % res['msg']['error']
else: else:
print "Given path is not a directory: %s" % path print "Given path is not a directory: %s" % path
def WatchListAction(option, opt, value, parser): def WatchListAction(option, opt, value, parser):
errorIfMultipleOption(parser.rargs) errorIfMultipleOption(parser.rargs)
if(len(parser.rargs) > 0): if(len(parser.rargs) > 0):
raise OptionValueError("This option doesn't take any argument.") raise OptionValueError("This option doesn't take any arguments.")
res = api_client.list_all_watched_dirs() res = api_client.list_all_watched_dirs()
if(res is None): if(res is None):
exit("Unable to connect to the server.") exit("Unable to connect to the Airtime server.")
dirs = res["dirs"].items() dirs = res["dirs"].items()
# there will be always 1 which is storage folder # there will be always 1 which is storage folder
if(len(dirs) == 1): if(len(dirs) == 1):
@ -167,21 +167,21 @@ def WatchListAction(option, opt, value, parser):
def WatchRemoveAction(option, opt, value, parser): def WatchRemoveAction(option, opt, value, parser):
errorIfMultipleOption(parser.rargs) errorIfMultipleOption(parser.rargs)
if(len(parser.rargs) > 1): if(len(parser.rargs) > 1):
raise OptionValueError("Too many arguments. This option need exactly one argument.") raise OptionValueError("Too many arguments. This option requires exactly one argument.")
elif(len(parser.rargs) == 0 ): elif(len(parser.rargs) == 0 ):
raise OptionValueError("No argument found. This option need exactly one argument.") raise OptionValueError("No argument found. This option requires exactly one argument.")
path = parser.rargs[0] path = parser.rargs[0]
if(os.path.isdir(path)): if(os.path.isdir(path)):
res = api_client.remove_watched_dir(path) res = api_client.remove_watched_dir(path)
if(res is None): if(res is None):
exit("Unable to connect to the server.") exit("Unable to connect to the Airtime server.")
# sucess # sucess
if(res['msg']['code'] == 0): if(res['msg']['code'] == 0):
print "%s removed from watched folder list successfully" % path print "%s removed from watch folder list successfully." % path
else: else:
print "Removing a watched folder failed. : %s" % res['msg']['error'] print "Removing the watch folder failed: %s" % res['msg']['error']
else: else:
print "Given path is not a directory: %s" % path print "The given path is not a directory: %s" % path
def StorageSetAction(option, opt, value, parser): def StorageSetAction(option, opt, value, parser):
bypass = False bypass = False
@ -199,38 +199,38 @@ def StorageSetAction(option, opt, value, parser):
confirm = raw_input("Are you sure you want to change the storage direcory? (y/N)") confirm = raw_input("Are you sure you want to change the storage direcory? (y/N)")
confirm = confirm or 'N' confirm = confirm or 'N'
while(confirm not in possibleInput): while(confirm not in possibleInput):
print "Not an acceptable input: %s" % confirm print "Not an acceptable input: %s\n" % confirm
confirm = raw_input("Are you sure you want to change the storage direcory? (y/N) ") confirm = raw_input("Are you sure you want to change the storage direcory? (y/N) ")
confirm = confirm or 'N' confirm = confirm or 'N'
if(confirm == 'n' or confirm =='N'): if(confirm == 'n' or confirm =='N'):
sys.exit(1) sys.exit(1)
if(len(parser.rargs) > 1): if(len(parser.rargs) > 1):
raise OptionValueError("Too many arguments. This option need exactly one argument.") raise OptionValueError("Too many arguments. This option requires exactly one argument.")
elif(len(parser.rargs) == 0 ): elif(len(parser.rargs) == 0 ):
raise OptionValueError("No argument found. This option need exactly one argument.") raise OptionValueError("No argument found. This option requires exactly one argument.")
path = parser.rargs[0] path = parser.rargs[0]
if(os.path.isdir(path)): if(os.path.isdir(path)):
res = api_client.set_storage_dir(path) res = api_client.set_storage_dir(path)
if(res is None): if(res is None):
exit("Unable to connect to the server.") exit("Unable to connect to the Airtime server.")
# sucess # sucess
if(res['msg']['code'] == 0): if(res['msg']['code'] == 0):
print "Successfully set storage folder to %s" % path print "Successfully set storage folder to %s" % path
else: else:
print "Setting storage folder to failed.: %s" % res['msg']['error'] print "Setting storage folder failed: %s" % res['msg']['error']
else: else:
print "Given path is not a directory: %s" % path print "The given path is not a directory: %s" % path
def StorageGetAction(option, opt, value, parser): def StorageGetAction(option, opt, value, parser):
errorIfMultipleOption(parser.rargs) errorIfMultipleOption(parser.rargs)
if(len(parser.rargs) > 0): if(len(parser.rargs) > 0):
raise OptionValueError("This option doesn't take any argument.") raise OptionValueError("This option does not take any arguments.")
print helper_get_stor_dir() print helper_get_stor_dir()
usage = """[-c|--copy FILE/DIR [FILE/DIR...]] [-m|--move FILE/DIR [FILE/DIR...]] usage = """[-c|--copy FILE/DIR [FILE/DIR...]] [-m|--move FILE/DIR [FILE/DIR...]]
[--watch-add DIR] [--watch-list] [--watch-remve DIR] [--watch-add DIR] [--watch-list] [--watch-remove DIR]
[--storage-dir-set DIR] [--storage-dir-get]""" [--storage-dir-set DIR] [--storage-dir-get]"""
parser = OptionParser(usage=usage, add_help_option=False) parser = OptionParser(usage=usage, add_help_option=False)