equal
deleted
inserted
replaced
41 def source_cnx(source, dbname=None, special_privs=False, verbose=True): |
41 def source_cnx(source, dbname=None, special_privs=False, verbose=True): |
42 """open and return a connection to the system database defined in the |
42 """open and return a connection to the system database defined in the |
43 given server.serverconfig |
43 given server.serverconfig |
44 """ |
44 """ |
45 from getpass import getpass |
45 from getpass import getpass |
46 from logilab.common.db import get_connection |
46 from logilab.database import get_connection |
47 dbhost = source.get('db-host') |
47 dbhost = source.get('db-host') |
48 if dbname is None: |
48 if dbname is None: |
49 dbname = source['db-name'] |
49 dbname = source['db-name'] |
50 driver = source['db-driver'] |
50 driver = source['db-driver'] |
51 print '-> connecting to %s database' % driver, |
51 print '-> connecting to %s database' % driver, |
315 dbname = source['db-name'] |
315 dbname = source['db-name'] |
316 driver = source['db-driver'] |
316 driver = source['db-driver'] |
317 create_db = self.config.create_db |
317 create_db = self.config.create_db |
318 helper = get_db_helper(driver) |
318 helper = get_db_helper(driver) |
319 if driver == 'sqlite': |
319 if driver == 'sqlite': |
320 if os.path.exists(dbname) and automatic or \ |
320 if os.path.exists(dbname) and ( |
321 ASK.confirm('Database %s already exists -- do you want to drop it ?' % dbname): |
321 automatic or |
|
322 ASK.confirm('Database %s already exists. Drop it?' % dbname)): |
322 os.unlink(dbname) |
323 os.unlink(dbname) |
323 elif create_db: |
324 elif create_db: |
324 print '\n'+underline_title('Creating the system database') |
325 print '\n'+underline_title('Creating the system database') |
325 # connect on the dbms system base to create our base |
326 # connect on the dbms system base to create our base |
326 dbcnx = _db_sys_cnx(source, 'CREATE DATABASE and / or USER', verbose=verbose) |
327 dbcnx = _db_sys_cnx(source, 'CREATE DATABASE and / or USER', verbose=verbose) |
390 ) |
391 ) |
391 |
392 |
392 def run(self, args): |
393 def run(self, args): |
393 print '\n'+underline_title('Initializing the system database') |
394 print '\n'+underline_title('Initializing the system database') |
394 from cubicweb.server import init_repository |
395 from cubicweb.server import init_repository |
395 from logilab.common.db import get_connection |
396 from logilab.database import get_connection |
396 appid = pop_arg(args, msg='No instance specified !') |
397 appid = pop_arg(args, msg='No instance specified !') |
397 config = ServerConfiguration.config_for(appid) |
398 config = ServerConfiguration.config_for(appid) |
398 try: |
399 try: |
399 system = config.sources()['system'] |
400 system = config.sources()['system'] |
400 extra_args=system.get('db-extra-arguments') |
401 extra_args=system.get('db-extra-arguments') |