Merge branch 'devel' of dev.sourcefabric.org:airtime into cc-2528-use-virtualenv-for-installing
Conflicts: python_apps/media-monitor/airtime-media-monitor
This commit is contained in:
commit
107c100cc4
35 changed files with 842 additions and 290 deletions
|
@ -3,8 +3,9 @@
|
|||
namespace DoctrineMigrations;
|
||||
|
||||
/*
|
||||
update cc_files table to include to "directory" column as well as add foreign key relation to
|
||||
cc_music_dirs table.
|
||||
1) update cc_files table to include to "directory" column
|
||||
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,
|
||||
|
@ -14,21 +15,22 @@ class Version20110711161043 extends AbstractMigration
|
|||
{
|
||||
public function up(Schema $schema)
|
||||
{
|
||||
|
||||
//CREATE the default value of "/srv/airtime/stor", this can be updated later in the upgrade script.
|
||||
/* 1) update cc_files table to include to "directory" column */
|
||||
$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', '');");
|
||||
|
||||
$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->addColumn('directory', 'integer', array('default'=> 2));
|
||||
|
||||
$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)
|
||||
|
|
|
@ -19,6 +19,9 @@ python ${SCRIPTPATH}/../python_apps/create-pypo-user.py
|
|||
|
||||
php ${SCRIPTPATH}/include/airtime-install.php $@
|
||||
|
||||
echo -e "\n*** API Client Installation ***"
|
||||
python ${SCRIPTPATH}/../python_apps/api_clients/install/api_client_install.py
|
||||
|
||||
echo -e "\n*** Pypo Installation ***"
|
||||
python ${SCRIPTPATH}/../python_apps/pypo/install/pypo-install.py
|
||||
|
||||
|
|
|
@ -23,6 +23,10 @@ python ${SCRIPTPATH}/../python_apps/show-recorder/install/recorder-uninstall.py
|
|||
echo -e "\n*** Uninstalling Media Monitor ***"
|
||||
python ${SCRIPTPATH}/../python_apps/media-monitor/install/media-monitor-uninstall.py
|
||||
|
||||
echo -e "\n*** Uninstalling API Client ***"
|
||||
python ${SCRIPTPATH}/../python_apps/api_clients/install/api_client_uninstall.py
|
||||
|
||||
|
||||
echo -e "\n*** Removing Pypo User ***"
|
||||
python ${SCRIPTPATH}/../python_apps/remove-pypo-user.py
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ class AirtimeIni
|
|||
const CONF_FILE_AIRTIME = "/etc/airtime/airtime.conf";
|
||||
const CONF_FILE_PYPO = "/etc/airtime/pypo.cfg";
|
||||
const CONF_FILE_RECORDER = "/etc/airtime/recorder.cfg";
|
||||
const CONF_FILE_API_CLIENT = "/etc/airtime/api_client.cfg";
|
||||
const CONF_FILE_LIQUIDSOAP = "/etc/airtime/liquidsoap.cfg";
|
||||
const CONF_FILE_MEDIAMONITOR = "/etc/airtime/media-monitor.cfg";
|
||||
const CONF_FILE_MONIT = "/etc/monit/conf.d/airtime-monit.cfg";
|
||||
|
@ -65,6 +66,10 @@ class AirtimeIni
|
|||
echo "Could not copy airtime.conf to /etc/airtime/. Exiting.";
|
||||
exit(1);
|
||||
}
|
||||
if (!copy(__DIR__."/../../python_apps/api_clients/api_client.cfg", AirtimeIni::CONF_FILE_API_CLIENT)){
|
||||
echo "Could not copy api_client.cfg to /etc/airtime/. Exiting.";
|
||||
exit(1);
|
||||
}
|
||||
if (!copy(__DIR__."/../../python_apps/pypo/pypo.cfg", AirtimeIni::CONF_FILE_PYPO)){
|
||||
echo "Could not copy pypo.cfg to /etc/airtime/. Exiting.";
|
||||
exit(1);
|
||||
|
|
|
@ -8,7 +8,9 @@
|
|||
|
||||
//Pear classes.
|
||||
set_include_path(__DIR__.'/../../airtime_mvc/library/pear' . PATH_SEPARATOR . get_include_path());
|
||||
|
||||
require_once('DB.php');
|
||||
require_once(__DIR__.'/../../airtime_mvc/application/configs/constants.php');
|
||||
require_once(dirname(__FILE__).'/AirtimeIni.php');
|
||||
|
||||
if(exec("whoami") != "root"){
|
||||
|
@ -87,9 +89,13 @@ if (strcmp($version, "1.9.0") < 0){
|
|||
//set the new version in the database.
|
||||
$sql = "DELETE FROM cc_pref WHERE keystr = 'system_version'";
|
||||
$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);
|
||||
|
||||
echo PHP_EOL."*** Updating Api Client ***".PHP_EOL;
|
||||
passthru("python ".__DIR__."/../../python_apps/api_clients/install/api_client_install.py");
|
||||
|
||||
echo PHP_EOL."*** Updating Pypo ***".PHP_EOL;
|
||||
passthru("python ".__DIR__."/../../python_apps/pypo/install/pypo-install.py");
|
||||
|
|
|
@ -321,7 +321,7 @@ class AirtimeInstall{
|
|||
INSERT INTO cc_country (isocode, name) VALUES ('ZWE', 'Zimbabwe ');";
|
||||
|
||||
echo "* Inserting data into country table".PHP_EOL;
|
||||
execSqlQuery($sql);
|
||||
Airtime190Upgrade::execSqlQuery($sql);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -332,7 +332,7 @@ class AirtimeIni{
|
|||
const CONF_FILE_RECORDER = "/etc/airtime/recorder.cfg";
|
||||
const CONF_FILE_LIQUIDSOAP = "/etc/airtime/liquidsoap.cfg";
|
||||
const CONF_FILE_MEDIAMONITOR = "/etc/airtime/media-monitor.cfg";
|
||||
|
||||
|
||||
/**
|
||||
* This function updates an INI style config file.
|
||||
*
|
||||
|
@ -420,7 +420,7 @@ class AirtimeIni{
|
|||
}
|
||||
}
|
||||
|
||||
function upgradeConfigFiles(){
|
||||
public static function upgradeConfigFiles(){
|
||||
|
||||
$configFiles = array(AirtimeIni::CONF_FILE_AIRTIME,
|
||||
AirtimeIni::CONF_FILE_PYPO,
|
||||
|
@ -443,7 +443,7 @@ class AirtimeIni{
|
|||
* This function creates the /etc/airtime configuration folder
|
||||
* and copies the default config files to it.
|
||||
*/
|
||||
function CreateIniFiles()
|
||||
public static function CreateIniFiles()
|
||||
{
|
||||
if (!file_exists("/etc/airtime/")){
|
||||
if (!mkdir("/etc/airtime/", 0755, true)){
|
||||
|
@ -474,115 +474,122 @@ class AirtimeIni{
|
|||
}
|
||||
}
|
||||
|
||||
function InstallAirtimePhpServerCode($phpDir)
|
||||
{
|
||||
class Airtime190Upgrade{
|
||||
|
||||
$AIRTIME_SRC = realpath(__DIR__.'/../../../airtime_mvc');
|
||||
public static function InstallAirtimePhpServerCode($phpDir)
|
||||
{
|
||||
|
||||
echo "* Installing PHP code to ".$phpDir.PHP_EOL;
|
||||
exec("mkdir -p ".$phpDir);
|
||||
exec("cp -R ".$AIRTIME_SRC."/* ".$phpDir);
|
||||
}
|
||||
$AIRTIME_SRC = realpath(__DIR__.'/../../../airtime_mvc');
|
||||
|
||||
function CopyUtils()
|
||||
{
|
||||
$utilsSrc = __DIR__."/../../../utils";
|
||||
|
||||
echo "* Installing binaries to ".CONF_DIR_BINARIES.PHP_EOL;
|
||||
exec("mkdir -p ".CONF_DIR_BINARIES);
|
||||
exec("cp -R ".$utilsSrc." ".CONF_DIR_BINARIES);
|
||||
}
|
||||
|
||||
/* Removes pypo, media-monitor, show-recorder and utils from system. These will
|
||||
* be reinstalled by the main airtime-upgrade script.
|
||||
*/
|
||||
function UninstallBinaries()
|
||||
{
|
||||
echo "* Removing Airtime binaries from ".CONF_DIR_BINARIES.PHP_EOL;
|
||||
exec('rm -rf "'.CONF_DIR_BINARIES.'"');
|
||||
}
|
||||
|
||||
|
||||
function removeOldAirtimeImport(){
|
||||
exec('rm -f "/usr/bin/airtime-import"');
|
||||
exec('rm -f "/usr/lib/airtime/utils/airtime-import.php"');
|
||||
exec('rm -rf "/usr/lib/airtime/utils/airtime-import"');
|
||||
}
|
||||
|
||||
function updateAirtimeImportSymLink(){
|
||||
$dir = "/usr/lib/airtime/utils/airtime-import/airtime-import";
|
||||
exec("ln -s $dir /usr/bin/airtime-import");
|
||||
}
|
||||
|
||||
function execSqlQuery($sql){
|
||||
global $CC_DBC;
|
||||
|
||||
$result = $CC_DBC->query($sql);
|
||||
if (PEAR::isError($result)) {
|
||||
echo "* Failed sql query: $sql".PHP_EOL;
|
||||
echo "* Message {$result->getMessage()}".PHP_EOL;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
function connectToDatabase(){
|
||||
global $CC_DBC, $CC_CONFIG;
|
||||
|
||||
$values = parse_ini_file('/etc/airtime/airtime.conf', true);
|
||||
|
||||
// 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_DBC = DB::connect($CC_CONFIG['dsn'], FALSE);
|
||||
}
|
||||
|
||||
/* Old database had a "fullpath" column that stored the absolute path of each track. We have to
|
||||
* change it so that the "fullpath" column has path relative to the "directory" column.
|
||||
*/
|
||||
function installMediaMonitor($values){
|
||||
|
||||
/* Handle Database Changes. */
|
||||
$stor_dir = realpath($values['general']['base_files_dir']."/stor")."/";
|
||||
echo "* Inserting stor directory location $stor_dir into music_dirs table".PHP_EOL;
|
||||
$sql = "UPDATE cc_music_dirs SET directory='$stor_dir' WHERE type='stor'";
|
||||
echo $sql.PHP_EOL;
|
||||
execSqlQuery($sql);
|
||||
|
||||
$sql = "SELECT id FROM cc_music_dirs WHERE type='stor'";
|
||||
echo $sql.PHP_EOL;
|
||||
$rows = execSqlQuery($sql);
|
||||
|
||||
echo "Creating media-monitor log file";
|
||||
mkdir("/var/log/airtime/media-monitor/", 755, true);
|
||||
touch("/var/log/airtime/media-monitor/media-monitor.log");
|
||||
|
||||
/* create media monitor config: */
|
||||
if (!copy(__DIR__."/../../../python_apps/media-monitor/media-monitor.cfg", AirtimeIni::CONF_FILE_MEDIAMONITOR)){
|
||||
echo "Could not copy media-monitor.cfg to /etc/airtime/. Exiting.";
|
||||
echo "* Installing PHP code to ".$phpDir.PHP_EOL;
|
||||
exec("mkdir -p ".$phpDir);
|
||||
exec("cp -R ".$AIRTIME_SRC."/* ".$phpDir);
|
||||
}
|
||||
|
||||
echo "Reorganizing files in stor directory";
|
||||
$mediaMonitorUpgradePath = realpath(__DIR__."/../../../python_apps/media-monitor/media-monitor-upgrade.py");
|
||||
exec("su -c \"python $mediaMonitorUpgradePath\"", $output);
|
||||
print_r($output);
|
||||
public static function CopyUtils()
|
||||
{
|
||||
$utilsSrc = __DIR__."/../../../utils";
|
||||
|
||||
$oldAndNewFileNames = json_decode($output[0]);
|
||||
echo "* Installing binaries to ".CONF_DIR_BINARIES.PHP_EOL;
|
||||
exec("mkdir -p ".CONF_DIR_BINARIES);
|
||||
exec("cp -R ".$utilsSrc." ".CONF_DIR_BINARIES);
|
||||
}
|
||||
|
||||
foreach ($oldAndNewFileNames as $pair){
|
||||
$relPathNew = pg_escape_string(substr($pair[1], strlen($stor_dir)));
|
||||
$absPathOld = pg_escape_string($pair[0]);
|
||||
$sql = "UPDATE cc_files SET filepath = '$relPathNew', directory=1 WHERE filepath = '$absPathOld'";
|
||||
/* Removes pypo, media-monitor, show-recorder and utils from system. These will
|
||||
* be reinstalled by the main airtime-upgrade script.
|
||||
*/
|
||||
public static function UninstallBinaries()
|
||||
{
|
||||
echo "* Removing Airtime binaries from ".CONF_DIR_BINARIES.PHP_EOL;
|
||||
exec('rm -rf "'.CONF_DIR_BINARIES.'"');
|
||||
}
|
||||
|
||||
|
||||
public static function removeOldAirtimeImport(){
|
||||
exec('rm -f "/usr/bin/airtime-import"');
|
||||
exec('rm -f "/usr/lib/airtime/utils/airtime-import.php"');
|
||||
exec('rm -rf "/usr/lib/airtime/utils/airtime-import"');
|
||||
}
|
||||
|
||||
public static function updateAirtimeImportSymLink(){
|
||||
$dir = "/usr/lib/airtime/utils/airtime-import/airtime-import";
|
||||
exec("ln -s $dir /usr/bin/airtime-import");
|
||||
}
|
||||
|
||||
public static function execSqlQuery($sql){
|
||||
global $CC_DBC;
|
||||
|
||||
$result = $CC_DBC->query($sql);
|
||||
if (PEAR::isError($result)) {
|
||||
echo "* Failed sql query: $sql".PHP_EOL;
|
||||
echo "* Message {$result->getMessage()}".PHP_EOL;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function connectToDatabase(){
|
||||
global $CC_DBC, $CC_CONFIG;
|
||||
|
||||
$values = parse_ini_file('/etc/airtime/airtime.conf', true);
|
||||
|
||||
// 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_DBC = DB::connect($CC_CONFIG['dsn'], FALSE);
|
||||
}
|
||||
|
||||
/* Old database had a "fullpath" column that stored the absolute path of each track. We have to
|
||||
* change it so that the "fullpath" column has path relative to the "directory" column.
|
||||
*/
|
||||
public static function installMediaMonitor($values){
|
||||
|
||||
/* Handle Database Changes. */
|
||||
$stor_dir = realpath($values['general']['base_files_dir']."/stor")."/";
|
||||
echo "* Inserting stor directory location $stor_dir into music_dirs table".PHP_EOL;
|
||||
$sql = "UPDATE cc_music_dirs SET directory='$stor_dir' WHERE type='stor'";
|
||||
echo $sql.PHP_EOL;
|
||||
execSqlQuery($sql);
|
||||
Airtime190Upgrade::execSqlQuery($sql);
|
||||
|
||||
$sql = "SELECT id FROM cc_music_dirs WHERE type='stor'";
|
||||
echo $sql.PHP_EOL;
|
||||
$rows = Airtime190Upgrade::execSqlQuery($sql);
|
||||
|
||||
echo "Creating media-monitor log file";
|
||||
mkdir("/var/log/airtime/media-monitor/", 755, true);
|
||||
touch("/var/log/airtime/media-monitor/media-monitor.log");
|
||||
|
||||
/* create media monitor config: */
|
||||
if (!copy(__DIR__."/../../../python_apps/media-monitor/media-monitor.cfg", AirtimeIni::CONF_FILE_MEDIAMONITOR)){
|
||||
echo "Could not copy media-monitor.cfg to /etc/airtime/. Exiting.";
|
||||
}
|
||||
|
||||
AirtimeIni::UpdateIniValue(AirtimeIni::CONF_FILE_MEDIAMONITOR, "api_key", $values["general"]["api_key"]);
|
||||
|
||||
echo "Reorganizing files in stor directory";
|
||||
$mediaMonitorUpgradePath = realpath(__DIR__."/../../../python_apps/media-monitor/media-monitor-upgrade.py");
|
||||
exec("su -c \"python $mediaMonitorUpgradePath\"", $output);
|
||||
print_r($output);
|
||||
|
||||
$oldAndNewFileNames = json_decode($output[0]);
|
||||
|
||||
foreach ($oldAndNewFileNames as $pair){
|
||||
$relPathNew = pg_escape_string(substr($pair[1], strlen($stor_dir)));
|
||||
$absPathOld = pg_escape_string($pair[0]);
|
||||
$sql = "UPDATE cc_files SET filepath = '$relPathNew', directory=1 WHERE filepath = '$absPathOld'";
|
||||
echo $sql.PHP_EOL;
|
||||
Airtime190Upgrade::execSqlQuery($sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
AirtimeInstall::CreateZendPhpLogFile();
|
||||
|
||||
/* In version 1.9.0 we have have switched from daemontools to more traditional
|
||||
|
@ -622,19 +629,19 @@ foreach ($pathnames as $pn){
|
|||
/* update Airtime Server PHP files */
|
||||
$values = parse_ini_file(AirtimeIni::CONF_FILE_AIRTIME, true);
|
||||
$phpDir = $values['general']['airtime_dir'];
|
||||
InstallAirtimePhpServerCode($phpDir);
|
||||
Airtime190Upgrade::InstallAirtimePhpServerCode($phpDir);
|
||||
|
||||
/* update utils (/usr/lib/airtime) folder */
|
||||
UninstallBinaries();
|
||||
CopyUtils();
|
||||
Airtime190Upgrade::UninstallBinaries();
|
||||
Airtime190Upgrade::CopyUtils();
|
||||
|
||||
/* James made a new airtime-import script, lets remove the old airtime-import php script,
|
||||
*install the new airtime-import.py script and update the /usr/bin/symlink.
|
||||
*/
|
||||
removeOldAirtimeImport();
|
||||
updateAirtimeImportSymLink();
|
||||
Airtime190Upgrade::removeOldAirtimeImport();
|
||||
Airtime190Upgrade::updateAirtimeImportSymLink();
|
||||
|
||||
connectToDatabase();
|
||||
Airtime190Upgrade::connectToDatabase();
|
||||
|
||||
if(AirtimeInstall::DbTableExists('doctrine_migration_versions') === false) {
|
||||
$migrations = array('20110312121200', '20110331111708', '20110402164819', '20110406182005');
|
||||
|
@ -652,7 +659,7 @@ AirtimeInstall::InsertCountryDataIntoDatabase();
|
|||
/* create cron file for phone home stat */
|
||||
AirtimeInstall::CreateCronFile();
|
||||
|
||||
installMediaMonitor($values);
|
||||
Airtime190Upgrade::installMediaMonitor($values);
|
||||
|
||||
AirtimeIni::upgradeConfigFiles();
|
||||
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
import sys
|
||||
|
||||
from configobj import ConfigObj
|
||||
|
||||
class AirtimeMediaConfig:
|
||||
|
||||
MODE_CREATE = "create"
|
||||
MODE_MODIFY = "modify"
|
||||
MODE_MOVED = "moved"
|
||||
MODE_DELETE = "delete"
|
||||
|
||||
def __init__(self, logger):
|
||||
|
||||
# loading config file
|
||||
try:
|
||||
config = ConfigObj('/etc/airtime/media-monitor.cfg')
|
||||
self.cfg = config
|
||||
except Exception, e:
|
||||
logger.info('Error loading config: ', e)
|
||||
sys.exit()
|
||||
|
||||
self.storage_directory = None
|
||||
|
||||
|
|
@ -0,0 +1,243 @@
|
|||
import os
|
||||
import grp
|
||||
import pwd
|
||||
import logging
|
||||
|
||||
from subprocess import Popen, PIPE
|
||||
from airtimemetadata import AirtimeMetadata
|
||||
|
||||
class MediaMonitorCommon:
|
||||
|
||||
timestamp_file = "/var/tmp/airtime/last_index"
|
||||
|
||||
def __init__(self, airtime_config):
|
||||
self.supported_file_formats = ['mp3', 'ogg']
|
||||
self.logger = logging.getLogger()
|
||||
self.config = airtime_config
|
||||
self.md_manager = AirtimeMetadata()
|
||||
|
||||
def is_parent_directory(self, filepath, directory):
|
||||
filepath = os.path.normpath(filepath)
|
||||
directory = os.path.normpath(directory)
|
||||
return (directory == filepath[0:len(directory)])
|
||||
|
||||
def is_temp_file(self, filename):
|
||||
info = filename.split(".")
|
||||
|
||||
if(info[-2] in self.supported_file_formats):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def is_audio_file(self, filename):
|
||||
info = filename.split(".")
|
||||
|
||||
if(info[-1] in self.supported_file_formats):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
#check if file is readable by "nobody"
|
||||
def has_correct_permissions(self, filepath):
|
||||
#drop root permissions and become "nobody"
|
||||
os.seteuid(65534)
|
||||
|
||||
try:
|
||||
open(filepath)
|
||||
readable = True
|
||||
except IOError:
|
||||
self.logger.warn("File does not have correct permissions: '%s'", filepath)
|
||||
readable = False
|
||||
except Exception, e:
|
||||
self.logger.error("Unexpected exception thrown: %s", e)
|
||||
readable = False
|
||||
finally:
|
||||
#reset effective user to root
|
||||
os.seteuid(0)
|
||||
|
||||
return readable
|
||||
|
||||
def set_needed_file_permissions(self, item, is_dir):
|
||||
try:
|
||||
omask = os.umask(0)
|
||||
|
||||
uid = pwd.getpwnam('www-data')[2]
|
||||
gid = grp.getgrnam('www-data')[2]
|
||||
|
||||
os.chown(item, uid, gid)
|
||||
|
||||
if is_dir is True:
|
||||
os.chmod(item, 02777)
|
||||
else:
|
||||
os.chmod(item, 0666)
|
||||
|
||||
except Exception, e:
|
||||
self.logger.error("Failed to change file's owner/group/permissions. %s", e)
|
||||
finally:
|
||||
os.umask(omask)
|
||||
|
||||
|
||||
#checks if path is a directory, and if it doesnt exist, then creates it.
|
||||
#Otherwise prints error to log file.
|
||||
def ensure_is_dir(self, directory):
|
||||
try:
|
||||
omask = os.umask(0)
|
||||
if not os.path.exists(directory):
|
||||
os.makedirs(directory, 02777)
|
||||
elif not os.path.isdir(directory):
|
||||
#path exists but it is a file not a directory!
|
||||
self.logger.error("path %s exists, but it is not a directory!!!")
|
||||
finally:
|
||||
os.umask(omask)
|
||||
|
||||
#moves file from source to dest but also recursively removes the
|
||||
#the source file's parent directories if they are now empty.
|
||||
def move_file(self, source, dest):
|
||||
|
||||
try:
|
||||
omask = os.umask(0)
|
||||
os.rename(source, dest)
|
||||
except Exception, e:
|
||||
self.logger.error("failed to move file. %s", e)
|
||||
finally:
|
||||
os.umask(omask)
|
||||
|
||||
dir = os.path.dirname(source)
|
||||
self.cleanup_empty_dirs(dir)
|
||||
|
||||
#keep moving up the file hierarchy and deleting parent
|
||||
#directories until we hit a non-empty directory, or we
|
||||
#hit the organize dir.
|
||||
def cleanup_empty_dirs(self, dir):
|
||||
if os.path.normpath(dir) != self.config.organize_directory:
|
||||
if len(os.listdir(dir)) == 0:
|
||||
os.rmdir(dir)
|
||||
|
||||
pdir = os.path.dirname(dir)
|
||||
self.cleanup_empty_dirs(pdir)
|
||||
|
||||
|
||||
#checks if path exists already in stor. If the path exists and the md5s are the
|
||||
#same just overwrite.
|
||||
def create_unique_filename(self, filepath, old_filepath):
|
||||
|
||||
try:
|
||||
if(os.path.exists(filepath)):
|
||||
self.logger.info("Path %s exists", filepath)
|
||||
|
||||
self.logger.info("Checking if md5s are the same.")
|
||||
md5_fp = self.md_manager.get_md5(filepath)
|
||||
md5_ofp = self.md_manager.get_md5(old_filepath)
|
||||
|
||||
if(md5_fp == md5_ofp):
|
||||
self.logger.info("Md5s are the same, moving to same filepath.")
|
||||
return filepath
|
||||
|
||||
self.logger.info("Md5s aren't the same, appending to filepath.")
|
||||
file_dir = os.path.dirname(filepath)
|
||||
filename = os.path.basename(filepath).split(".")[0]
|
||||
#will be in the format .ext
|
||||
file_ext = os.path.splitext(filepath)[1]
|
||||
i = 1;
|
||||
while(True):
|
||||
new_filepath = '%s/%s(%s)%s' % (file_dir, filename, i, file_ext)
|
||||
self.logger.error("Trying %s", new_filepath)
|
||||
|
||||
if(os.path.exists(new_filepath)):
|
||||
i = i+1;
|
||||
else:
|
||||
filepath = new_filepath
|
||||
break
|
||||
|
||||
except Exception, e:
|
||||
self.logger.error("Exception %s", e)
|
||||
|
||||
return filepath
|
||||
|
||||
#create path in /srv/airtime/stor/imported/[song-metadata]
|
||||
def create_file_path(self, original_path, orig_md):
|
||||
|
||||
storage_directory = self.config.storage_directory
|
||||
|
||||
is_recorded_show = False
|
||||
|
||||
try:
|
||||
#will be in the format .ext
|
||||
file_ext = os.path.splitext(original_path)[1]
|
||||
file_ext = file_ext.encode('utf-8')
|
||||
|
||||
path_md = ['MDATA_KEY_TITLE', 'MDATA_KEY_CREATOR', 'MDATA_KEY_SOURCE', 'MDATA_KEY_TRACKNUMBER', 'MDATA_KEY_BITRATE']
|
||||
|
||||
md = {}
|
||||
for m in path_md:
|
||||
if m not in orig_md:
|
||||
md[m] = u'unknown'.encode('utf-8')
|
||||
else:
|
||||
#get rid of any "/" which will interfere with the filepath.
|
||||
if isinstance(orig_md[m], basestring):
|
||||
md[m] = orig_md[m].replace("/", "-")
|
||||
else:
|
||||
md[m] = orig_md[m]
|
||||
|
||||
if 'MDATA_KEY_TRACKNUMBER' in orig_md:
|
||||
#make sure all track numbers are at least 2 digits long in the filepath.
|
||||
md['MDATA_KEY_TRACKNUMBER'] = "%02d" % (int(md['MDATA_KEY_TRACKNUMBER']))
|
||||
|
||||
#format bitrate as 128kbps
|
||||
md['MDATA_KEY_BITRATE'] = str(md['MDATA_KEY_BITRATE']/1000)+"kbps"
|
||||
|
||||
filepath = None
|
||||
#file is recorded by Airtime
|
||||
#/srv/airtime/stor/recorded/year/month/year-month-day-time-showname-bitrate.ext
|
||||
if(md['MDATA_KEY_CREATOR'] == "AIRTIMERECORDERSOURCEFABRIC".encode('utf-8')):
|
||||
#yyyy-mm-dd-hh-MM-ss
|
||||
y = orig_md['MDATA_KEY_YEAR'].split("-")
|
||||
filepath = '%s/%s/%s/%s/%s-%s-%s%s' % (storage_directory, "recorded".encode('utf-8'), y[0], y[1], orig_md['MDATA_KEY_YEAR'], md['MDATA_KEY_TITLE'], md['MDATA_KEY_BITRATE'], file_ext)
|
||||
elif(md['MDATA_KEY_TRACKNUMBER'] == u'unknown'.encode('utf-8')):
|
||||
filepath = '%s/%s/%s/%s/%s-%s%s' % (storage_directory, "imported".encode('utf-8'), md['MDATA_KEY_CREATOR'], md['MDATA_KEY_SOURCE'], md['MDATA_KEY_TITLE'], md['MDATA_KEY_BITRATE'], file_ext)
|
||||
else:
|
||||
filepath = '%s/%s/%s/%s/%s-%s-%s%s' % (storage_directory, "imported".encode('utf-8'), md['MDATA_KEY_CREATOR'], md['MDATA_KEY_SOURCE'], md['MDATA_KEY_TRACKNUMBER'], md['MDATA_KEY_TITLE'], md['MDATA_KEY_BITRATE'], file_ext)
|
||||
|
||||
filepath = self.create_unique_filename(filepath, original_path)
|
||||
self.logger.info('Unique filepath: %s', filepath)
|
||||
self.ensure_is_dir(os.path.dirname(filepath))
|
||||
|
||||
except Exception, e:
|
||||
self.logger.error('Exception: %s', e)
|
||||
|
||||
return filepath
|
||||
|
||||
def execCommandAndReturnStdOut(self, command):
|
||||
p = Popen(command, shell=True, stdout=PIPE)
|
||||
stdout = p.communicate()[0]
|
||||
if p.returncode != 0:
|
||||
self.logger.warn("command \n%s\n return with a non-zero return value", command)
|
||||
return stdout
|
||||
|
||||
def scan_dir_for_new_files(self, dir):
|
||||
command = 'find "%s" -type f -iname "*.ogg" -o -iname "*.mp3" -readable' % dir.replace('"', '\\"')
|
||||
self.logger.debug(command)
|
||||
stdout = self.execCommandAndReturnStdOut(command)
|
||||
stdout = unicode(stdout, "utf_8")
|
||||
|
||||
return stdout.splitlines()
|
||||
|
||||
def touch_index_file(self):
|
||||
open(self.timestamp_file, "w")
|
||||
|
||||
def organize_new_file(self, pathname):
|
||||
self.logger.info("Organizing new file: %s", pathname)
|
||||
file_md = self.md_manager.get_md_from_file(pathname)
|
||||
|
||||
if file_md is not None:
|
||||
#is_recorded_show = 'MDATA_KEY_CREATOR' in file_md and \
|
||||
# file_md['MDATA_KEY_CREATOR'] == "AIRTIMERECORDERSOURCEFABRIC".encode('utf-8')
|
||||
filepath = self.create_file_path(pathname, file_md)
|
||||
|
||||
self.logger.debug("Moving from %s to %s", pathname, filepath)
|
||||
self.move_file(pathname, filepath)
|
||||
else:
|
||||
filepath = None
|
||||
self.logger.warn("File %s, has invalid metadata", pathname)
|
||||
|
||||
return filepath
|
83
install/upgrades/airtime-1.9.0/conf.php
Normal file
83
install/upgrades/airtime-1.9.0/conf.php
Normal 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;
|
||||
}
|
||||
}
|
22
install/upgrades/airtime-1.9.0/logging.cfg
Normal file
22
install/upgrades/airtime-1.9.0/logging.cfg
Normal file
|
@ -0,0 +1,22 @@
|
|||
[loggers]
|
||||
keys=root
|
||||
|
||||
[handlers]
|
||||
keys=fileOutHandler
|
||||
|
||||
[formatters]
|
||||
keys=simpleFormatter
|
||||
|
||||
[logger_root]
|
||||
level=DEBUG
|
||||
handlers=fileOutHandler
|
||||
|
||||
[handler_fileOutHandler]
|
||||
class=logging.handlers.RotatingFileHandler
|
||||
level=DEBUG
|
||||
formatter=simpleFormatter
|
||||
args=("/var/log/airtime/media-monitor/media-monitor.log", 'a', 1000000, 5,)
|
||||
|
||||
[formatter_simpleFormatter]
|
||||
format=%(asctime)s %(levelname)s - [%(filename)s : %(funcName)s() : line %(lineno)d] - %(message)s
|
||||
datefmt=
|
44
install/upgrades/airtime-1.9.0/media-monitor-upgrade.py
Normal file
44
install/upgrades/airtime-1.9.0/media-monitor-upgrade.py
Normal file
|
@ -0,0 +1,44 @@
|
|||
from airtimefilemonitor.mediamonitorcommon import MediaMonitorCommon
|
||||
from airtimefilemonitor.mediaconfig import AirtimeMediaConfig
|
||||
|
||||
import logging
|
||||
import logging.config
|
||||
import sys
|
||||
import os
|
||||
import json
|
||||
import ConfigParser
|
||||
|
||||
import os.path
|
||||
|
||||
# configure logging
|
||||
try:
|
||||
logging.config.fileConfig("%s/logging.cfg"%os.path.dirname(__file__))
|
||||
except Exception, e:
|
||||
print 'Error configuring logging: ', e
|
||||
sys.exit(1)
|
||||
|
||||
logger = logging.getLogger()
|
||||
mmconfig = AirtimeMediaConfig(logger)
|
||||
|
||||
#get stor folder location from /etc/airtime/airtime.conf
|
||||
config = ConfigParser.RawConfigParser()
|
||||
config.read('/etc/airtime/airtime.conf')
|
||||
stor_dir = config.get('general', 'base_files_dir') + "/stor"
|
||||
|
||||
mmconfig.storage_directory = os.path.normpath(stor_dir)
|
||||
mmconfig.imported_directory = os.path.normpath(stor_dir + '/imported')
|
||||
mmconfig.organize_directory = os.path.normpath(stor_dir + '/organize')
|
||||
|
||||
mmc = MediaMonitorCommon(mmconfig)
|
||||
|
||||
#read list of all files in stor location.....and one-by-one pass this through to
|
||||
#mmc.organize_files. print out json encoding of before and after
|
||||
pairs = []
|
||||
for root, dirs, files in os.walk(mmconfig.storage_directory):
|
||||
for f in files:
|
||||
#print os.path.join(root, f)
|
||||
#print mmc.organize_new_file(os.path.join(root, f))
|
||||
pair = os.path.join(root, f), mmc.organize_new_file(os.path.join(root, f))
|
||||
pairs.append(pair)
|
||||
|
||||
print json.dumps(pairs)
|
Loading…
Add table
Add a link
Reference in a new issue