-added script that updates various database config files for the frameworks we are using.

This commit is contained in:
mkonecny 2011-01-07 16:32:41 -05:00
parent 8d58f8fddb
commit ee6235f7f8
4 changed files with 95 additions and 13 deletions

View File

@ -7,13 +7,7 @@ global $CC_CONFIG;
$CC_CONFIG = array( $CC_CONFIG = array(
// Database config // Database config
'dsn' => array( 'dsn' => load_db_config(),
'username' => 'airtime',
'password' => 'airtime',
'hostspec' => 'localhost',
'phptype' => 'pgsql',
'database' => 'airtime',
),
// Name of the web server user // Name of the web server user
'webServerUser' => 'www-data', 'webServerUser' => 'www-data',
@ -171,6 +165,15 @@ set_include_path('.'.PATH_SEPARATOR.$CC_CONFIG['pearPath']
// exit(1); // exit(1);
//} //}
//$CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC); //$CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC);
function load_db_config(){
$ini_array = parse_ini_file(dirname(__FILE__).'/../../build/database.conf', true);
return array(
'username' => $ini_array['database']['dbuser'],
'password' => $ini_array['database']['dbpass'],
'hostspec' => $ini_array['database']['host'],
'phptype' => 'pgsql',
'database' => $ini_array['database']['dbname']);
}
?> ?>

6
build/database.conf Normal file
View File

@ -0,0 +1,6 @@
[database]
host = localhost
dbname = airtime
dbuser = airtime
dbpass = airtime

77
build/update_db_info.py Normal file
View File

@ -0,0 +1,77 @@
"""
The purpose of this script is to consolidate into one location where
we need to update database host, dbname, username and password.
This script reads from database.conf.
"""
import ConfigParser
import xml.dom.minidom
from xml.dom.minidom import Node
#Read the universal values
parser = ConfigParser.SafeConfigParser()
parser.read('database.conf')
section_names = parser.sections();
items_in_section = parser.items(section_names[0])
print "Updating ../application/configs/application.ini"
host = 'resources.db.params.host'
dbname = 'resources.db.params.dbname'
username = 'resources.db.params.username'
password = 'resources.db.params.password'
f = file('../application/configs/application.ini','r')
file_lines = []
for line in f:
if line[0:len(host)] == host:
line= '%s = "%s"\n' % (host, parser.get('database', 'host'))
elif line[0:len(dbname)] == dbname:
line= '%s = "%s"\n' % (dbname, parser.get('database', 'dbname'))
elif line[0:len(username)] == username:
line= '%s = "%s"\n' % (username, parser.get('database', 'dbuser'))
elif line[0:len(password)] == password:
line= '%s = "%s"\n' % (password, parser.get('database', 'dbpass'))
file_lines.append(line)
f.close()
f = file('../application/configs/application.ini', 'w')
f.writelines(file_lines)
f.close()
print "Updating ./build.properties"
f = file('build.properties', 'r')
file_lines = []
db_url = 'propel.database.url'
for line in f:
if line[0:len(db_url)] == db_url:
line = '%s = pgsql:host=%s dbname=%s user=%s password=%s\n' % \
(db_url, parser.get('database', 'host'), parser.get('database', 'dbname'), parser.get('database', 'dbuser'), \
parser.get('database', 'dbpass'))
file_lines.append(line)
f.close()
f = file('build.properties', 'w')
f.writelines(file_lines)
f.close()
print "Updating ./runtime-conf.xml"
doc = xml.dom.minidom.parse('./runtime-conf.xml')
node = doc.getElementsByTagName("dsn")[0]
node.firstChild.nodeValue = 'pgsql:host=%s;port=5432;dbname=%s;user=%s;password=%s' % (parser.get('database', 'host'), \
parser.get('database', 'dbname'), parser.get('database', 'dbuser'), parser.get('database', 'dbpass'))
xml_file = open('runtime-conf.xml', "w")
xml_file.writelines(doc.toxml('utf-8'))
xml_file.close()

View File

@ -238,11 +238,7 @@ if ($DEBUG_IMPORT) {
$testonly = false; $testonly = false;
$importMode = "link"; $importMode = "link";
$files = array("/path/to/your/test/file.mp3"); $files = array("/path/to/your/test/file.mp3");
$dsn = array('username' => 'airtime', $dsn = $CC_CONFIG['dsn'];
'password' => 'airtime',
'hostspec' => 'localhost',
'phptype' => 'pgsql',
'database' => 'airtime');
} else { } else {
$dsn = $CC_CONFIG['dsn']; $dsn = $CC_CONFIG['dsn'];
} }