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

This commit is contained in:
James 2012-04-13 17:18:52 -04:00
commit a6f44226b9
8 changed files with 65 additions and 117 deletions

View File

@ -64,6 +64,10 @@ class Config {
$CC_CONFIG['cache_ahead_hours'] = $values['general']['cache_ahead_hours'];
$CC_CONFIG['monit_user'] = $values['monit']['monit_user'];
$CC_CONFIG['monit_password'] = $values['monit']['monit_password'];
// Database config
$CC_CONFIG['dsn']['username'] = $values['database']['dbuser'];
$CC_CONFIG['dsn']['password'] = $values['database']['dbpass'];

View File

@ -17,15 +17,23 @@ class Logging {
self::$_path = $path;
}
public static function toString($p_msg){
if (is_array($p_msg)){
return print_r($p_msg, true);
} else {
return $p_msg;
}
}
public static function log($p_msg){
$logger = self::getLogger();
$logger->info($p_msg);
$logger->info(self::toString($p_msg));
}
public static function debug($p_msg){
if (defined('APPLICATION_ENV') && APPLICATION_ENV == "development"){
$logger = self::getLogger();
$logger->debug($p_msg);
$logger->debug(self::toString($p_msg));
}
}
}

View File

@ -4,20 +4,25 @@ class Application_Model_Systemstatus
{
public static function GetMonitStatus($p_ip){
global $CC_CONFIG;
$monit_user = $CC_CONFIG['monit_user'];
$monit_password = $CC_CONFIG['monit_password'];
$url = "http://$p_ip:2812/_status?format=xml";
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, "guest:airtime");
curl_setopt($ch, CURLOPT_USERPWD, "$monit_user:$monit_password");
//wait a max of 3 seconds before aborting connection attempt
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
$result = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
$docRoot = null;
if ($result != FALSE){
if ($result !== FALSE && $info["http_code"] === 200){
if ($result != ""){
$xmlDoc = new DOMDocument();
$xmlDoc->loadXML($result);

View File

@ -22,6 +22,10 @@ base_port = 80
;cache scheduled media files.
cache_ahead_hours = 1
[monit]
monit_user = guest
monit_password = airtime
[soundcloud]
connection_retries = 3
time_between_retries = 60

View File

@ -520,10 +520,14 @@ var AIRTIME = (function(AIRTIME) {
function checkImportStatus(){
$.getJSON('/Preference/is-import-in-progress', function(data){
var div = $('#import_status');
var table = $('#library_display').dataTable();
if (data == true){
div.show();
}
else{
if ($(div).is(':visible')) {
table.fnDraw();
}
div.hide();
}
});

View File

@ -22,6 +22,10 @@ base_port = 80
;cache scheduled media files.
cache_ahead_hours = 1
[monit]
monit_user = guest
monit_password = airtime
[soundcloud]
connection_retries = 3
time_between_retries = 60

View File

@ -399,7 +399,6 @@ class PypoFetch(Thread):
media_filtered[key] = media_item
self.media_prepare_queue.put(copy.copy(media_filtered))
self.prepare_media(media_filtered)
except Exception, e: self.logger.error("%s", e)
# Send the data to pypo-push
@ -410,106 +409,6 @@ class PypoFetch(Thread):
# cleanup
try: self.cache_cleanup(media)
except Exception, e: self.logger.error("%s", e)
def prepare_media(self, media):
"""
Iterate through the list of media items in "media" append some
attributes such as show_name
"""
try:
mediaKeys = sorted(media.iterkeys())
for mkey in mediaKeys:
media_item = media[mkey]
except Exception, e:
self.logger.error("%s", e)
return media
def handle_media_file(self, media_item, dst):
"""
Download and cache the media item.
"""
self.logger.debug("Processing track %s", media_item['uri'])
try:
#blocking function to download the media item
#self.download_file(media_item, dst)
self.copy_file(media_item, dst)
if os.access(dst, os.R_OK):
# check filesize (avoid zero-byte files)
try:
fsize = os.path.getsize(dst)
if fsize > 0:
return True
except Exception, e:
self.logger.error("%s", e)
fsize = 0
else:
self.logger.warning("Cannot read file %s.", dst)
except Exception, e:
self.logger.info("%s", e)
return False
def copy_file(self, media_item, dst):
"""
Copy the file from local library directory. Note that we are not using os.path.exists
since this can lie to us! It seems the best way to get whether a file exists is to actually
do an operation on the file (such as query its size). Getting the file size of a non-existent
file will throw an exception, so we can look for this exception instead of os.path.exists.
"""
src = media_item['uri']
try:
src_size = os.path.getsize(src)
except Exception, e:
self.logger.error("Could not get size of source file: %s", src)
return
dst_exists = True
try:
dst_size = os.path.getsize(dst)
except Exception, e:
dst_exists = False
do_copy = False
if dst_exists:
if src_size != dst_size:
do_copy = True
else:
do_copy = True
if do_copy:
self.logger.debug("copying from %s to local cache %s" % (src, dst))
try:
"""
copy will overwrite dst if it already exists
"""
shutil.copy(src, dst)
except:
self.logger.error("Could not copy from %s to %s" % (src, dst))
"""
def download_file(self, media_item, dst):
#Download a file from a remote server and store it in the cache.
if os.path.isfile(dst):
pass
#self.logger.debug("file already in cache: %s", dst)
else:
self.logger.debug("try to download %s", media_item['uri'])
self.api_client.get_media(media_item['uri'], dst)
"""
def cache_cleanup(self, media):
"""

View File

@ -36,21 +36,38 @@ class PypoFile(Thread):
def copy_file(self, media_item):
"""
Copy media_item from local library directory to local cache directory.
"""
if media_item is None:
return
"""
src = media_item['uri']
dst = media_item['dst']
if not os.path.isfile(dst):
self.logger.debug("copying from %s to local cache %s" % (media_item['uri'], dst))
try:
shutil.copy(media_item['uri'], dst)
except:
self.logger.error("Could not copy from %s to %s" % (media_item['uri'], dst))
try:
src_size = os.path.getsize(src)
except Exception, e:
self.logger.error("Could not get size of source file: %s", src)
return
dst_exists = True
try:
dst_size = os.path.getsize(dst)
except Exception, e:
dst_exists = False
do_copy = False
if dst_exists:
if src_size != dst_size:
do_copy = True
else:
self.logger.debug("Destination %s already exists. Not copying", dst)
do_copy = True
if do_copy:
self.logger.debug("copying from %s to local cache %s" % (src, dst))
try:
"""
copy will overwrite dst if it already exists
"""
shutil.copy(src, dst)
except:
self.logger.error("Could not copy from %s to %s" % (src, dst))
def get_highest_priority_media_item(self, schedule):
"""
@ -107,7 +124,10 @@ class PypoFile(Thread):
media_item = self.get_highest_priority_media_item(self.media)
self.copy_file(media_item)
except Exception, e:
import traceback
top = traceback.format_exc()
self.logger.error(str(e))
self.logger.error(top)
raise
def run(self):