Mercurial > kallithea
comparison rhodecode/lib/db_manage.py @ 837:60cbde084047 beta
fixed wrong migration schema
added filling out some default options for db migration script,
added path fix
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sat, 11 Dec 2010 04:29:21 +0100 |
parents | 08d2dcd71666 |
children | 12eb1a018199 |
comparison
equal
deleted
inserted
replaced
836:28a4bb11bb6f | 837:60cbde084047 |
---|---|
30 import uuid | 30 import uuid |
31 import logging | 31 import logging |
32 from os.path import dirname as dn, join as jn | 32 from os.path import dirname as dn, join as jn |
33 | 33 |
34 from rhodecode import __dbversion__ | 34 from rhodecode import __dbversion__ |
35 from rhodecode.model.db import | |
36 from rhodecode.model import meta | 35 from rhodecode.model import meta |
37 | 36 |
38 from rhodecode.lib.auth import get_crypt_password | 37 from rhodecode.lib.auth import get_crypt_password |
39 from rhodecode.lib.utils import ask_ok | 38 from rhodecode.lib.utils import ask_ok |
40 from rhodecode.model import init_model | 39 from rhodecode.model import init_model |
66 self.db_exists = True | 65 self.db_exists = True |
67 if not override: | 66 if not override: |
68 raise Exception('database already exists') | 67 raise Exception('database already exists') |
69 | 68 |
70 def create_tables(self, override=False): | 69 def create_tables(self, override=False): |
70 """Create a auth database | |
71 """ | 71 """ |
72 Create a auth database | 72 |
73 """ | |
74 self.check_for_db(override) | 73 self.check_for_db(override) |
75 if self.db_exists: | 74 if self.db_exists: |
76 log.info("database exist and it's going to be destroyed") | 75 log.info("database exist and it's going to be destroyed") |
77 if self.tests: | 76 if self.tests: |
78 destroy = True | 77 destroy = True |
99 except: | 98 except: |
100 self.sa.rollback() | 99 self.sa.rollback() |
101 raise | 100 raise |
102 log.info('db version set to: %s', __dbversion__) | 101 log.info('db version set to: %s', __dbversion__) |
103 | 102 |
103 def fix_repo_paths(self): | |
104 """Fixes a old rhodecode version path into new one without a '*' | |
105 """ | |
106 | |
107 paths = self.sa.query(RhodeCodeUi)\ | |
108 .filter(RhodeCodeUi.ui_key == '/')\ | |
109 .scalar() | |
110 | |
111 paths.ui_value = paths.ui_value.replace('*', '') | |
112 | |
113 try: | |
114 self.sa.add(paths) | |
115 self.sa.commit() | |
116 except: | |
117 self.sa.rollback() | |
118 raise | |
119 | |
120 | |
121 | |
104 def admin_prompt(self, second=False): | 122 def admin_prompt(self, second=False): |
105 if not self.tests: | 123 if not self.tests: |
106 import getpass | 124 import getpass |
107 | 125 |
108 | 126 |
134 log.info('creating admin and regular test users') | 152 log.info('creating admin and regular test users') |
135 self.create_user('test_admin', 'test12', 'test_admin@mail.com', True) | 153 self.create_user('test_admin', 'test12', 'test_admin@mail.com', True) |
136 self.create_user('test_regular', 'test12', 'test_regular@mail.com', False) | 154 self.create_user('test_regular', 'test12', 'test_regular@mail.com', False) |
137 self.create_user('test_regular2', 'test12', 'test_regular2@mail.com', False) | 155 self.create_user('test_regular2', 'test12', 'test_regular2@mail.com', False) |
138 | 156 |
139 | 157 def create_ui_settings(self): |
158 """Creates ui settings, fills out hooks | |
159 and disables dotencode | |
160 | |
161 """ | |
162 #HOOKS | |
163 hooks1_key = 'changegroup.update' | |
164 hooks1_ = self.sa.query(RhodeCodeUi)\ | |
165 .filter(RhodeCodeUi.ui_key == hooks1_key).scalar() | |
166 | |
167 hooks1 = RhodeCodeUi() if hooks1_ is None else hooks1_ | |
168 hooks1.ui_section = 'hooks' | |
169 hooks1.ui_key = hooks1_key | |
170 hooks1.ui_value = 'hg update >&2' | |
171 hooks1.ui_active = False | |
172 | |
173 hooks2_key = 'changegroup.repo_size' | |
174 hooks2_ = self.sa.query(RhodeCodeUi)\ | |
175 .filter(RhodeCodeUi.ui_key == hooks2_key).scalar() | |
176 | |
177 hooks2 = RhodeCodeUi() if hooks2_ is None else hooks2_ | |
178 hooks2.ui_section = 'hooks' | |
179 hooks2.ui_key = hooks2_key | |
180 hooks2.ui_value = 'python:rhodecode.lib.hooks.repo_size' | |
181 | |
182 hooks3 = RhodeCodeUi() | |
183 hooks3.ui_section = 'hooks' | |
184 hooks3.ui_key = 'pretxnchangegroup.push_logger' | |
185 hooks3.ui_value = 'python:rhodecode.lib.hooks.log_push_action' | |
186 | |
187 hooks4 = RhodeCodeUi() | |
188 hooks4.ui_section = 'hooks' | |
189 hooks4.ui_key = 'preoutgoing.pull_logger' | |
190 hooks4.ui_value = 'python:rhodecode.lib.hooks.log_pull_action' | |
191 | |
192 #For mercurial 1.7 set backward comapatibility with format | |
193 dotencode_disable = RhodeCodeUi() | |
194 dotencode_disable.ui_section = 'format' | |
195 dotencode_disable.ui_key = 'dotencode' | |
196 dotencode_disable.ui_value = 'false' | |
197 | |
198 try: | |
199 self.sa.add(hooks1) | |
200 self.sa.add(hooks2) | |
201 self.sa.add(hooks3) | |
202 self.sa.add(hooks4) | |
203 self.sa.add(dotencode_disable) | |
204 self.sa.commit() | |
205 except: | |
206 self.sa.rollback() | |
207 raise | |
208 | |
209 | |
210 def create_ldap_options(self): | |
211 """Creates ldap settings""" | |
212 | |
213 try: | |
214 for k in ['ldap_active', 'ldap_host', 'ldap_port', 'ldap_ldaps', | |
215 'ldap_dn_user', 'ldap_dn_pass', 'ldap_base_dn']: | |
216 | |
217 setting = RhodeCodeSettings(k, '') | |
218 self.sa.add(setting) | |
219 self.sa.commit() | |
220 except: | |
221 self.sa.rollback() | |
222 raise | |
140 | 223 |
141 def config_prompt(self, test_repo_path=''): | 224 def config_prompt(self, test_repo_path=''): |
142 log.info('Setting up repositories config') | 225 log.info('Setting up repositories config') |
143 | 226 |
144 if not self.tests and not test_repo_path: | 227 if not self.tests and not test_repo_path: |
149 | 232 |
150 if not os.path.isdir(path): | 233 if not os.path.isdir(path): |
151 log.error('You entered wrong path: %s', path) | 234 log.error('You entered wrong path: %s', path) |
152 sys.exit() | 235 sys.exit() |
153 | 236 |
154 hooks1 = RhodeCodeUi() | 237 self.create_ui_settings() |
155 hooks1.ui_section = 'hooks' | 238 |
156 hooks1.ui_key = 'changegroup.update' | 239 #HG UI OPTIONS |
157 hooks1.ui_value = 'hg update >&2' | |
158 hooks1.ui_active = False | |
159 | |
160 hooks2 = RhodeCodeUi() | |
161 hooks2.ui_section = 'hooks' | |
162 hooks2.ui_key = 'changegroup.repo_size' | |
163 hooks2.ui_value = 'python:rhodecode.lib.hooks.repo_size' | |
164 | |
165 hooks3 = RhodeCodeUi() | |
166 hooks3.ui_section = 'hooks' | |
167 hooks3.ui_key = 'pretxnchangegroup.push_logger' | |
168 hooks3.ui_value = 'python:rhodecode.lib.hooks.log_push_action' | |
169 | |
170 hooks4 = RhodeCodeUi() | |
171 hooks4.ui_section = 'hooks' | |
172 hooks4.ui_key = 'preoutgoing.pull_logger' | |
173 hooks4.ui_value = 'python:rhodecode.lib.hooks.log_pull_action' | |
174 | |
175 #for mercurial 1.7 set backward comapatibility with format | |
176 | |
177 dotencode_disable = RhodeCodeUi() | |
178 dotencode_disable.ui_section = 'format' | |
179 dotencode_disable.ui_key = 'dotencode' | |
180 dotencode_disable.ui_section = 'false' | |
181 | |
182 | |
183 web1 = RhodeCodeUi() | 240 web1 = RhodeCodeUi() |
184 web1.ui_section = 'web' | 241 web1.ui_section = 'web' |
185 web1.ui_key = 'push_ssl' | 242 web1.ui_key = 'push_ssl' |
186 web1.ui_value = 'false' | 243 web1.ui_value = 'false' |
187 | 244 |
209 hgsettings1 = RhodeCodeSettings('realm', 'RhodeCode authentication') | 266 hgsettings1 = RhodeCodeSettings('realm', 'RhodeCode authentication') |
210 hgsettings2 = RhodeCodeSettings('title', 'RhodeCode') | 267 hgsettings2 = RhodeCodeSettings('title', 'RhodeCode') |
211 | 268 |
212 | 269 |
213 try: | 270 try: |
214 self.sa.add(hooks1) | |
215 self.sa.add(hooks2) | |
216 self.sa.add(hooks3) | |
217 self.sa.add(hooks4) | |
218 self.sa.add(web1) | 271 self.sa.add(web1) |
219 self.sa.add(web2) | 272 self.sa.add(web2) |
220 self.sa.add(web3) | 273 self.sa.add(web3) |
221 self.sa.add(web4) | 274 self.sa.add(web4) |
222 self.sa.add(paths) | 275 self.sa.add(paths) |
223 self.sa.add(hgsettings1) | 276 self.sa.add(hgsettings1) |
224 self.sa.add(hgsettings2) | 277 self.sa.add(hgsettings2) |
225 self.sa.add(dotencode_disable) | 278 |
226 for k in ['ldap_active', 'ldap_host', 'ldap_port', 'ldap_ldaps', | 279 self.sa.commit() |
227 'ldap_dn_user', 'ldap_dn_pass', 'ldap_base_dn']: | 280 except: |
228 | 281 self.sa.rollback() |
229 setting = RhodeCodeSettings(k, '') | 282 raise |
230 self.sa.add(setting) | 283 |
231 | 284 self.create_ldap_options() |
232 self.sa.commit() | 285 |
233 except: | |
234 self.sa.rollback() | |
235 raise | |
236 log.info('created ui config') | 286 log.info('created ui config') |
237 | 287 |
238 def create_user(self, username, password, email='', admin=False): | 288 def create_user(self, username, password, email='', admin=False): |
239 log.info('creating administrator user %s', username) | 289 log.info('creating administrator user %s', username) |
240 new_user = User() | 290 new_user = User() |