Converted API functions to Zend Framework. Converted pypo to use

the new Zendified URLs.  Fixed bugs in the daemontool scripts.

The installed scheduler is still not working at this point, but
getting close.
This commit is contained in:
paul.baranowski 2010-12-09 18:44:47 -05:00
parent 38bc0de9a2
commit 84c2a3bceb
13 changed files with 126 additions and 29 deletions

View file

@ -54,6 +54,9 @@
<actionMethod actionName="eventFeed"/> <actionMethod actionName="eventFeed"/>
<actionMethod actionName="addShowDialog"/> <actionMethod actionName="addShowDialog"/>
</controllerFile> </controllerFile>
<controllerFile controllerName="Api">
<actionMethod actionName="index"/>
</controllerFile>
</controllersDirectory> </controllersDirectory>
<formsDirectory> <formsDirectory>
<formFile formName="Login"/> <formFile formName="Login"/>
@ -167,6 +170,9 @@
<viewControllerScriptsDirectory forControllerName="Schedule"> <viewControllerScriptsDirectory forControllerName="Schedule">
<viewScriptFile forActionName="addShowDialog"/> <viewScriptFile forActionName="addShowDialog"/>
</viewControllerScriptsDirectory> </viewControllerScriptsDirectory>
<viewControllerScriptsDirectory forControllerName="Api">
<viewScriptFile forActionName="index"/>
</viewControllerScriptsDirectory>
</viewScriptsDirectory> </viewScriptsDirectory>
<viewHelpersDirectory/> <viewHelpersDirectory/>
<viewFiltersDirectory enabled="false"/> <viewFiltersDirectory enabled="false"/>
@ -207,6 +213,7 @@
<testApplicationControllerFile filesystemName="SearchControllerTest.php"/> <testApplicationControllerFile filesystemName="SearchControllerTest.php"/>
<testApplicationControllerFile filesystemName="LoginControllerTest.php"/> <testApplicationControllerFile filesystemName="LoginControllerTest.php"/>
<testApplicationControllerFile filesystemName="ScheduleControllerTest.php"/> <testApplicationControllerFile filesystemName="ScheduleControllerTest.php"/>
<testApplicationControllerFile filesystemName="ApiControllerTest.php"/>
</testApplicationControllerDirectory> </testApplicationControllerDirectory>
</testApplicationDirectory> </testApplicationDirectory>
<testLibraryDirectory> <testLibraryDirectory>

View file

@ -15,6 +15,7 @@ $ccAcl->add(new Zend_Acl_Resource('library'))
->add(new Zend_Acl_Resource('playlist')) ->add(new Zend_Acl_Resource('playlist'))
->add(new Zend_Acl_Resource('plupload')) ->add(new Zend_Acl_Resource('plupload'))
->add(new Zend_Acl_Resource('schedule')) ->add(new Zend_Acl_Resource('schedule'))
->add(new Zend_Acl_Resource('api'))
->add(new Zend_Acl_Resource('search')); ->add(new Zend_Acl_Resource('search'));
/** Creating permissions */ /** Creating permissions */
@ -23,6 +24,7 @@ $ccAcl->allow('guest', 'index')
->allow('guest', 'error') ->allow('guest', 'error')
->allow('guest', 'library') ->allow('guest', 'library')
->allow('guest', 'search') ->allow('guest', 'search')
->allow('guest', 'api')
->allow('host', 'plupload') ->allow('host', 'plupload')
->allow('host', 'playlist') ->allow('host', 'playlist')
->allow('host', 'schedule'); ->allow('host', 'schedule');

View file

@ -25,6 +25,8 @@ $CC_CONFIG = array(
'apiKey' => array('AAA'), 'apiKey' => array('AAA'),
'apiPath' => "/api/",
'baseFilesDir' => __DIR__."/../../files", 'baseFilesDir' => __DIR__."/../../files",
// main directory for storing binary media files // main directory for storing binary media files
'storageDir' => __DIR__.'/../../files/stor', 'storageDir' => __DIR__.'/../../files/stor',
@ -162,4 +164,13 @@ set_include_path('.'.PATH_SEPARATOR.$CC_CONFIG['pearPath']
.PATH_SEPARATOR.$CC_CONFIG['zendPath'] .PATH_SEPARATOR.$CC_CONFIG['zendPath']
.PATH_SEPARATOR.$old_include_path); .PATH_SEPARATOR.$old_include_path);
//$dsn = $CC_CONFIG['dsn'];
//$CC_DBC = DB::connect($dsn, TRUE);
//if (PEAR::isError($CC_DBC)) {
// echo "ERROR: ".$CC_DBC->getMessage()." ".$CC_DBC->getUserInfo()."\n";
// exit(1);
//}
//$CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC);
?> ?>

View file

@ -102,6 +102,13 @@ class Playlist {
} }
public static function findPlaylistByName($p_name)
{
$res = CcPlaylistQuery::create()->findByDbName($p_name);
return $res;
}
/** /**
* Fetch instance of Playlist object.<br> * Fetch instance of Playlist object.<br>
* *

View file

@ -401,6 +401,26 @@ class Schedule {
return $t[0]."-".$t[1]."-".$t[2]." ".$t[3].":".$t[4].":00"; return $t[0]."-".$t[1]."-".$t[2]." ".$t[3].":".$t[4].":00";
} }
/**
* Return true if the input string is in the format YYYY-MM-DD-HH-mm
*
* @param string $p_time
* @return boolean
*/
public static function ValidPypoTimeFormat($p_time)
{
$t = explode("-", $p_time);
if (count($t) != 5) {
return false;
}
foreach ($t as $part) {
if (!is_numeric($part)) {
return false;
}
}
return true;
}
/** /**
* Converts a time value as a string (with format HH:MM:SS.mmmmmm) to * Converts a time value as a string (with format HH:MM:SS.mmmmmm) to
* millisecs. * millisecs.

View file

@ -1697,7 +1697,7 @@ class StoredFile {
{ {
global $CC_CONFIG; global $CC_CONFIG;
return "http://".$CC_CONFIG["storageUrlHost"] return "http://".$CC_CONFIG["storageUrlHost"]
.$CC_CONFIG["apiPath"]."get_media.php?file=" .$CC_CONFIG["apiPath"]."getMedia/file/"
.$this->gunid.".".$this->getFileExtension(); .$this->gunid.".".$this->getFileExtension();
} }

View file

@ -251,7 +251,7 @@ class CampcasterApiClient(ApiClientInterface):
logger = logging.getLogger() logger = logging.getLogger()
try: try:
src = src + "&api_key=" + self.config["api_key"] src = src + "/api_key/" + self.config["api_key"]
# check if file exists already before downloading again # check if file exists already before downloading again
filename, headers = urllib.urlretrieve(src, dst) filename, headers = urllib.urlretrieve(src, dst)
@ -269,7 +269,7 @@ class CampcasterApiClient(ApiClientInterface):
schedule_id = playlist["schedule_id"] schedule_id = playlist["schedule_id"]
url = self.config["base_url"] + self.config["api_base"] + self.config["update_item_url"] url = self.config["base_url"] + self.config["api_base"] + self.config["update_item_url"]
url = url.replace("%%schedule_id%%", str(schedule_id)) url = url.replace("%%schedule_id%%", str(schedule_id))
url += "&api_key=" + self.config["api_key"] url = url.replace("%%api_key%%", self.config["api_key"])
logger.debug(url) logger.debug(url)
try: try:

View file

@ -72,24 +72,24 @@ cue_style = 'pre'
api_key = 'AAA' api_key = 'AAA'
# Path to the base of the API # Path to the base of the API
api_base = 'campcaster/' api_base = 'api/'
# URL to get the version number of the server API # URL to get the version number of the server API
version_url = 'api/api_version.php?api_key=%%api_key%%' version_url = 'version/api_key/%%api_key%%'
# Schedule export path. # Schedule export path.
# %%from%% - starting date/time in the form YYYY-MM-DD-hh-mm # %%from%% - starting date/time in the form YYYY-MM-DD-hh-mm
# %%to%% - starting date/time in the form YYYY-MM-DD-hh-mm # %%to%% - starting date/time in the form YYYY-MM-DD-hh-mm
export_url = 'api/schedule.php?from=%%from%%&to=%%to%%&api_key=%%api_key%%' export_url = 'schedule/api_key/%%api_key%%/from/%%from%%/to/%%to%%'
# Update whether a schedule group has begun playing. # Update whether a schedule group has begun playing.
update_item_url = 'api/notify_schedule_group_play.php?schedule_id=%%schedule_id%%' update_item_url = 'notifyScheduleGroupPlay/api_key/%%api_key%%/schedule_id/%%schedule_id%%'
# Update whether an audio clip is currently playing. # Update whether an audio clip is currently playing.
update_start_playing_url = 'api/notify_media_item_start_play.php?media_id=%%media_id%%&schedule_id=%%schedule_id%%' update_start_playing_url = 'notifyMediaItemStartPlay/api_key/%%api_key%%/media_id/%%media_id%%/schedule_id/%%schedule_id%%'
# ??? # ???
generate_range_url = 'api/generate_range_dp.php' generate_range_url = 'generate_range_dp.php'
############## ##############

View file

@ -2,8 +2,8 @@
pypo_user="pypo" pypo_user="pypo"
export HOME="/home/pypo/" export HOME="/home/pypo/"
# Location of pypo_cli.py Python script # Location of pypo_cli.py Python script
pypo_path="/opt/pypo/bin" pypo_path="/opt/pypo/bin/"
pypo_script="pypo_cli.py" pypo_script="pypo-cli.py"
echo "*** Daemontools: starting daemon" echo "*** Daemontools: starting daemon"
cd ${pypo_path} cd ${pypo_path}
exec 2>&1 exec 2>&1

View file

@ -2,8 +2,8 @@
pypo_user="pypo" pypo_user="pypo"
export HOME="/home/pypo/" export HOME="/home/pypo/"
# Location of pypo_cli.py Python script # Location of pypo_cli.py Python script
pypo_path="/opt/pypo/bin" pypo_path="/opt/pypo/bin/"
pypo_script="pypo_cli.py" pypo_script="pypo-cli.py"
echo "*** Daemontools: starting daemon" echo "*** Daemontools: starting daemon"
cd ${pypo_path} cd ${pypo_path}
exec 2>&1 exec 2>&1

View file

@ -61,7 +61,16 @@ try:
shutil.copy("../scripts/silence-playlist.lsp", BASE_PATH+"files/basic") shutil.copy("../scripts/silence-playlist.lsp", BASE_PATH+"files/basic")
shutil.copy("../scripts/silence.mp3", BASE_PATH+"files/basic") shutil.copy("../scripts/silence.mp3", BASE_PATH+"files/basic")
shutil.copy("../pypo-cli.py", BASE_PATH+"bin") shutil.copy("../pypo-cli.py", BASE_PATH+"bin")
shutil.copy("../pypo-notify.py", BASE_PATH+"bin")
shutil.copy("../logging.cfg", BASE_PATH+"bin")
shutil.copy("../config.cfg", BASE_PATH+"bin")
shutil.copy("../pypo-log.sh", BASE_PATH+"bin") shutil.copy("../pypo-log.sh", BASE_PATH+"bin")
print "Copying directory util"
shutil.copytree("../util", BASE_PATH+"bin/util")
print "Copying directory api_clients"
shutil.copytree("../api_clients", BASE_PATH+"bin/api_clients")
print "Copying directory scripts"
shutil.copytree("../scripts", BASE_PATH+"bin/scripts")
print "Setting permissions" print "Setting permissions"
os.system("chmod -R 755 "+BASE_PATH) os.system("chmod -R 755 "+BASE_PATH)
@ -95,8 +104,18 @@ try:
output = p.stdout.read() output = p.stdout.read()
if (output.find("unable to open supervise/ok: file does not exist") >= 0): if (output.find("unable to open supervise/ok: file does not exist") >= 0):
print "Install has completed, but daemontools is not running, please make sure you have it installed and then reboot." print "Install has completed, but daemontools is not running, please make sure you have it installed and then reboot."
sys.exit()
print output
#os.symlink(BASE_PATH+"bin/pypo-log.sh", "/usr/local/bin/") p = Popen('svstat /etc/service/pypo-push', shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
output = p.stdout.read()
print output
p = Popen('svstat /etc/service/pypo-liquidsoap', shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
output = p.stdout.read()
print output
#os.symlink(BASE_PATH+"bin/pypo-log.sh", "/usr/local/bin/")
except Exception, e: except Exception, e:

View file

@ -1,12 +1,23 @@
<?php <?php
require_once '../../conf.php'; require_once '../../application/configs/conf.php';
require_once '../Playlist.php'; require_once 'DB.php';
require_once '../StoredFile.php'; require_once '../../application/models/Playlist.php';
require_once(__DIR__.'/../../3rd_party/php/propel/runtime/lib/Propel.php'); require_once '../../application/models/StoredFile.php';
require_once(__DIR__.'/../../library/propel/runtime/lib/Propel.php');
// Initialize Propel with the runtime configuration // Initialize Propel with the runtime configuration
Propel::init(__DIR__."/../propel-db/build/conf/campcaster-conf.php"); Propel::init(__DIR__."/../../application/configs/propel-config.php");
// Add the generated 'classes' directory to the include path // Add the generated 'classes' directory to the include path
set_include_path(__DIR__."/../propel-db/build/classes" . PATH_SEPARATOR . get_include_path()); set_include_path(__DIR__."/../../application/models" . PATH_SEPARATOR . get_include_path());
$dsn = $CC_CONFIG['dsn'];
$CC_DBC = DB::connect($dsn, TRUE);
if (PEAR::isError($CC_DBC)) {
echo "ERROR: ".$CC_DBC->getMessage()." ".$CC_DBC->getUserInfo()."\n";
exit(1);
}
$CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC);
$playlistName = "pypo_playlist_test"; $playlistName = "pypo_playlist_test";
$minutesFromNow = 1; $minutesFromNow = 1;

View file

@ -0,0 +1,20 @@
<?php
require_once 'PHPUnit/Framework/TestCase.php';
class ApiControllerTest extends PHPUnit_Framework_TestCase
{
public function setUp()
{
/* Setup Routine */
}
public function tearDown()
{
/* Tear Down Routine */
}
}