54 user = user or default_user |
54 user = user or default_user |
55 if user == source.get('db-user') and source.get('db-password'): |
55 if user == source.get('db-user') and source.get('db-password'): |
56 password = source['db-password'] |
56 password = source['db-password'] |
57 else: |
57 else: |
58 password = getpass('password: ') |
58 password = getpass('password: ') |
|
59 extra_args = source.get('db-extra-arguments') |
|
60 extra = extra_args and {'extra_args': extra_args} or {} |
59 return get_connection(driver, dbhost, dbname, user, password=password, |
61 return get_connection(driver, dbhost, dbname, user, password=password, |
60 port=source.get('db-port'), |
62 port=source.get('db-port'), |
61 extra_args=source.get('db-extra-arguments')) |
63 **extra) |
62 |
64 |
63 def system_source_cnx(source, dbms_system_base=False, |
65 def system_source_cnx(source, dbms_system_base=False, |
64 special_privs='CREATE/DROP DATABASE', verbose=True): |
66 special_privs='CREATE/DROP DATABASE', verbose=True): |
65 """shortcut to get a connextion to the instance system database |
67 """shortcut to get a connextion to the instance system database |
66 defined in the given config. If <dbms_system_base> is True, |
68 defined in the given config. If <dbms_system_base> is True, |
364 from logilab.common.db import get_connection |
366 from logilab.common.db import get_connection |
365 appid = pop_arg(args, msg='No instance specified !') |
367 appid = pop_arg(args, msg='No instance specified !') |
366 config = ServerConfiguration.config_for(appid) |
368 config = ServerConfiguration.config_for(appid) |
367 try: |
369 try: |
368 system = config.sources()['system'] |
370 system = config.sources()['system'] |
|
371 extra_args=system.get('db-extra-arguments') |
|
372 extra = extra_args and {'extra_args': extra_args} or {} |
369 get_connection( |
373 get_connection( |
370 system['db-driver'], database=system['db-name'], |
374 system['db-driver'], database=system['db-name'], |
371 host=system.get('db-host'), port=system.get('db-port'), |
375 host=system.get('db-host'), port=system.get('db-port'), |
372 user=system.get('db-user'), password=system.get('db-password'), |
376 user=system.get('db-user'), password=system.get('db-password'), |
373 extra_args=system.get('db-extra-arguments')) |
377 **extra) |
374 except Exception, ex: |
378 except Exception, ex: |
375 raise ConfigurationError( |
379 raise ConfigurationError( |
376 'You seem to have provided wrong connection information in '\ |
380 'You seem to have provided wrong connection information in '\ |
377 'the %s file. Resolve this first (error: %s).' |
381 'the %s file. Resolve this first (error: %s).' |
378 % (config.sources_file(), str(ex).strip())) |
382 % (config.sources_file(), str(ex).strip())) |