# HG changeset patch # User Marcin Kuzminski # Date 2017-11-10 15:08:48 # Node ID 31bf5a7bd4d39bbfcbb69b1ba780cc5c4a101ddb # Parent 79804d6ecd5279708ff1b67b401be9046c1690fa core: ported setup-app to pyramid command. - backward compat is working too for paster setup-app diff --git a/rhodecode/lib/rc_commands/setup_rc.py b/rhodecode/lib/rc_commands/setup_rc.py --- a/rhodecode/lib/rc_commands/setup_rc.py +++ b/rhodecode/lib/rc_commands/setup_rc.py @@ -17,17 +17,87 @@ # This program is dual-licensed. If you wish to learn more about the # RhodeCode Enterprise Edition, including its added features, Support services, # and proprietary license terms, please see https://rhodecode.com/licenses/ +import logging import click +import pyramid.paster -from rhodecode.lib.pyramid_utils import bootstrap -import pyramid.paster +from rhodecode.lib.pyramid_utils import bootstrap, get_app_config +from rhodecode.lib.db_manage import DbManage +from rhodecode.model.db import Session + + +log = logging.getLogger(__name__) @click.command() @click.argument('ini_path', type=click.Path(exists=True)) -def main(ini_path): +@click.option( + '--force-yes/--force-no', default=None, + help="Force yes/no to every question") +@click.option( + '--user', + default=None, + help='Initial super-admin username') +@click.option( + '--email', + default=None, + help='Initial super-admin email address.') +@click.option( + '--password', + default=None, + help='Initial super-admin password. Minimum 6 chars.') +@click.option( + '--api-key', + help='Initial API key for the admin user') +@click.option( + '--repos', + default=None, + help='Absolute path to storage location. This is storage for all ' + 'existing and future repositories, and repository groups.') +@click.option( + '--public-access/--no-public-access', + default=None, + help='Enable public access on this installation. ' + 'Default is public access enabled.') +def main(ini_path, force_yes, user, email, password, api_key, repos, + public_access): + return command(ini_path, force_yes, user, email, password, api_key, + repos, public_access) + + +def command(ini_path, force_yes, user, email, password, api_key, repos, + public_access): + # mapping of old parameters to new CLI from click + options = dict( + username=user, + email=email, + password=password, + api_key=api_key, + repos_location=repos, + force_ask=force_yes, + public_access=public_access + ) pyramid.paster.setup_logging(ini_path) + config = get_app_config(ini_path) + + db_uri = config['sqlalchemy.db1.url'] + dbmanage = DbManage(log_sql=True, dbconf=db_uri, root='.', + tests=False, cli_args=options) + dbmanage.create_tables(override=True) + dbmanage.set_db_version() + opts = dbmanage.config_prompt(None) + dbmanage.create_settings(opts) + dbmanage.create_default_user() + dbmanage.create_admin_and_prompt() + dbmanage.create_permissions() + dbmanage.populate_default_permissions() + Session().commit() + with bootstrap(ini_path) as env: - print(env['request'].application_url) \ No newline at end of file + msg = 'Successfully initialized database, schema and default data.' + print() + print('*' * len(msg)) + print(msg.upper()) + print('*' * len(msg)) diff --git a/rhodecode/tests/database/conftest.py b/rhodecode/tests/database/conftest.py --- a/rhodecode/tests/database/conftest.py +++ b/rhodecode/tests/database/conftest.py @@ -167,7 +167,7 @@ class DBBackend(object): os.makedirs(self._repos_git_lfs_store) self.execute( - "paster setup-rhodecode {0} --user=marcink " + "rc-setup-app {0} --user=marcink " "--email=marcin@rhodeocode.com --password={1} " "--repos={2} --force-yes".format( _ini_file, 'qweqwe', self._repos_location), env=env) 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,7 +1,7 @@ #!/bin/sh 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 --force-yes --user=marcink --password=qweqwe --email=marcin@python-blog.com --repos=/home/marcink/repos --no-public-access +rc-setup-app rc.ini --force-yes --user=marcink --password=qweqwe --email=marcin@python-blog.com --repos=/home/marcink/repos --no-public-access 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 @@ -18,32 +18,27 @@ # RhodeCode Enterprise Edition, including its added features, Support services, # and proprietary license terms, please see https://rhodecode.com/licenses/ -""" -Weboperations and setup for rhodecode -""" import logging -from rhodecode.config.environment import load_environment -from rhodecode.lib.db_manage import DbManage -from rhodecode.model.meta import Session - +from rhodecode.lib.rc_commands.setup_rc import command as setup_command log = logging.getLogger(__name__) 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, cli_args=command.options.__dict__) - dbmanage.create_tables(override=True) - dbmanage.set_db_version() - opts = dbmanage.config_prompt(None) - dbmanage.create_settings(opts) - dbmanage.create_default_user() - dbmanage.create_admin_and_prompt() - dbmanage.create_permissions() - dbmanage.populate_default_permissions() - Session().commit() - load_environment(conf.global_conf, conf.local_conf, initial=True) + opts = command.options.__dict__ + + # mapping of old parameters to new CLI from click + options = dict( + ini_path=command.args[0], + force_yes=opts.get('force_ask'), + user=opts.get('username'), + email=opts.get('email'), + password=opts.get('password'), + api_key=opts.get('api_key'), + repos=opts.get('repos_location'), + public_access=opts.get('public_access') + ) + setup_command(**options) +