##// END OF EJS Templates
core: ported setup-app to pyramid command....
marcink -
r2341:31bf5a7b default
parent child Browse files
Show More
@@ -17,17 +17,87 b''
17 # This program is dual-licensed. If you wish to learn more about the
17 # This program is dual-licensed. If you wish to learn more about the
18 # RhodeCode Enterprise Edition, including its added features, Support services,
18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20 import logging
20
21
21 import click
22 import click
23 import pyramid.paster
22
24
23 from rhodecode.lib.pyramid_utils import bootstrap
25 from rhodecode.lib.pyramid_utils import bootstrap, get_app_config
24 import pyramid.paster
26 from rhodecode.lib.db_manage import DbManage
27 from rhodecode.model.db import Session
28
29
30 log = logging.getLogger(__name__)
25
31
26
32
27 @click.command()
33 @click.command()
28 @click.argument('ini_path', type=click.Path(exists=True))
34 @click.argument('ini_path', type=click.Path(exists=True))
29 def main(ini_path):
35 @click.option(
36 '--force-yes/--force-no', default=None,
37 help="Force yes/no to every question")
38 @click.option(
39 '--user',
40 default=None,
41 help='Initial super-admin username')
42 @click.option(
43 '--email',
44 default=None,
45 help='Initial super-admin email address.')
46 @click.option(
47 '--password',
48 default=None,
49 help='Initial super-admin password. Minimum 6 chars.')
50 @click.option(
51 '--api-key',
52 help='Initial API key for the admin user')
53 @click.option(
54 '--repos',
55 default=None,
56 help='Absolute path to storage location. This is storage for all '
57 'existing and future repositories, and repository groups.')
58 @click.option(
59 '--public-access/--no-public-access',
60 default=None,
61 help='Enable public access on this installation. '
62 'Default is public access enabled.')
63 def main(ini_path, force_yes, user, email, password, api_key, repos,
64 public_access):
65 return command(ini_path, force_yes, user, email, password, api_key,
66 repos, public_access)
67
68
69 def command(ini_path, force_yes, user, email, password, api_key, repos,
70 public_access):
71 # mapping of old parameters to new CLI from click
72 options = dict(
73 username=user,
74 email=email,
75 password=password,
76 api_key=api_key,
77 repos_location=repos,
78 force_ask=force_yes,
79 public_access=public_access
80 )
30 pyramid.paster.setup_logging(ini_path)
81 pyramid.paster.setup_logging(ini_path)
31
82
83 config = get_app_config(ini_path)
84
85 db_uri = config['sqlalchemy.db1.url']
86 dbmanage = DbManage(log_sql=True, dbconf=db_uri, root='.',
87 tests=False, cli_args=options)
88 dbmanage.create_tables(override=True)
89 dbmanage.set_db_version()
90 opts = dbmanage.config_prompt(None)
91 dbmanage.create_settings(opts)
92 dbmanage.create_default_user()
93 dbmanage.create_admin_and_prompt()
94 dbmanage.create_permissions()
95 dbmanage.populate_default_permissions()
96 Session().commit()
97
32 with bootstrap(ini_path) as env:
98 with bootstrap(ini_path) as env:
33 print(env['request'].application_url) No newline at end of file
99 msg = 'Successfully initialized database, schema and default data.'
100 print()
101 print('*' * len(msg))
102 print(msg.upper())
103 print('*' * len(msg))
@@ -167,7 +167,7 b' class DBBackend(object):'
167 os.makedirs(self._repos_git_lfs_store)
167 os.makedirs(self._repos_git_lfs_store)
168
168
169 self.execute(
169 self.execute(
170 "paster setup-rhodecode {0} --user=marcink "
170 "rc-setup-app {0} --user=marcink "
171 "--email=marcin@rhodeocode.com --password={1} "
171 "--email=marcin@rhodeocode.com --password={1} "
172 "--repos={2} --force-yes".format(
172 "--repos={2} --force-yes".format(
173 _ini_file, 'qweqwe', self._repos_location), env=env)
173 _ini_file, 'qweqwe', self._repos_location), env=env)
@@ -1,7 +1,7 b''
1 #!/bin/sh
1 #!/bin/sh
2 psql -U postgres -h localhost -c 'drop database if exists rhodecode;'
2 psql -U postgres -h localhost -c 'drop database if exists rhodecode;'
3 psql -U postgres -h localhost -c 'create database rhodecode;'
3 psql -U postgres -h localhost -c 'create database rhodecode;'
4 paster setup-rhodecode rc.ini --force-yes --user=marcink --password=qweqwe --email=marcin@python-blog.com --repos=/home/marcink/repos --no-public-access
4 rc-setup-app rc.ini --force-yes --user=marcink --password=qweqwe --email=marcin@python-blog.com --repos=/home/marcink/repos --no-public-access
5 API_KEY=`psql -R " " -A -U postgres -h localhost -c "select api_key from users where admin=TRUE" -d rhodecode | awk '{print $2}'`
5 API_KEY=`psql -R " " -A -U postgres -h localhost -c "select api_key from users where admin=TRUE" -d rhodecode | awk '{print $2}'`
6 echo "run those after running server"
6 echo "run those after running server"
7 paster serve rc.ini --pid-file=rc.pid --daemon
7 paster serve rc.ini --pid-file=rc.pid --daemon
@@ -18,32 +18,27 b''
18 # RhodeCode Enterprise Edition, including its added features, Support services,
18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20
20
21 """
22 Weboperations and setup for rhodecode
23 """
24
21
25 import logging
22 import logging
26
23
27 from rhodecode.config.environment import load_environment
24 from rhodecode.lib.rc_commands.setup_rc import command as setup_command
28 from rhodecode.lib.db_manage import DbManage
29 from rhodecode.model.meta import Session
30
31
25
32 log = logging.getLogger(__name__)
26 log = logging.getLogger(__name__)
33
27
34
28
35 def setup_app(command, conf, vars):
29 def setup_app(command, conf, vars):
36 """Place any commands to setup rhodecode here"""
30 opts = command.options.__dict__
37 dbconf = conf['sqlalchemy.db1.url']
31
38 dbmanage = DbManage(log_sql=True, dbconf=dbconf, root=conf['here'],
32 # mapping of old parameters to new CLI from click
39 tests=False, cli_args=command.options.__dict__)
33 options = dict(
40 dbmanage.create_tables(override=True)
34 ini_path=command.args[0],
41 dbmanage.set_db_version()
35 force_yes=opts.get('force_ask'),
42 opts = dbmanage.config_prompt(None)
36 user=opts.get('username'),
43 dbmanage.create_settings(opts)
37 email=opts.get('email'),
44 dbmanage.create_default_user()
38 password=opts.get('password'),
45 dbmanage.create_admin_and_prompt()
39 api_key=opts.get('api_key'),
46 dbmanage.create_permissions()
40 repos=opts.get('repos_location'),
47 dbmanage.populate_default_permissions()
41 public_access=opts.get('public_access')
48 Session().commit()
42 )
49 load_environment(conf.global_conf, conf.local_conf, initial=True)
43 setup_command(**options)
44
General Comments 0
You need to be logged in to leave comments. Login now