CC-2279: Upgrade script for converting stor directory to new format
-in progress...
This commit is contained in:
parent
75e56034e4
commit
621c85b1df
|
@ -77,6 +77,16 @@ function updateAirtimeImportSymLink(){
|
|||
exec("ln -s $dir /usr/bin/airtime-import");
|
||||
}
|
||||
|
||||
function execSqlQuery($sqlString){
|
||||
$result = $CC_DBC->query($sql);
|
||||
echo $sql.PHP_EOL;
|
||||
if (PEAR::isError($result)) {
|
||||
echo "* Failed sql query: $sql".PHP_EOL;
|
||||
echo "* Message {$result->getMessage()}".PHP_EOL;
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
function connectToDatabase(){
|
||||
global $CC_DBC, $CC_CONFIG;
|
||||
|
||||
|
@ -392,28 +402,34 @@ $sql = "INSERT INTO cc_country (isocode, name) VALUES ('AFG', 'Afghanistan ');
|
|||
INSERT INTO cc_country (isocode, name) VALUES ('ZWE', 'Zimbabwe ');";
|
||||
|
||||
echo "* Inserting data into country table".PHP_EOL;
|
||||
$result = $CC_DBC->query($sql);
|
||||
if (PEAR::isError($result)) {
|
||||
echo "* Failed inserting data into cc_country".PHP_EOL;
|
||||
echo "* Message {$result->getMessage()}".PHP_EOL;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$ini = parse_ini_file(__DIR__."/../../include/airtime-install.ini");
|
||||
|
||||
$stor_dir = realpath($ini["storage_dir"])."/";
|
||||
echo "* Inserting stor directory location $stor_dir into music_dirs table".PHP_EOL;
|
||||
$sql = "INSERT INTO cc_music_dirs (directory, type) VALUES ('$stor_dir', 'stor')";
|
||||
$result = $CC_DBC->query($sql);
|
||||
if (PEAR::isError($result)) {
|
||||
echo "* Failed inserting {$stor_dir} in cc_music_dirs".PHP_EOL;
|
||||
echo "* Message {$result->getMessage()}".PHP_EOL;
|
||||
exit(1);
|
||||
}
|
||||
execSqlQuery($sql);
|
||||
|
||||
//create cron file for phone home stat
|
||||
AirtimeInstall::CreateCronFile();
|
||||
|
||||
$stor_dir = realpath($values['general']['base_dir']."/stor")."/";
|
||||
echo "* Inserting stor directory location $stor_dir into music_dirs table".PHP_EOL;
|
||||
$sql = "INSERT INTO cc_music_dirs (directory, type) VALUES ('$stor_dir', 'stor')";
|
||||
execSqlQuery($sql);
|
||||
|
||||
//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.
|
||||
|
||||
$mediaMonitorUpgradePath = realpath(__DIR__."/../../../python_apps/media-monitor/media-monitor-upgrade.py");
|
||||
exec("python $mediaMonitorUpgradePath", $output);
|
||||
|
||||
print_r($output);
|
||||
|
||||
$oldAndNewFileNames = json_decode($output);
|
||||
|
||||
print_r($oldAndNewFileNames);
|
||||
|
||||
foreach ($oldAndNewFileNames as $pair){
|
||||
$relPathNew = substr($pair[1], 0, strlen($stor_dir));
|
||||
$absPathOld = $pair[0];
|
||||
$sql = "UPDATE cc_music_dirs SET filepath = \"$relPathNew\", directory=1 WHERE filepath = \"$absPathOld\"";
|
||||
execSqlQuery($sql);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -237,9 +237,9 @@ class MediaMonitorCommon:
|
|||
filepath = self.create_file_path(pathname, file_md)
|
||||
|
||||
self.logger.debug(u"Moving from %s to %s", pathname, filepath)
|
||||
self.move_file(pathname, filepath)
|
||||
#self.move_file(pathname, filepath)
|
||||
else:
|
||||
filepath = None
|
||||
self.logger.warn("File %s, has invalid metadata", pathname)
|
||||
|
||||
return filepath
|
||||
return filepath
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
from airtimefilemonitor.mediamonitorcommon import MediaMonitorCommon
|
||||
from airtimefilemonitor.mediaconfig import AirtimeMediaConfig
|
||||
|
||||
import logging
|
||||
import logging.config
|
||||
import sys
|
||||
import os
|
||||
import json
|
||||
import ConfigParser
|
||||
|
||||
# configure logging
|
||||
try:
|
||||
logging.config.fileConfig("logging.cfg")
|
||||
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_dir')
|
||||
|
||||
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 = []
|
||||
print "walking through %s" % stor_dir
|
||||
for root, dirs, files in os.walk(stor_dir):
|
||||
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…
Reference in New Issue