# HG changeset patch # User Mads Kiilerich # Date 1473115878 -7200 # Node ID 4bcaf1ca2e080ef4141dae57e7eef46a9d0468dc # Parent a9412063e8bcfc67cb78a9aa2c156bab21feafd2 db_manage: cleanup and minor refactorings - because we like it better that way. diff -r a9412063e8bc -r 4bcaf1ca2e08 kallithea/lib/db_manage.py --- a/kallithea/lib/db_manage.py Tue Sep 06 00:51:18 2016 +0200 +++ b/kallithea/lib/db_manage.py Tue Sep 06 00:51:18 2016 +0200 @@ -74,10 +74,12 @@ self.cli_args = cli_args or {} self.init_db(SESSION=SESSION) + def _ask_ok(self, msg): + """Invoke ask_ok unless the force_ask option provides the answer""" force_ask = self.cli_args.get('force_ask') if force_ask is not None: - global ask_ok - ask_ok = lambda *args, **kwargs: force_ask + return force_ask + return ask_ok(msg) def init_db(self, SESSION=None): if SESSION: @@ -97,7 +99,7 @@ if self.tests: destroy = True else: - destroy = ask_ok('Are you sure to destroy old database ? [y/n]') + destroy = self._ask_ok('Are you sure to destroy old database ? [y/n]') if not destroy: print 'Nothing done.' sys.exit(0) @@ -164,11 +166,9 @@ if not self.tests: import getpass - # defaults - defaults = self.cli_args - username = defaults.get('username') - password = defaults.get('password') - email = defaults.get('email') + username = self.cli_args.get('username') + password = self.cli_args.get('password') + email = self.cli_args.get('email') def get_password(): password = getpass.getpass('Specify admin password ' @@ -366,8 +366,7 @@ RepoModel.update_repoinfo() def config_prompt(self, test_repo_path='', retries=3): - defaults = self.cli_args - _path = defaults.get('repos_location') + _path = self.cli_args.get('repos_location') if retries == 3: log.info('Setting up repositories config') @@ -399,7 +398,7 @@ # check write access, warn user about non writeable paths elif not os.access(path, os.W_OK) and path_ok: log.warning('No write permission to given path %s', path) - if not ask_ok('Given path %s is not writeable, do you want to ' + if not self._ask_ok('Given path %s is not writeable, do you want to ' 'continue with read only mode ? [y/n]' % (path,)): log.error('Canceled by user') sys.exit(-1)