F add --automatic/-a option to run db-create without user input stable
authorNicolas Chauvat <nicolas.chauvat@logilab.fr>
Mon, 24 Aug 2009 19:53:10 +0200
branchstable
changeset 2969 d95f23a0fc3b
parent 2963 12ad88615a12
child 2971 bc0a270622c2
F add --automatic/-a option to run db-create without user input
server/serverctl.py
--- a/server/serverctl.py	Fri Aug 21 15:05:50 2009 +0200
+++ b/server/serverctl.py	Mon Aug 24 19:53:10 2009 +0200
@@ -257,12 +257,19 @@
           'help': 'verbose mode: will ask all possible configuration questions',
           }
          ),
+        ('automatic',
+         {'short': 'a', 'type' : 'yn', 'metavar': '<auto>',
+          'default': 'n',
+          'help': 'automatic mode: never ask and use default answer to every question',
+          }
+         ),
         )
     def run(self, args):
         """run the command with its specific arguments"""
         from logilab.common.adbh import get_adv_func_helper
         from indexer import get_indexer
         verbose = self.get('verbose')
+        automatic = self.get('automatic')
         appid = pop_arg(args, msg='No instance specified !')
         config = ServerConfiguration.config_for(appid)
         create_db = self.config.create_db
@@ -277,13 +284,13 @@
             try:
                 if helper.users_support:
                     user = source['db-user']
-                    if not helper.user_exists(cursor, user) and \
-                           ASK.confirm('Create db user %s ?' % user, default_is_yes=False):
+                    if not helper.user_exists(cursor, user) and (automatic or \
+                           ASK.confirm('Create db user %s ?' % user, default_is_yes=False)):
                         helper.create_user(source['db-user'], source['db-password'])
                         print '-> user %s created.' % user
                 dbname = source['db-name']
                 if dbname in helper.list_databases(cursor):
-                    if ASK.confirm('Database %s already exists -- do you want to drop it ?' % dbname):
+                    if automatic or ASK.confirm('Database %s already exists -- do you want to drop it ?' % dbname):
                         cursor.execute('DROP DATABASE %s' % dbname)
                     else:
                         return
@@ -311,7 +318,7 @@
         cnx.commit()
         print '-> database for instance %s created and necessary extensions installed.' % appid
         print
-        if ASK.confirm('Run db-init to initialize the system database ?'):
+        if automatic or ASK.confirm('Run db-init to initialize the system database ?'):
             cmd_run('db-init', config.appid)
         else:
             print ('-> nevermind, you can do it later with '