diff options
author | mbligh <mbligh@592f7852-d20e-0410-864c-8624ca9c26a4> | 2008-02-27 21:33:46 +0000 |
---|---|---|
committer | mbligh <mbligh@592f7852-d20e-0410-864c-8624ca9c26a4> | 2008-02-27 21:33:46 +0000 |
commit | 781c31d754c09448e98c05c8192960cb09ad44d3 (patch) | |
tree | 044efee8b1304dc54d64f21c12f41054eac88bdf /migrate/migrate.py | |
parent | 67db112e31d04a261d74a8a7a2f164ef83cabb51 (diff) |
more on global config
From: Travis Miller <raphtee@google.com>
With these changes, the .database, and .priv_login files are no longer needed.
git-svn-id: svn://test.kernel.org/autotest/trunk@1273 592f7852-d20e-0410-864c-8624ca9c26a4
Diffstat (limited to 'migrate/migrate.py')
-rwxr-xr-x | migrate/migrate.py | 65 |
1 files changed, 27 insertions, 38 deletions
diff --git a/migrate/migrate.py b/migrate/migrate.py index ce9580ba..b622a7ca 100755 --- a/migrate/migrate.py +++ b/migrate/migrate.py @@ -2,13 +2,12 @@ import os, sys, re, subprocess, tempfile import MySQLdb, MySQLdb.constants.ER +from optparse import OptionParser +from common import global_config MIGRATE_TABLE = 'migrate_info' DEFAULT_MIGRATIONS_DIR = 'migrations' -DATABASE_FILE = '.database' -LOGIN_FILE = '.priv_login' - class Migration(object): version = None module = None @@ -23,8 +22,9 @@ class MigrationManager(object): cursor = None migrations_dir = None - def __init__(self, migrations_dir=None, db_host=None, db_name=None, + def __init__(self, database, migrations_dir=None, db_host=None, db_name=None, username=None, password=None): + self.database = database if migrations_dir is None: migrations_dir = os.path.abspath(DEFAULT_MIGRATIONS_DIR) self.migrations_dir = migrations_dir @@ -37,33 +37,14 @@ class MigrationManager(object): self.password = password - def read_lines_from_file(self, filename): - base_dir = os.getcwd() - file_path = os.path.join(base_dir, filename) - f = open(file_path, 'r') - lines = [line.strip() for line in f.read().splitlines()] - f.close() - return lines - - def read_db_info(self): - # try setting.py first - try: - sys.path.append(os.getcwd()) - import settings - sys.path.pop() - self.db_host = settings.DATABASE_HOST or 'localhost' - self.db_name = settings.DATABASE_NAME - self.username = settings.DATABASE_USER - self.password = settings.DATABASE_PASSWORD - return - except ImportError: - pass - - self.db_host, self.db_name = ( - self.read_lines_from_file(DATABASE_FILE)) - self.username, self.password = ( - self.read_lines_from_file(LOGIN_FILE)) + # grab the config file and parse for info + c = global_config.global_config + print "database = %s\n" % (self.database) + self.db_host = c.get_config_value(self.database, "host") + self.db_name = c.get_config_value(self.database, "database") + self.username = c.get_config_value(self.database, "user") + self.password = c.get_config_value(self.database, "password") def connect(self, host, db_name, username, password): @@ -247,19 +228,27 @@ class MigrationManager(object): print 'Test finished successfully' -USAGE = '%s [sync|test|simulate|safesync]' % sys.argv[0] +USAGE = 'must specify one of [sync|test|simulate|safesync]' def main(): - manager = MigrationManager() - if len(sys.argv) > 1: - if sys.argv[1] == 'sync': + parser = OptionParser() + parser.add_option("-d", "--database", + help="which database to act on", + dest="database") + parser.add_option("-a", "--action", help="what action to perform", + dest="action") + (options, args) = parser.parse_args() + manager = MigrationManager(options.database) + + if len(args) > 0: + if args[0] == 'sync': manager.do_sync_db() - elif sys.argv[1] == 'test': + elif args[0] == 'test': manager.test_sync_db() - elif sys.argv[1] == 'simulate': + elif args[0] == 'simulate': manager.simulate_sync_db() - elif sys.argv[1] == 'safesync': + elif args[0] == 'safesync': print 'Simluating migration' manager.simulate_sync_db() print 'Performing real migration' @@ -267,7 +256,7 @@ def main(): else: print USAGE return - + print USAGE |