diff --git a/application/configs/conf.php b/application/configs/conf.php index c46d38b69..8f077ab81 100644 --- a/application/configs/conf.php +++ b/application/configs/conf.php @@ -7,13 +7,7 @@ global $CC_CONFIG; $CC_CONFIG = array( // Database config - 'dsn' => array( - 'username' => 'airtime', - 'password' => 'airtime', - 'hostspec' => 'localhost', - 'phptype' => 'pgsql', - 'database' => 'airtime', - ), + 'dsn' => load_db_config(), // Name of the web server user 'webServerUser' => 'www-data', @@ -171,6 +165,15 @@ set_include_path('.'.PATH_SEPARATOR.$CC_CONFIG['pearPath'] // exit(1); //} //$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']); +} ?> diff --git a/build/database.conf b/build/database.conf new file mode 100644 index 000000000..9b0e7fca8 --- /dev/null +++ b/build/database.conf @@ -0,0 +1,6 @@ +[database] +host = localhost +dbname = airtime +dbuser = airtime +dbpass = airtime + diff --git a/build/update_db_info.py b/build/update_db_info.py new file mode 100644 index 000000000..38c820b2f --- /dev/null +++ b/build/update_db_info.py @@ -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() + + + diff --git a/utils/airtime-import.php b/utils/airtime-import.php index 21d47e2de..2323abbf4 100644 --- a/utils/airtime-import.php +++ b/utils/airtime-import.php @@ -238,11 +238,7 @@ if ($DEBUG_IMPORT) { $testonly = false; $importMode = "link"; $files = array("/path/to/your/test/file.mp3"); - $dsn = array('username' => 'airtime', - 'password' => 'airtime', - 'hostspec' => 'localhost', - 'phptype' => 'pgsql', - 'database' => 'airtime'); + $dsn = $CC_CONFIG['dsn']; } else { $dsn = $CC_CONFIG['dsn']; }