283 from indexer import get_indexer |
283 from indexer import get_indexer |
284 verbose = self.get('verbose') |
284 verbose = self.get('verbose') |
285 automatic = self.get('automatic') |
285 automatic = self.get('automatic') |
286 appid = pop_arg(args, msg='No instance specified !') |
286 appid = pop_arg(args, msg='No instance specified !') |
287 config = ServerConfiguration.config_for(appid) |
287 config = ServerConfiguration.config_for(appid) |
|
288 source = config.sources()['system'] |
|
289 dbname = source['db-name'] |
|
290 driver = source['db-driver'] |
288 create_db = self.config.create_db |
291 create_db = self.config.create_db |
289 source = config.sources()['system'] |
|
290 driver = source['db-driver'] |
|
291 helper = get_adv_func_helper(driver) |
292 helper = get_adv_func_helper(driver) |
292 if create_db: |
293 if driver == 'sqlite': |
|
294 if os.path.exists(dbname) and automatic or \ |
|
295 ASK.confirm('Database %s already exists -- do you want to drop it ?' % dbname): |
|
296 os.unlink(dbname) |
|
297 elif create_db: |
293 print '\n'+underline_title('Creating the system database') |
298 print '\n'+underline_title('Creating the system database') |
294 # connect on the dbms system base to create our base |
299 # connect on the dbms system base to create our base |
295 dbcnx = _db_sys_cnx(source, 'CREATE DATABASE and / or USER', verbose=verbose) |
300 dbcnx = _db_sys_cnx(source, 'CREATE DATABASE and / or USER', verbose=verbose) |
296 cursor = dbcnx.cursor() |
301 cursor = dbcnx.cursor() |
297 try: |
302 try: |
299 user = source['db-user'] |
304 user = source['db-user'] |
300 if not helper.user_exists(cursor, user) and (automatic or \ |
305 if not helper.user_exists(cursor, user) and (automatic or \ |
301 ASK.confirm('Create db user %s ?' % user, default_is_yes=False)): |
306 ASK.confirm('Create db user %s ?' % user, default_is_yes=False)): |
302 helper.create_user(source['db-user'], source['db-password']) |
307 helper.create_user(source['db-user'], source['db-password']) |
303 print '-> user %s created.' % user |
308 print '-> user %s created.' % user |
304 dbname = source['db-name'] |
|
305 if dbname in helper.list_databases(cursor): |
309 if dbname in helper.list_databases(cursor): |
306 if automatic or ASK.confirm('Database %s already exists -- do you want to drop it ?' % dbname): |
310 if automatic or ASK.confirm('Database %s already exists -- do you want to drop it ?' % dbname): |
307 cursor.execute('DROP DATABASE %s' % dbname) |
311 cursor.execute('DROP DATABASE %s' % dbname) |
308 else: |
312 else: |
309 return |
313 return |
312 source['db-encoding']) |
316 source['db-encoding']) |
313 else: |
317 else: |
314 helper.create_database(cursor, dbname, |
318 helper.create_database(cursor, dbname, |
315 encoding=source['db-encoding']) |
319 encoding=source['db-encoding']) |
316 dbcnx.commit() |
320 dbcnx.commit() |
317 print '-> database %s created.' % source['db-name'] |
321 print '-> database %s created.' % dbname |
318 except: |
322 except: |
319 dbcnx.rollback() |
323 dbcnx.rollback() |
320 raise |
324 raise |
321 cnx = system_source_cnx(source, special_privs='LANGUAGE C', verbose=verbose) |
325 cnx = system_source_cnx(source, special_privs='LANGUAGE C', verbose=verbose) |
322 cursor = cnx.cursor() |
326 cursor = cnx.cursor() |