server/serverctl.py
changeset 5590 a56eb02f9ce7
parent 5555 a64f48dd5fe4
parent 5586 aabe082fee02
child 5696 98d390c28edb
equal deleted inserted replaced
5578:6b9fee0c5c42 5590:a56eb02f9ce7
    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')