239 from cubicweb.server.repository import pyro_unregister |
239 from cubicweb.server.repository import pyro_unregister |
240 pyro_unregister(self.config) |
240 pyro_unregister(self.config) |
241 |
241 |
242 |
242 |
243 # repository specific commands ################################################ |
243 # repository specific commands ################################################ |
|
244 |
244 class CreateInstanceDBCommand(Command): |
245 class CreateInstanceDBCommand(Command): |
245 """Create the system database of an instance (run after 'create'). |
246 """Create the system database of an instance (run after 'create'). |
246 |
247 |
247 You will be prompted for a login / password to use to connect to |
248 You will be prompted for a login / password to use to connect to |
248 the system database. The given user should have almost all rights |
249 the system database. The given user should have almost all rights |
357 ) |
358 ) |
358 |
359 |
359 def run(self, args): |
360 def run(self, args): |
360 print '\n'+underline_title('Initializing the system database') |
361 print '\n'+underline_title('Initializing the system database') |
361 from cubicweb.server import init_repository |
362 from cubicweb.server import init_repository |
|
363 from logilab.common.db import get_connection |
362 appid = pop_arg(args, msg='No instance specified !') |
364 appid = pop_arg(args, msg='No instance specified !') |
363 config = ServerConfiguration.config_for(appid) |
365 config = ServerConfiguration.config_for(appid) |
|
366 try: |
|
367 system = config.sources()['system'] |
|
368 get_connection( |
|
369 system['db-driver'], database=system['db-name'], |
|
370 host=system.get('db-host'), port=system.get('db-port'), |
|
371 user=system.get('db-user'), password=system.get('db-password')) |
|
372 except Exception, ex: |
|
373 raise ConfigurationError( |
|
374 'You seem to have provided wrong connection information in '\ |
|
375 'the %s file. Resolve this first (error: %s).' |
|
376 % (config.sources_file(), str(ex).strip())) |
364 init_repository(config, drop=self.config.drop) |
377 init_repository(config, drop=self.config.drop) |
365 |
378 |
366 |
379 |
367 class GrantUserOnInstanceCommand(Command): |
380 class GrantUserOnInstanceCommand(Command): |
368 """Grant a database user on a repository system database. |
381 """Grant a database user on a repository system database. |
402 traceback.print_exc() |
415 traceback.print_exc() |
403 print '-> an error occured:', ex |
416 print '-> an error occured:', ex |
404 else: |
417 else: |
405 cnx.commit() |
418 cnx.commit() |
406 print '-> rights granted to %s on instance %s.' % (appid, user) |
419 print '-> rights granted to %s on instance %s.' % (appid, user) |
|
420 |
407 |
421 |
408 class ResetAdminPasswordCommand(Command): |
422 class ResetAdminPasswordCommand(Command): |
409 """Reset the administrator password. |
423 """Reset the administrator password. |
410 |
424 |
411 <instance> |
425 <instance> |