# HG changeset patch # User Sylvain Thénault # Date 1261552938 -3600 # Node ID 5446c74189b63cef0e6dfd2d0307aca1df5ef100 # Parent 25dd5a0836610801849581fcd73698e141526ba1 quick and dirty fix to avoid crash when running db-create command with an sqlite source diff -r 25dd5a083661 -r 5446c74189b6 server/serverctl.py --- a/server/serverctl.py Tue Dec 22 23:45:43 2009 +0100 +++ b/server/serverctl.py Wed Dec 23 08:22:18 2009 +0100 @@ -285,11 +285,16 @@ automatic = self.get('automatic') appid = pop_arg(args, msg='No instance specified !') config = ServerConfiguration.config_for(appid) - create_db = self.config.create_db source = config.sources()['system'] + dbname = source['db-name'] driver = source['db-driver'] + create_db = self.config.create_db helper = get_adv_func_helper(driver) - if create_db: + if driver == 'sqlite': + if os.path.exists(dbname) and automatic or \ + ASK.confirm('Database %s already exists -- do you want to drop it ?' % dbname): + os.unlink(dbname) + elif create_db: print '\n'+underline_title('Creating the system database') # connect on the dbms system base to create our base dbcnx = _db_sys_cnx(source, 'CREATE DATABASE and / or USER', verbose=verbose) @@ -301,7 +306,6 @@ ASK.confirm('Create db user %s ?' % user, default_is_yes=False)): helper.create_user(source['db-user'], source['db-password']) print '-> user %s created.' % user - dbname = source['db-name'] if dbname in helper.list_databases(cursor): if automatic or ASK.confirm('Database %s already exists -- do you want to drop it ?' % dbname): cursor.execute('DROP DATABASE %s' % dbname) @@ -314,7 +318,7 @@ helper.create_database(cursor, dbname, encoding=source['db-encoding']) dbcnx.commit() - print '-> database %s created.' % source['db-name'] + print '-> database %s created.' % dbname except: dbcnx.rollback() raise