##// END OF EJS Templates
core: ported setup-app to pyramid command....
marcink -
r2341:31bf5a7b default
parent child Browse files
Show More
@@ -1,33 +1,103 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2
2
3 # Copyright (C) 2016-2017 RhodeCode GmbH
3 # Copyright (C) 2016-2017 RhodeCode GmbH
4 #
4 #
5 # This program is free software: you can redistribute it and/or modify
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License, version 3
6 # it under the terms of the GNU Affero General Public License, version 3
7 # (only), as published by the Free Software Foundation.
7 # (only), as published by the Free Software Foundation.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU Affero General Public License
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #
16 #
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))
@@ -1,287 +1,287 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2
2
3 # Copyright (C) 2010-2017 RhodeCode GmbH
3 # Copyright (C) 2010-2017 RhodeCode GmbH
4 #
4 #
5 # This program is free software: you can redistribute it and/or modify
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License, version 3
6 # it under the terms of the GNU Affero General Public License, version 3
7 # (only), as published by the Free Software Foundation.
7 # (only), as published by the Free Software Foundation.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU Affero General Public License
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #
16 #
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
20
21 from subprocess32 import Popen, PIPE
21 from subprocess32 import Popen, PIPE
22 import os
22 import os
23 import shutil
23 import shutil
24 import sys
24 import sys
25 import tempfile
25 import tempfile
26
26
27 import pytest
27 import pytest
28 from sqlalchemy.engine import url
28 from sqlalchemy.engine import url
29
29
30 from rhodecode.tests.fixture import TestINI
30 from rhodecode.tests.fixture import TestINI
31
31
32
32
33 def _get_dbs_from_metafunc(metafunc):
33 def _get_dbs_from_metafunc(metafunc):
34 if hasattr(metafunc.function, 'dbs'):
34 if hasattr(metafunc.function, 'dbs'):
35 # Supported backends by this test function, created from
35 # Supported backends by this test function, created from
36 # pytest.mark.dbs
36 # pytest.mark.dbs
37 backends = metafunc.function.dbs.args
37 backends = metafunc.function.dbs.args
38 else:
38 else:
39 backends = metafunc.config.getoption('--dbs')
39 backends = metafunc.config.getoption('--dbs')
40 return backends
40 return backends
41
41
42
42
43 def pytest_generate_tests(metafunc):
43 def pytest_generate_tests(metafunc):
44 # Support test generation based on --dbs parameter
44 # Support test generation based on --dbs parameter
45 if 'db_backend' in metafunc.fixturenames:
45 if 'db_backend' in metafunc.fixturenames:
46 requested_backends = set(metafunc.config.getoption('--dbs'))
46 requested_backends = set(metafunc.config.getoption('--dbs'))
47 backends = _get_dbs_from_metafunc(metafunc)
47 backends = _get_dbs_from_metafunc(metafunc)
48 backends = requested_backends.intersection(backends)
48 backends = requested_backends.intersection(backends)
49 # TODO: johbo: Disabling a backend did not work out with
49 # TODO: johbo: Disabling a backend did not work out with
50 # parametrization, find better way to achieve this.
50 # parametrization, find better way to achieve this.
51 if not backends:
51 if not backends:
52 metafunc.function._skip = True
52 metafunc.function._skip = True
53 metafunc.parametrize('db_backend_name', backends)
53 metafunc.parametrize('db_backend_name', backends)
54
54
55
55
56 def pytest_collection_modifyitems(session, config, items):
56 def pytest_collection_modifyitems(session, config, items):
57 remaining = [
57 remaining = [
58 i for i in items if not getattr(i.obj, '_skip', False)]
58 i for i in items if not getattr(i.obj, '_skip', False)]
59 items[:] = remaining
59 items[:] = remaining
60
60
61
61
62 @pytest.fixture
62 @pytest.fixture
63 def db_backend(
63 def db_backend(
64 request, db_backend_name, pylons_config, tmpdir_factory):
64 request, db_backend_name, pylons_config, tmpdir_factory):
65 basetemp = tmpdir_factory.getbasetemp().strpath
65 basetemp = tmpdir_factory.getbasetemp().strpath
66 klass = _get_backend(db_backend_name)
66 klass = _get_backend(db_backend_name)
67
67
68 option_name = '--{}-connection-string'.format(db_backend_name)
68 option_name = '--{}-connection-string'.format(db_backend_name)
69 connection_string = request.config.getoption(option_name) or None
69 connection_string = request.config.getoption(option_name) or None
70
70
71 return klass(
71 return klass(
72 config_file=pylons_config, basetemp=basetemp,
72 config_file=pylons_config, basetemp=basetemp,
73 connection_string=connection_string)
73 connection_string=connection_string)
74
74
75
75
76 def _get_backend(backend_type):
76 def _get_backend(backend_type):
77 return {
77 return {
78 'sqlite': SQLiteDBBackend,
78 'sqlite': SQLiteDBBackend,
79 'postgres': PostgresDBBackend,
79 'postgres': PostgresDBBackend,
80 'mysql': MySQLDBBackend,
80 'mysql': MySQLDBBackend,
81 '': EmptyDBBackend
81 '': EmptyDBBackend
82 }[backend_type]
82 }[backend_type]
83
83
84
84
85 class DBBackend(object):
85 class DBBackend(object):
86 _store = os.path.dirname(os.path.abspath(__file__))
86 _store = os.path.dirname(os.path.abspath(__file__))
87 _type = None
87 _type = None
88 _base_ini_config = [{'app:main': {'vcs.start_server': 'false'}}]
88 _base_ini_config = [{'app:main': {'vcs.start_server': 'false'}}]
89 _db_url = [{'app:main': {'sqlalchemy.db1.url': ''}}]
89 _db_url = [{'app:main': {'sqlalchemy.db1.url': ''}}]
90 _base_db_name = 'rhodecode_test_db_backend'
90 _base_db_name = 'rhodecode_test_db_backend'
91
91
92 def __init__(
92 def __init__(
93 self, config_file, db_name=None, basetemp=None,
93 self, config_file, db_name=None, basetemp=None,
94 connection_string=None):
94 connection_string=None):
95
95
96 from rhodecode.lib.vcs.backends.hg import largefiles_store
96 from rhodecode.lib.vcs.backends.hg import largefiles_store
97 from rhodecode.lib.vcs.backends.git import lfs_store
97 from rhodecode.lib.vcs.backends.git import lfs_store
98
98
99 self.fixture_store = os.path.join(self._store, self._type)
99 self.fixture_store = os.path.join(self._store, self._type)
100 self.db_name = db_name or self._base_db_name
100 self.db_name = db_name or self._base_db_name
101 self._base_ini_file = config_file
101 self._base_ini_file = config_file
102 self.stderr = ''
102 self.stderr = ''
103 self.stdout = ''
103 self.stdout = ''
104 self._basetemp = basetemp or tempfile.gettempdir()
104 self._basetemp = basetemp or tempfile.gettempdir()
105 self._repos_location = os.path.join(self._basetemp, 'rc_test_repos')
105 self._repos_location = os.path.join(self._basetemp, 'rc_test_repos')
106 self._repos_hg_largefiles_store = largefiles_store(self._basetemp)
106 self._repos_hg_largefiles_store = largefiles_store(self._basetemp)
107 self._repos_git_lfs_store = lfs_store(self._basetemp)
107 self._repos_git_lfs_store = lfs_store(self._basetemp)
108 self.connection_string = connection_string
108 self.connection_string = connection_string
109
109
110 @property
110 @property
111 def connection_string(self):
111 def connection_string(self):
112 return self._connection_string
112 return self._connection_string
113
113
114 @connection_string.setter
114 @connection_string.setter
115 def connection_string(self, new_connection_string):
115 def connection_string(self, new_connection_string):
116 if not new_connection_string:
116 if not new_connection_string:
117 new_connection_string = self.get_default_connection_string()
117 new_connection_string = self.get_default_connection_string()
118 else:
118 else:
119 new_connection_string = new_connection_string.format(
119 new_connection_string = new_connection_string.format(
120 db_name=self.db_name)
120 db_name=self.db_name)
121 url_parts = url.make_url(new_connection_string)
121 url_parts = url.make_url(new_connection_string)
122 self._connection_string = new_connection_string
122 self._connection_string = new_connection_string
123 self.user = url_parts.username
123 self.user = url_parts.username
124 self.password = url_parts.password
124 self.password = url_parts.password
125 self.host = url_parts.host
125 self.host = url_parts.host
126
126
127 def get_default_connection_string(self):
127 def get_default_connection_string(self):
128 raise NotImplementedError('default connection_string is required.')
128 raise NotImplementedError('default connection_string is required.')
129
129
130 def execute(self, cmd, env=None, *args):
130 def execute(self, cmd, env=None, *args):
131 """
131 """
132 Runs command on the system with given ``args``.
132 Runs command on the system with given ``args``.
133 """
133 """
134
134
135 command = cmd + ' ' + ' '.join(args)
135 command = cmd + ' ' + ' '.join(args)
136 sys.stdout.write(command)
136 sys.stdout.write(command)
137
137
138 # Tell Python to use UTF-8 encoding out stdout
138 # Tell Python to use UTF-8 encoding out stdout
139 _env = os.environ.copy()
139 _env = os.environ.copy()
140 _env['PYTHONIOENCODING'] = 'UTF-8'
140 _env['PYTHONIOENCODING'] = 'UTF-8'
141 if env:
141 if env:
142 _env.update(env)
142 _env.update(env)
143 self.p = Popen(command, shell=True, stdout=PIPE, stderr=PIPE, env=_env)
143 self.p = Popen(command, shell=True, stdout=PIPE, stderr=PIPE, env=_env)
144 self.stdout, self.stderr = self.p.communicate()
144 self.stdout, self.stderr = self.p.communicate()
145 sys.stdout.write('COMMAND:'+command+'\n')
145 sys.stdout.write('COMMAND:'+command+'\n')
146 sys.stdout.write(self.stdout)
146 sys.stdout.write(self.stdout)
147 return self.stdout, self.stderr
147 return self.stdout, self.stderr
148
148
149 def assert_returncode_success(self):
149 def assert_returncode_success(self):
150 if not self.p.returncode == 0:
150 if not self.p.returncode == 0:
151 print(self.stderr)
151 print(self.stderr)
152 raise AssertionError('non 0 retcode:{}'.format(self.p.returncode))
152 raise AssertionError('non 0 retcode:{}'.format(self.p.returncode))
153
153
154 def setup_rhodecode_db(self, ini_params=None, env=None):
154 def setup_rhodecode_db(self, ini_params=None, env=None):
155 if not ini_params:
155 if not ini_params:
156 ini_params = self._base_ini_config
156 ini_params = self._base_ini_config
157
157
158 ini_params.extend(self._db_url)
158 ini_params.extend(self._db_url)
159 with TestINI(self._base_ini_file, ini_params,
159 with TestINI(self._base_ini_file, ini_params,
160 self._type, destroy=True) as _ini_file:
160 self._type, destroy=True) as _ini_file:
161
161
162 if not os.path.isdir(self._repos_location):
162 if not os.path.isdir(self._repos_location):
163 os.makedirs(self._repos_location)
163 os.makedirs(self._repos_location)
164 if not os.path.isdir(self._repos_hg_largefiles_store):
164 if not os.path.isdir(self._repos_hg_largefiles_store):
165 os.makedirs(self._repos_hg_largefiles_store)
165 os.makedirs(self._repos_hg_largefiles_store)
166 if not os.path.isdir(self._repos_git_lfs_store):
166 if not os.path.isdir(self._repos_git_lfs_store):
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)
174
174
175 def upgrade_database(self, ini_params=None):
175 def upgrade_database(self, ini_params=None):
176 if not ini_params:
176 if not ini_params:
177 ini_params = self._base_ini_config
177 ini_params = self._base_ini_config
178 ini_params.extend(self._db_url)
178 ini_params.extend(self._db_url)
179
179
180 test_ini = TestINI(
180 test_ini = TestINI(
181 self._base_ini_file, ini_params, self._type, destroy=True)
181 self._base_ini_file, ini_params, self._type, destroy=True)
182 with test_ini as ini_file:
182 with test_ini as ini_file:
183 if not os.path.isdir(self._repos_location):
183 if not os.path.isdir(self._repos_location):
184 os.makedirs(self._repos_location)
184 os.makedirs(self._repos_location)
185 self.execute(
185 self.execute(
186 "paster upgrade-db {} --force-yes".format(ini_file))
186 "paster upgrade-db {} --force-yes".format(ini_file))
187
187
188 def setup_db(self):
188 def setup_db(self):
189 raise NotImplementedError
189 raise NotImplementedError
190
190
191 def teardown_db(self):
191 def teardown_db(self):
192 raise NotImplementedError
192 raise NotImplementedError
193
193
194 def import_dump(self, dumpname):
194 def import_dump(self, dumpname):
195 raise NotImplementedError
195 raise NotImplementedError
196
196
197
197
198 class EmptyDBBackend(DBBackend):
198 class EmptyDBBackend(DBBackend):
199 _type = ''
199 _type = ''
200
200
201 def setup_db(self):
201 def setup_db(self):
202 pass
202 pass
203
203
204 def teardown_db(self):
204 def teardown_db(self):
205 pass
205 pass
206
206
207 def import_dump(self, dumpname):
207 def import_dump(self, dumpname):
208 pass
208 pass
209
209
210 def assert_returncode_success(self):
210 def assert_returncode_success(self):
211 assert True
211 assert True
212
212
213
213
214 class SQLiteDBBackend(DBBackend):
214 class SQLiteDBBackend(DBBackend):
215 _type = 'sqlite'
215 _type = 'sqlite'
216
216
217 def get_default_connection_string(self):
217 def get_default_connection_string(self):
218 return 'sqlite:///{}/{}.sqlite'.format(self._basetemp, self.db_name)
218 return 'sqlite:///{}/{}.sqlite'.format(self._basetemp, self.db_name)
219
219
220 def setup_db(self):
220 def setup_db(self):
221 # dump schema for tests
221 # dump schema for tests
222 # cp -v $TEST_DB_NAME
222 # cp -v $TEST_DB_NAME
223 self._db_url = [{'app:main': {
223 self._db_url = [{'app:main': {
224 'sqlalchemy.db1.url': self.connection_string}}]
224 'sqlalchemy.db1.url': self.connection_string}}]
225
225
226 def import_dump(self, dumpname):
226 def import_dump(self, dumpname):
227 dump = os.path.join(self.fixture_store, dumpname)
227 dump = os.path.join(self.fixture_store, dumpname)
228 shutil.copy(
228 shutil.copy(
229 dump,
229 dump,
230 os.path.join(self._basetemp, '{0.db_name}.sqlite'.format(self)))
230 os.path.join(self._basetemp, '{0.db_name}.sqlite'.format(self)))
231
231
232 def teardown_db(self):
232 def teardown_db(self):
233 self.execute("rm -rf {}.sqlite".format(
233 self.execute("rm -rf {}.sqlite".format(
234 os.path.join(self._basetemp, self.db_name)))
234 os.path.join(self._basetemp, self.db_name)))
235
235
236
236
237 class MySQLDBBackend(DBBackend):
237 class MySQLDBBackend(DBBackend):
238 _type = 'mysql'
238 _type = 'mysql'
239
239
240 def get_default_connection_string(self):
240 def get_default_connection_string(self):
241 return 'mysql://root:qweqwe@127.0.0.1/{}'.format(self.db_name)
241 return 'mysql://root:qweqwe@127.0.0.1/{}'.format(self.db_name)
242
242
243 def setup_db(self):
243 def setup_db(self):
244 # dump schema for tests
244 # dump schema for tests
245 # mysqldump -uroot -pqweqwe $TEST_DB_NAME
245 # mysqldump -uroot -pqweqwe $TEST_DB_NAME
246 self._db_url = [{'app:main': {
246 self._db_url = [{'app:main': {
247 'sqlalchemy.db1.url': self.connection_string}}]
247 'sqlalchemy.db1.url': self.connection_string}}]
248 self.execute("mysql -v -u{} -p{} -e 'create database '{}';'".format(
248 self.execute("mysql -v -u{} -p{} -e 'create database '{}';'".format(
249 self.user, self.password, self.db_name))
249 self.user, self.password, self.db_name))
250
250
251 def import_dump(self, dumpname):
251 def import_dump(self, dumpname):
252 dump = os.path.join(self.fixture_store, dumpname)
252 dump = os.path.join(self.fixture_store, dumpname)
253 self.execute("mysql -u{} -p{} {} < {}".format(
253 self.execute("mysql -u{} -p{} {} < {}".format(
254 self.user, self.password, self.db_name, dump))
254 self.user, self.password, self.db_name, dump))
255
255
256 def teardown_db(self):
256 def teardown_db(self):
257 self.execute("mysql -v -u{} -p{} -e 'drop database '{}';'".format(
257 self.execute("mysql -v -u{} -p{} -e 'drop database '{}';'".format(
258 self.user, self.password, self.db_name))
258 self.user, self.password, self.db_name))
259
259
260
260
261 class PostgresDBBackend(DBBackend):
261 class PostgresDBBackend(DBBackend):
262 _type = 'postgres'
262 _type = 'postgres'
263
263
264 def get_default_connection_string(self):
264 def get_default_connection_string(self):
265 return 'postgresql://postgres:qweqwe@localhost/{}'.format(self.db_name)
265 return 'postgresql://postgres:qweqwe@localhost/{}'.format(self.db_name)
266
266
267 def setup_db(self):
267 def setup_db(self):
268 # dump schema for tests
268 # dump schema for tests
269 # pg_dump -U postgres -h localhost $TEST_DB_NAME
269 # pg_dump -U postgres -h localhost $TEST_DB_NAME
270 self._db_url = [{'app:main': {
270 self._db_url = [{'app:main': {
271 'sqlalchemy.db1.url':
271 'sqlalchemy.db1.url':
272 self.connection_string}}]
272 self.connection_string}}]
273 self.execute("PGPASSWORD={} psql -U {} -h localhost "
273 self.execute("PGPASSWORD={} psql -U {} -h localhost "
274 "-c 'create database '{}';'".format(
274 "-c 'create database '{}';'".format(
275 self.password, self.user, self.db_name))
275 self.password, self.user, self.db_name))
276
276
277 def teardown_db(self):
277 def teardown_db(self):
278 self.execute("PGPASSWORD={} psql -U {} -h localhost "
278 self.execute("PGPASSWORD={} psql -U {} -h localhost "
279 "-c 'drop database if exists '{}';'".format(
279 "-c 'drop database if exists '{}';'".format(
280 self.password, self.user, self.db_name))
280 self.password, self.user, self.db_name))
281
281
282 def import_dump(self, dumpname):
282 def import_dump(self, dumpname):
283 dump = os.path.join(self.fixture_store, dumpname)
283 dump = os.path.join(self.fixture_store, dumpname)
284 self.execute(
284 self.execute(
285 "PGPASSWORD={} psql -U {} -h localhost -d {} -1 "
285 "PGPASSWORD={} psql -U {} -h localhost -d {} -1 "
286 "-f {}".format(
286 "-f {}".format(
287 self.password, self.user, self.db_name, dump))
287 self.password, self.user, self.db_name, dump))
@@ -1,17 +1,17 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
8 sleep 3
8 sleep 3
9 rhodecode-api --apikey=$API_KEY --apihost=http://127.0.0.1:5001 create_user username:demo1 password:qweqwe email:demo1@rhodecode.org
9 rhodecode-api --apikey=$API_KEY --apihost=http://127.0.0.1:5001 create_user username:demo1 password:qweqwe email:demo1@rhodecode.org
10 rhodecode-api --apikey=$API_KEY --apihost=http://127.0.0.1:5001 create_user username:demo2 password:qweqwe email:demo2@rhodecode.org
10 rhodecode-api --apikey=$API_KEY --apihost=http://127.0.0.1:5001 create_user username:demo2 password:qweqwe email:demo2@rhodecode.org
11 rhodecode-api --apikey=$API_KEY --apihost=http://127.0.0.1:5001 create_user username:demo3 password:qweqwe email:demo3@rhodecode.org
11 rhodecode-api --apikey=$API_KEY --apihost=http://127.0.0.1:5001 create_user username:demo3 password:qweqwe email:demo3@rhodecode.org
12 rhodecode-api --apikey=$API_KEY --apihost=http://127.0.0.1:5001 create_user_group group_name:demo12
12 rhodecode-api --apikey=$API_KEY --apihost=http://127.0.0.1:5001 create_user_group group_name:demo12
13 rhodecode-api --apikey=$API_KEY --apihost=http://127.0.0.1:5001 add_user_to_user_group usergroupid:demo12 userid:demo1
13 rhodecode-api --apikey=$API_KEY --apihost=http://127.0.0.1:5001 add_user_to_user_group usergroupid:demo12 userid:demo1
14 rhodecode-api --apikey=$API_KEY --apihost=http://127.0.0.1:5001 add_user_to_user_group usergroupid:demo12 userid:demo2
14 rhodecode-api --apikey=$API_KEY --apihost=http://127.0.0.1:5001 add_user_to_user_group usergroupid:demo12 userid:demo2
15 echo "killing server"
15 echo "killing server"
16 kill `cat rc.pid`
16 kill `cat rc.pid`
17 rm rc.pid
17 rm rc.pid
@@ -1,49 +1,44 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2
2
3 # Copyright (C) 2010-2017 RhodeCode GmbH
3 # Copyright (C) 2010-2017 RhodeCode GmbH
4 #
4 #
5 # This program is free software: you can redistribute it and/or modify
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License, version 3
6 # it under the terms of the GNU Affero General Public License, version 3
7 # (only), as published by the Free Software Foundation.
7 # (only), as published by the Free Software Foundation.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU Affero General Public License
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #
16 #
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
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