CC-2524:MusicDir.php: adding error handling
- following functions now handle error and return code and error message if there is an error: addDir(), setStorDir(), removeWatchedDir() - fixed airtime-importy.py to work with new MusicDir functions
This commit is contained in:
parent
ece84a04c5
commit
e47f80802e
|
@ -569,7 +569,7 @@ class ApiController extends Zend_Controller_Action
|
|||
exit;
|
||||
}
|
||||
|
||||
$this->view = MusicDir::addWatchedDir($path);
|
||||
$this->view->msg = MusicDir::addWatchedDir($path);
|
||||
}
|
||||
|
||||
public function removeWatchedDirAction() {
|
||||
|
@ -586,8 +586,7 @@ class ApiController extends Zend_Controller_Action
|
|||
exit;
|
||||
}
|
||||
|
||||
$dir = MusicDir::getDirByPath($path);
|
||||
$this->view = $dir->remove();
|
||||
$this->view->msg = MusicDir::removeWatchedDir($path);
|
||||
}
|
||||
|
||||
public function setStorageDirAction() {
|
||||
|
@ -603,8 +602,8 @@ class ApiController extends Zend_Controller_Action
|
|||
print 'You are not allowed to access this resource.';
|
||||
exit;
|
||||
}
|
||||
MusicDir::setStorDir($path);
|
||||
$this->view = MusicDir::getStorDir()->getDirectory();
|
||||
|
||||
$this->view->msg = MusicDir::setStorDir($path);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -47,12 +47,16 @@ class MusicDir {
|
|||
{
|
||||
$dir = new CcMusicDirs();
|
||||
$dir->setType($p_type);
|
||||
$dir->setDirectory($p_path);
|
||||
$dir->save();
|
||||
$temp = $dir->setDirectory($p_path);
|
||||
try{
|
||||
$dir->save();
|
||||
return array("code"=>0);
|
||||
}
|
||||
catch(Exception $e){
|
||||
//echo $e->getMessage();
|
||||
return array("code"=>1, "error"=>"$p_path is already set as the current storage dir or the watched folders");
|
||||
}
|
||||
|
||||
$mus_dir = new MusicDir($dir);
|
||||
|
||||
return $mus_dir;
|
||||
}
|
||||
|
||||
public static function addWatchedDir($p_path)
|
||||
|
@ -75,8 +79,13 @@ class MusicDir {
|
|||
->filterByDirectory($p_path)
|
||||
->findOne();
|
||||
|
||||
$mus_dir = new MusicDir($dir);
|
||||
return $mus_dir;
|
||||
if($dir == NULL){
|
||||
return null;
|
||||
}
|
||||
else{
|
||||
$mus_dir = new MusicDir($dir);
|
||||
return $mus_dir;
|
||||
}
|
||||
}
|
||||
|
||||
public static function getWatchedDirs()
|
||||
|
@ -109,8 +118,14 @@ class MusicDir {
|
|||
public static function setStorDir($p_dir)
|
||||
{
|
||||
$dir = self::getStorDir();
|
||||
// we need to check if p_dir is in watched list
|
||||
$dir->setDirectory($p_dir);
|
||||
// if $p_dir doesn't exist in DB
|
||||
$exist = $dir->getDirByPath($p_dir);
|
||||
if($exist == NULL){
|
||||
$dir->setDirectory($p_dir);
|
||||
return array("code"=>0);
|
||||
}else{
|
||||
return array("code"=>1, "error"=>"$p_dir is already set as the current storage dir or the watched folders");
|
||||
}
|
||||
}
|
||||
|
||||
public static function getWatchedDirFromFilepath($p_filepath)
|
||||
|
@ -129,6 +144,16 @@ class MusicDir {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static function removeWatchedDir($p_dir){
|
||||
$dir = MusicDir::getDirByPath($p_dir);
|
||||
if($dir == NULL){
|
||||
return array("code"=>1,"error"=>"$p_dir doesn't exist in the watched list");
|
||||
}else{
|
||||
$dir->remove();
|
||||
return array("code"=>0);
|
||||
}
|
||||
}
|
||||
|
||||
public static function splitFilePath($p_filepath)
|
||||
{
|
||||
$mus_dir = self::getWatchedDirFromFilepath($p_filepath);
|
||||
|
|
|
@ -46,10 +46,10 @@ def watch_add(args):
|
|||
if(os.path.isdir(args.path)):
|
||||
res = api_client.add_watched_dir(args.path)
|
||||
# sucess
|
||||
if(res == '[]'):
|
||||
if(res['msg']['code'] == 0):
|
||||
print "%s added to watched folder list successfully" % args.path
|
||||
else:
|
||||
print "Adding %s to watched folder list failed.( path already exist in the list )" % args.path
|
||||
print "Adding a watched folder failed. : %s" % res['msg']['error']
|
||||
else:
|
||||
print "Given path is not a directory: %s" % args.path
|
||||
|
||||
|
@ -69,10 +69,10 @@ def watch_remove(args):
|
|||
if(os.path.isdir(args.path)):
|
||||
res = api_client.remove_watched_dir(args.path)
|
||||
# sucess
|
||||
if(res == '[]'):
|
||||
if(res['msg']['code'] == 0):
|
||||
print "%s removed from watched folder list successfully" % args.path
|
||||
else:
|
||||
print "Removing %s from watched folder list failed.( path doesn't exist in the list )" % args.path
|
||||
print "Removing a watched folder failed. : %s" % res['msg']['error']
|
||||
else:
|
||||
print "Given path is not a directory: %s" % args.path
|
||||
|
||||
|
@ -80,10 +80,10 @@ def set_stor_dir(args):
|
|||
if(os.path.isdir(args.path)):
|
||||
res = api_client.set_storage_dir(args.path)
|
||||
# sucess
|
||||
if(res == '[]'):
|
||||
if(res['msg']['code'] == 0):
|
||||
print "Successfully set storage folder to %s" % args.path
|
||||
else:
|
||||
print "Setting storage folder to %s failed." % args.path
|
||||
print "Setting storage folder to failed.: %s" % res['msg']['error']
|
||||
else:
|
||||
print "Given path is not a directory: %s" % args.path
|
||||
|
||||
|
|
|
@ -464,6 +464,7 @@ class AirTimeApiClient(ApiClientInterface):
|
|||
|
||||
req = urllib2.Request(url)
|
||||
response = urllib2.urlopen(req).read()
|
||||
response = json.loads(response)
|
||||
except Exception, e:
|
||||
response = None
|
||||
logger.error("Exception: %s", e)
|
||||
|
@ -480,7 +481,7 @@ class AirTimeApiClient(ApiClientInterface):
|
|||
|
||||
req = urllib2.Request(url)
|
||||
response = urllib2.urlopen(req).read()
|
||||
#response = json.loads(response)
|
||||
response = json.loads(response)
|
||||
except Exception, e:
|
||||
response = None
|
||||
logger.error("Exception: %s", e)
|
||||
|
@ -497,7 +498,7 @@ class AirTimeApiClient(ApiClientInterface):
|
|||
|
||||
req = urllib2.Request(url)
|
||||
response = urllib2.urlopen(req).read()
|
||||
#response = json.loads(response)
|
||||
response = json.loads(response)
|
||||
except Exception, e:
|
||||
response = None
|
||||
logger.error("Exception: %s", e)
|
||||
|
|
Loading…
Reference in New Issue