diff --git a/rhodecode/config/setup_rhodecode.py b/rhodecode/config/setup_rhodecode.py --- a/rhodecode/config/setup_rhodecode.py +++ b/rhodecode/config/setup_rhodecode.py @@ -50,6 +50,16 @@ class SetupCommand(AbstractInstallComman dest='section_name', default=None, help='The name of the section to set up (default: app:main)') + parser.add_option('--force-yes', + action='store_true', + dest='force_ask', + default=None, + help='Force yes to every question') + parser.add_option('--force-no', + action='store_false', + dest='force_ask', + default=None, + help='Force no to every question') def command(self): config_spec = self.args[0] @@ -61,7 +71,7 @@ class SetupCommand(AbstractInstallComman section = 'main' if not ':' in section: plain_section = section - section = 'app:'+section + section = 'app:' + section else: plain_section = section.split(':', 1)[0] if not config_spec.startswith('config:'): diff --git a/rhodecode/lib/db_manage.py b/rhodecode/lib/db_manage.py --- a/rhodecode/lib/db_manage.py +++ b/rhodecode/lib/db_manage.py @@ -57,32 +57,39 @@ def notify(msg): class DbManage(object): - def __init__(self, log_sql, dbconf, root, tests=False): + def __init__(self, log_sql, dbconf, root, tests=False, cli_args={}): self.dbname = dbconf.split('/')[-1] self.tests = tests self.root = root self.dburi = dbconf self.log_sql = log_sql self.db_exists = False + self.cli_args = cli_args self.init_db() + global ask_ok + + if self.cli_args.get('force_ask') is True: + ask_ok = lambda *args, **kwargs: True + elif self.cli_args.get('force_ask') is False: + ask_ok = lambda *args, **kwargs: False def init_db(self): engine = create_engine(self.dburi, echo=self.log_sql) init_model(engine) self.sa = Session() - def create_tables(self, override=False, defaults={}): + def create_tables(self, override=False): """ Create a auth database """ - quiet = defaults.get('quiet') + log.info("Any existing database is going to be destroyed") - if self.tests or quiet: + if self.tests: destroy = True else: destroy = ask_ok('Are you sure to destroy old database ? [y/n]') if not destroy: - sys.exit() + sys.exit('Nothing done') if destroy: Base.metadata.drop_all() @@ -328,11 +335,12 @@ class DbManage(object): self.sa.rollback() raise - def admin_prompt(self, second=False, defaults={}): + def admin_prompt(self, second=False): if not self.tests: import getpass # defaults + defaults = self.cli_args username = defaults.get('username') password = defaults.get('password') email = defaults.get('email') @@ -507,7 +515,8 @@ class DbManage(object): self.populate_default_permissions() return fixed - def config_prompt(self, test_repo_path='', retries=3, defaults={}): + def config_prompt(self, test_repo_path='', retries=3): + defaults = self.cli_args _path = defaults.get('repos_location') if retries == 3: log.info('Setting up repositories config') diff --git a/rhodecode/tests/scripts/create_rc.sh b/rhodecode/tests/scripts/create_rc.sh --- a/rhodecode/tests/scripts/create_rc.sh +++ b/rhodecode/tests/scripts/create_rc.sh @@ -1,6 +1,6 @@ psql -U postgres -h localhost -c 'drop database if exists rhodecode;' psql -U postgres -h localhost -c 'create database rhodecode;' -paster setup-rhodecode rc.ini -q --user=marcink --password=qweqwe --email=marcin@python-blog.com --repos=/home/marcink/repos +paster setup-rhodecode rc.ini --force-yes --user=marcink --password=qweqwe --email=marcin@python-blog.com --repos=/home/marcink/repos API_KEY=`psql -R " " -A -U postgres -h localhost -c "select api_key from users where admin=TRUE" -d rhodecode | awk '{print $2}'` echo "run those after running server" paster serve rc.ini --pid-file=rc.pid --daemon diff --git a/rhodecode/websetup.py b/rhodecode/websetup.py --- a/rhodecode/websetup.py +++ b/rhodecode/websetup.py @@ -37,15 +37,15 @@ def setup_app(command, conf, vars): """Place any commands to setup rhodecode here""" dbconf = conf['sqlalchemy.db1.url'] dbmanage = DbManage(log_sql=True, dbconf=dbconf, root=conf['here'], - tests=False) - dbmanage.create_tables(override=True, defaults=command.options.__dict__) + tests=False, cli_args=command.options.__dict__) + dbmanage.create_tables(override=True) dbmanage.set_db_version() - opts = dbmanage.config_prompt(None, defaults=command.options.__dict__) + opts = dbmanage.config_prompt(None) dbmanage.create_settings(opts) dbmanage.create_default_user() - dbmanage.admin_prompt(defaults=command.options.__dict__) + dbmanage.admin_prompt() dbmanage.create_permissions() dbmanage.populate_default_permissions() - Session.commit() + Session().commit() load_environment(conf.global_conf, conf.local_conf, initial=True) dbmanage.finish()