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="addShowDialog"/>
</controllerFile>
<controllerFile controllerName="Api">
<actionMethod actionName="index"/>
</controllerFile>
</controllersDirectory>
<formsDirectory>
<formFile formName="Login"/>
@ -167,6 +170,9 @@
<viewControllerScriptsDirectory forControllerName="Schedule">
<viewScriptFile forActionName="addShowDialog"/>
</viewControllerScriptsDirectory>
<viewControllerScriptsDirectory forControllerName="Api">
<viewScriptFile forActionName="index"/>
</viewControllerScriptsDirectory>
</viewScriptsDirectory>
<viewHelpersDirectory/>
<viewFiltersDirectory enabled="false"/>
@ -207,6 +213,7 @@
<testApplicationControllerFile filesystemName="SearchControllerTest.php"/>
<testApplicationControllerFile filesystemName="LoginControllerTest.php"/>
<testApplicationControllerFile filesystemName="ScheduleControllerTest.php"/>
<testApplicationControllerFile filesystemName="ApiControllerTest.php"/>
</testApplicationControllerDirectory>
</testApplicationDirectory>
<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('plupload'))
->add(new Zend_Acl_Resource('schedule'))
->add(new Zend_Acl_Resource('api'))
->add(new Zend_Acl_Resource('search'));
/** Creating permissions */
@ -23,6 +24,7 @@ $ccAcl->allow('guest', 'index')
->allow('guest', 'error')
->allow('guest', 'library')
->allow('guest', 'search')
->allow('guest', 'api')
->allow('host', 'plupload')
->allow('host', 'playlist')
->allow('host', 'schedule');

View file

@ -25,6 +25,8 @@ $CC_CONFIG = array(
'apiKey' => array('AAA'),
'apiPath' => "/api/",
'baseFilesDir' => __DIR__."/../../files",
// main directory for storing binary media files
'storageDir' => __DIR__.'/../../files/stor',
@ -162,4 +164,13 @@ set_include_path('.'.PATH_SEPARATOR.$CC_CONFIG['pearPath']
.PATH_SEPARATOR.$CC_CONFIG['zendPath']
.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>
*

View file

@ -401,6 +401,26 @@ class Schedule {
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
* millisecs.

View file

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

View file

@ -251,7 +251,7 @@ class CampcasterApiClient(ApiClientInterface):
logger = logging.getLogger()
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
filename, headers = urllib.urlretrieve(src, dst)
@ -269,7 +269,7 @@ class CampcasterApiClient(ApiClientInterface):
schedule_id = playlist["schedule_id"]
url = self.config["base_url"] + self.config["api_base"] + self.config["update_item_url"]
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)
try:

View file

@ -72,24 +72,24 @@ cue_style = 'pre'
api_key = 'AAA'
# Path to the base of the API
api_base = 'campcaster/'
api_base = '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.
# %%from%% - 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_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_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"
export HOME="/home/pypo/"
# Location of pypo_cli.py Python script
pypo_path="/opt/pypo/bin"
pypo_script="pypo_cli.py"
pypo_path="/opt/pypo/bin/"
pypo_script="pypo-cli.py"
echo "*** Daemontools: starting daemon"
cd ${pypo_path}
exec 2>&1

View file

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

View file

@ -61,7 +61,16 @@ try:
shutil.copy("../scripts/silence-playlist.lsp", BASE_PATH+"files/basic")
shutil.copy("../scripts/silence.mp3", BASE_PATH+"files/basic")
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")
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"
os.system("chmod -R 755 "+BASE_PATH)
@ -95,6 +104,16 @@ try:
output = p.stdout.read()
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."
sys.exit()
print output
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/")

View file

@ -1,12 +1,23 @@
<?php
require_once '../../conf.php';
require_once '../Playlist.php';
require_once '../StoredFile.php';
require_once(__DIR__.'/../../3rd_party/php/propel/runtime/lib/Propel.php');
require_once '../../application/configs/conf.php';
require_once 'DB.php';
require_once '../../application/models/Playlist.php';
require_once '../../application/models/StoredFile.php';
require_once(__DIR__.'/../../library/propel/runtime/lib/Propel.php');
// 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
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";
$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 */
}
}