##// END OF EJS Templates
added migrations for column change for gists expiration date
marcink -
r3972:3cb5a35a default
parent child Browse files
Show More
@@ -0,0 +1,38 b''
1 import logging
2 import datetime
3
4 from sqlalchemy import *
5 from sqlalchemy.exc import DatabaseError
6 from sqlalchemy.orm import relation, backref, class_mapper, joinedload
7 from sqlalchemy.orm.session import Session
8 from sqlalchemy.ext.declarative import declarative_base
9
10 from rhodecode.lib.dbmigrate.migrate import *
11 from rhodecode.lib.dbmigrate.migrate.changeset import *
12
13 from rhodecode.model.meta import Base
14 from rhodecode.model import meta
15 from rhodecode.lib.dbmigrate.versions import _reset_base
16
17 log = logging.getLogger(__name__)
18
19
20 def upgrade(migrate_engine):
21 """
22 Upgrade operations go here.
23 Don't create your own engine; bind migrate_engine to your metadata
24 """
25 _reset_base(migrate_engine)
26
27 #==========================================================================
28 # Gist
29 #==========================================================================
30 from rhodecode.lib.dbmigrate.schema.db_1_7_0 import Gist
31 tbl = Gist.__table__
32 user_id = tbl.columns.gist_expires
33 user_id.alter(type=Float(53))
34
35
36 def downgrade(migrate_engine):
37 meta = MetaData()
38 meta.bind = migrate_engine
@@ -1,62 +1,62 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """
2 """
3 rhodecode.__init__
3 rhodecode.__init__
4 ~~~~~~~~~~~~~~~~~~
4 ~~~~~~~~~~~~~~~~~~
5
5
6 RhodeCode, a web based repository management based on pylons
6 RhodeCode, a web based repository management based on pylons
7 versioning implementation: http://www.python.org/dev/peps/pep-0386/
7 versioning implementation: http://www.python.org/dev/peps/pep-0386/
8
8
9 :created_on: Apr 9, 2010
9 :created_on: Apr 9, 2010
10 :author: marcink
10 :author: marcink
11 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com>
11 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com>
12 :license: GPLv3, see COPYING for more details.
12 :license: GPLv3, see COPYING for more details.
13 """
13 """
14 # This program is free software: you can redistribute it and/or modify
14 # This program is free software: you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by
15 # it under the terms of the GNU General Public License as published by
16 # the Free Software Foundation, either version 3 of the License, or
16 # the Free Software Foundation, either version 3 of the License, or
17 # (at your option) any later version.
17 # (at your option) any later version.
18 #
18 #
19 # This program is distributed in the hope that it will be useful,
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
22 # GNU General Public License for more details.
23 #
23 #
24 # You should have received a copy of the GNU General Public License
24 # You should have received a copy of the GNU General Public License
25 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 # along with this program. If not, see <http://www.gnu.org/licenses/>.
26 import sys
26 import sys
27 import platform
27 import platform
28
28
29 VERSION = (1, 7, 1)
29 VERSION = (1, 7, 1)
30 BACKENDS = {
30 BACKENDS = {
31 'hg': 'Mercurial repository',
31 'hg': 'Mercurial repository',
32 'git': 'Git repository',
32 'git': 'Git repository',
33 }
33 }
34
34
35 CELERY_ON = False
35 CELERY_ON = False
36 CELERY_EAGER = False
36 CELERY_EAGER = False
37
37
38 # link to config for pylons
38 # link to config for pylons
39 CONFIG = {}
39 CONFIG = {}
40
40
41 # Linked module for extensions
41 # Linked module for extensions
42 EXTENSIONS = {}
42 EXTENSIONS = {}
43
43
44 try:
44 try:
45 from rhodecode.lib import get_current_revision
45 from rhodecode.lib import get_current_revision
46 _rev = get_current_revision(quiet=True)
46 _rev = get_current_revision(quiet=True)
47 if _rev and len(VERSION) > 3:
47 if _rev and len(VERSION) > 3:
48 VERSION += ('%s' % _rev[0],)
48 VERSION += ('%s' % _rev[0],)
49 except ImportError:
49 except ImportError:
50 pass
50 pass
51
51
52 __version__ = ('.'.join((str(each) for each in VERSION[:3])) +
52 __version__ = ('.'.join((str(each) for each in VERSION[:3])) +
53 '.'.join(VERSION[3:]))
53 '.'.join(VERSION[3:]))
54 __dbversion__ = 13 # defines current db version for migrations
54 __dbversion__ = 14 # defines current db version for migrations
55 __platform__ = platform.system()
55 __platform__ = platform.system()
56 __license__ = 'GPLv3'
56 __license__ = 'GPLv3'
57 __py_version__ = sys.version_info
57 __py_version__ = sys.version_info
58 __author__ = 'Marcin Kuzminski'
58 __author__ = 'Marcin Kuzminski'
59 __url__ = 'http://rhodecode.org'
59 __url__ = 'http://rhodecode.org'
60
60
61 is_windows = __platform__ in ['Windows']
61 is_windows = __platform__ in ['Windows']
62 is_unix = not is_windows
62 is_unix = not is_windows
@@ -1,713 +1,721 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """
2 """
3 rhodecode.lib.db_manage
3 rhodecode.lib.db_manage
4 ~~~~~~~~~~~~~~~~~~~~~~~
4 ~~~~~~~~~~~~~~~~~~~~~~~
5
5
6 Database creation, and setup module for RhodeCode. Used for creation
6 Database creation, and setup module for RhodeCode. Used for creation
7 of database as well as for migration operations
7 of database as well as for migration operations
8
8
9 :created_on: Apr 10, 2010
9 :created_on: Apr 10, 2010
10 :author: marcink
10 :author: marcink
11 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com>
11 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com>
12 :license: GPLv3, see COPYING for more details.
12 :license: GPLv3, see COPYING for more details.
13 """
13 """
14 # This program is free software: you can redistribute it and/or modify
14 # This program is free software: you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by
15 # it under the terms of the GNU General Public License as published by
16 # the Free Software Foundation, either version 3 of the License, or
16 # the Free Software Foundation, either version 3 of the License, or
17 # (at your option) any later version.
17 # (at your option) any later version.
18 #
18 #
19 # This program is distributed in the hope that it will be useful,
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
22 # GNU General Public License for more details.
23 #
23 #
24 # You should have received a copy of the GNU General Public License
24 # You should have received a copy of the GNU General Public License
25 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 # along with this program. If not, see <http://www.gnu.org/licenses/>.
26
26
27 import os
27 import os
28 import sys
28 import sys
29 import time
29 import time
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 import datetime
33
34
34 from rhodecode import __dbversion__, __py_version__
35 from rhodecode import __dbversion__, __py_version__
35
36
36 from rhodecode.model.user import UserModel
37 from rhodecode.model.user import UserModel
37 from rhodecode.lib.utils import ask_ok
38 from rhodecode.lib.utils import ask_ok
38 from rhodecode.model import init_model
39 from rhodecode.model import init_model
39 from rhodecode.model.db import User, Permission, RhodeCodeUi, \
40 from rhodecode.model.db import User, Permission, RhodeCodeUi, \
40 RhodeCodeSetting, UserToPerm, DbMigrateVersion, RepoGroup, \
41 RhodeCodeSetting, UserToPerm, DbMigrateVersion, RepoGroup, \
41 UserRepoGroupToPerm, CacheInvalidation, UserGroup
42 UserRepoGroupToPerm, CacheInvalidation, UserGroup
42
43
43 from sqlalchemy.engine import create_engine
44 from sqlalchemy.engine import create_engine
44 from rhodecode.model.repos_group import ReposGroupModel
45 from rhodecode.model.repos_group import ReposGroupModel
45 #from rhodecode.model import meta
46 #from rhodecode.model import meta
46 from rhodecode.model.meta import Session, Base
47 from rhodecode.model.meta import Session, Base
47 from rhodecode.model.repo import RepoModel
48 from rhodecode.model.repo import RepoModel
48 from rhodecode.model.permission import PermissionModel
49 from rhodecode.model.permission import PermissionModel
49 from rhodecode.model.users_group import UserGroupModel
50 from rhodecode.model.users_group import UserGroupModel
50
51
51
52
52 log = logging.getLogger(__name__)
53 log = logging.getLogger(__name__)
53
54
54
55
55 def notify(msg):
56 def notify(msg):
56 """
57 """
57 Notification for migrations messages
58 Notification for migrations messages
58 """
59 """
59 ml = len(msg) + (4 * 2)
60 ml = len(msg) + (4 * 2)
60 print('\n%s\n*** %s ***\n%s' % ('*' * ml, msg, '*' * ml)).upper()
61 print('\n%s\n*** %s ***\n%s' % ('*' * ml, msg, '*' * ml)).upper()
61
62
62
63
63 class UpgradeSteps(object):
64 class UpgradeSteps(object):
64 """
65 """
65 Those steps follow schema versions so for example schema
66 Those steps follow schema versions so for example schema
66 for example schema with seq 002 == step_2 and so on.
67 for example schema with seq 002 == step_2 and so on.
67 """
68 """
68
69
69 def __init__(self, klass):
70 def __init__(self, klass):
70 self.klass = klass
71 self.klass = klass
71
72
72 def step_1(self):
73 def step_1(self):
73 pass
74 pass
74
75
75 def step_2(self):
76 def step_2(self):
76 notify('Patching repo paths for newer version of RhodeCode')
77 notify('Patching repo paths for newer version of RhodeCode')
77 self.klass.fix_repo_paths()
78 self.klass.fix_repo_paths()
78
79
79 notify('Patching default user of RhodeCode')
80 notify('Patching default user of RhodeCode')
80 self.klass.fix_default_user()
81 self.klass.fix_default_user()
81
82
82 log.info('Changing ui settings')
83 log.info('Changing ui settings')
83 self.klass.create_ui_settings()
84 self.klass.create_ui_settings()
84
85
85 def step_3(self):
86 def step_3(self):
86 notify('Adding additional settings into RhodeCode db')
87 notify('Adding additional settings into RhodeCode db')
87 self.klass.fix_settings()
88 self.klass.fix_settings()
88 notify('Adding ldap defaults')
89 notify('Adding ldap defaults')
89 self.klass.create_ldap_options(skip_existing=True)
90 self.klass.create_ldap_options(skip_existing=True)
90
91
91 def step_4(self):
92 def step_4(self):
92 notify('create permissions and fix groups')
93 notify('create permissions and fix groups')
93 self.klass.create_permissions()
94 self.klass.create_permissions()
94 self.klass.fixup_groups()
95 self.klass.fixup_groups()
95
96
96 def step_5(self):
97 def step_5(self):
97 pass
98 pass
98
99
99 def step_6(self):
100 def step_6(self):
100
101
101 notify('re-checking permissions')
102 notify('re-checking permissions')
102 self.klass.create_permissions()
103 self.klass.create_permissions()
103
104
104 notify('installing new UI options')
105 notify('installing new UI options')
105 sett4 = RhodeCodeSetting('show_public_icon', True)
106 sett4 = RhodeCodeSetting('show_public_icon', True)
106 Session().add(sett4)
107 Session().add(sett4)
107 sett5 = RhodeCodeSetting('show_private_icon', True)
108 sett5 = RhodeCodeSetting('show_private_icon', True)
108 Session().add(sett5)
109 Session().add(sett5)
109 sett6 = RhodeCodeSetting('stylify_metatags', False)
110 sett6 = RhodeCodeSetting('stylify_metatags', False)
110 Session().add(sett6)
111 Session().add(sett6)
111
112
112 notify('fixing old PULL hook')
113 notify('fixing old PULL hook')
113 _pull = RhodeCodeUi.get_by_key('preoutgoing.pull_logger')
114 _pull = RhodeCodeUi.get_by_key('preoutgoing.pull_logger')
114 if _pull:
115 if _pull:
115 _pull.ui_key = RhodeCodeUi.HOOK_PULL
116 _pull.ui_key = RhodeCodeUi.HOOK_PULL
116 Session().add(_pull)
117 Session().add(_pull)
117
118
118 notify('fixing old PUSH hook')
119 notify('fixing old PUSH hook')
119 _push = RhodeCodeUi.get_by_key('pretxnchangegroup.push_logger')
120 _push = RhodeCodeUi.get_by_key('pretxnchangegroup.push_logger')
120 if _push:
121 if _push:
121 _push.ui_key = RhodeCodeUi.HOOK_PUSH
122 _push.ui_key = RhodeCodeUi.HOOK_PUSH
122 Session().add(_push)
123 Session().add(_push)
123
124
124 notify('installing new pre-push hook')
125 notify('installing new pre-push hook')
125 hooks4 = RhodeCodeUi()
126 hooks4 = RhodeCodeUi()
126 hooks4.ui_section = 'hooks'
127 hooks4.ui_section = 'hooks'
127 hooks4.ui_key = RhodeCodeUi.HOOK_PRE_PUSH
128 hooks4.ui_key = RhodeCodeUi.HOOK_PRE_PUSH
128 hooks4.ui_value = 'python:rhodecode.lib.hooks.pre_push'
129 hooks4.ui_value = 'python:rhodecode.lib.hooks.pre_push'
129 Session().add(hooks4)
130 Session().add(hooks4)
130
131
131 notify('installing new pre-pull hook')
132 notify('installing new pre-pull hook')
132 hooks6 = RhodeCodeUi()
133 hooks6 = RhodeCodeUi()
133 hooks6.ui_section = 'hooks'
134 hooks6.ui_section = 'hooks'
134 hooks6.ui_key = RhodeCodeUi.HOOK_PRE_PULL
135 hooks6.ui_key = RhodeCodeUi.HOOK_PRE_PULL
135 hooks6.ui_value = 'python:rhodecode.lib.hooks.pre_pull'
136 hooks6.ui_value = 'python:rhodecode.lib.hooks.pre_pull'
136 Session().add(hooks6)
137 Session().add(hooks6)
137
138
138 notify('installing hgsubversion option')
139 notify('installing hgsubversion option')
139 # enable hgsubversion disabled by default
140 # enable hgsubversion disabled by default
140 hgsubversion = RhodeCodeUi()
141 hgsubversion = RhodeCodeUi()
141 hgsubversion.ui_section = 'extensions'
142 hgsubversion.ui_section = 'extensions'
142 hgsubversion.ui_key = 'hgsubversion'
143 hgsubversion.ui_key = 'hgsubversion'
143 hgsubversion.ui_value = ''
144 hgsubversion.ui_value = ''
144 hgsubversion.ui_active = False
145 hgsubversion.ui_active = False
145 Session().add(hgsubversion)
146 Session().add(hgsubversion)
146
147
147 notify('installing hg git option')
148 notify('installing hg git option')
148 # enable hggit disabled by default
149 # enable hggit disabled by default
149 hggit = RhodeCodeUi()
150 hggit = RhodeCodeUi()
150 hggit.ui_section = 'extensions'
151 hggit.ui_section = 'extensions'
151 hggit.ui_key = 'hggit'
152 hggit.ui_key = 'hggit'
152 hggit.ui_value = ''
153 hggit.ui_value = ''
153 hggit.ui_active = False
154 hggit.ui_active = False
154 Session().add(hggit)
155 Session().add(hggit)
155
156
156 notify('re-check default permissions')
157 notify('re-check default permissions')
157 default_user = User.get_by_username(User.DEFAULT_USER)
158 default_user = User.get_by_username(User.DEFAULT_USER)
158 perm = Permission.get_by_key('hg.fork.repository')
159 perm = Permission.get_by_key('hg.fork.repository')
159 reg_perm = UserToPerm()
160 reg_perm = UserToPerm()
160 reg_perm.user = default_user
161 reg_perm.user = default_user
161 reg_perm.permission = perm
162 reg_perm.permission = perm
162 Session().add(reg_perm)
163 Session().add(reg_perm)
163
164
164 def step_7(self):
165 def step_7(self):
165 perm_fixes = self.klass.reset_permissions(User.DEFAULT_USER)
166 perm_fixes = self.klass.reset_permissions(User.DEFAULT_USER)
166 Session().commit()
167 Session().commit()
167 if perm_fixes:
168 if perm_fixes:
168 notify('There was an inconsistent state of permissions '
169 notify('There was an inconsistent state of permissions '
169 'detected for default user. Permissions are now '
170 'detected for default user. Permissions are now '
170 'reset to the default value for default user. '
171 'reset to the default value for default user. '
171 'Please validate and check default permissions '
172 'Please validate and check default permissions '
172 'in admin panel')
173 'in admin panel')
173
174
174 def step_8(self):
175 def step_8(self):
175 self.klass.create_permissions()
176 self.klass.create_permissions()
176 self.klass.populate_default_permissions()
177 self.klass.populate_default_permissions()
177 self.klass.create_default_options(skip_existing=True)
178 self.klass.create_default_options(skip_existing=True)
178 Session().commit()
179 Session().commit()
179
180
180 def step_9(self):
181 def step_9(self):
181 pass
182 pass
182
183
183 def step_10(self):
184 def step_10(self):
184 pass
185 pass
185
186
186 def step_11(self):
187 def step_11(self):
187 self.klass.update_repo_info()
188 self.klass.update_repo_info()
188
189
189 def step_12(self):
190 def step_12(self):
190 self.klass.create_permissions()
191 self.klass.create_permissions()
191 Session().commit()
192 Session().commit()
192
193
193 self.klass.populate_default_permissions()
194 self.klass.populate_default_permissions()
194 Session().commit()
195 Session().commit()
195
196
196 #fix all usergroups
197 #fix all usergroups
197 ug_model = UserGroupModel()
198 ug_model = UserGroupModel()
198 for ug in UserGroup.get_all():
199 for ug in UserGroup.get_all():
199 perm_obj = ug_model._create_default_perms(ug)
200 perm_obj = ug_model._create_default_perms(ug)
200 Session().add(perm_obj)
201 Session().add(perm_obj)
201 Session().commit()
202 Session().commit()
202
203
203 adm = User.get_first_admin()
204 adm = User.get_first_admin()
204 # fix owners of UserGroup
205 # fix owners of UserGroup
205 for ug in Session().query(UserGroup).all():
206 for ug in Session().query(UserGroup).all():
206 ug.user_id = adm.user_id
207 ug.user_id = adm.user_id
207 Session().add(ug)
208 Session().add(ug)
208 Session().commit()
209 Session().commit()
209
210
210 # fix owners of RepoGroup
211 # fix owners of RepoGroup
211 for ug in Session().query(RepoGroup).all():
212 for ug in Session().query(RepoGroup).all():
212 ug.user_id = adm.user_id
213 ug.user_id = adm.user_id
213 Session().add(ug)
214 Session().add(ug)
214 Session().commit()
215 Session().commit()
215
216
216 def step_13(self):
217 def step_13(self):
217 pass
218 pass
218
219
220 def step_14(self):
221 # fix nullable columns on last_update
222 for r in RepoModel().get_all():
223 if r.updated_on is None:
224 r.updated_on = datetime.datetime.fromtimestamp(0)
225 Session().add(r)
226 Session().commit()
219
227
220 class DbManage(object):
228 class DbManage(object):
221 def __init__(self, log_sql, dbconf, root, tests=False, cli_args={}):
229 def __init__(self, log_sql, dbconf, root, tests=False, cli_args={}):
222 self.dbname = dbconf.split('/')[-1]
230 self.dbname = dbconf.split('/')[-1]
223 self.tests = tests
231 self.tests = tests
224 self.root = root
232 self.root = root
225 self.dburi = dbconf
233 self.dburi = dbconf
226 self.log_sql = log_sql
234 self.log_sql = log_sql
227 self.db_exists = False
235 self.db_exists = False
228 self.cli_args = cli_args
236 self.cli_args = cli_args
229 self.init_db()
237 self.init_db()
230
238
231 force_ask = self.cli_args.get('force_ask')
239 force_ask = self.cli_args.get('force_ask')
232 if force_ask is not None:
240 if force_ask is not None:
233 global ask_ok
241 global ask_ok
234 ask_ok = lambda *args, **kwargs: force_ask
242 ask_ok = lambda *args, **kwargs: force_ask
235
243
236 def init_db(self):
244 def init_db(self):
237 engine = create_engine(self.dburi, echo=self.log_sql)
245 engine = create_engine(self.dburi, echo=self.log_sql)
238 init_model(engine)
246 init_model(engine)
239 self.sa = Session()
247 self.sa = Session()
240
248
241 def create_tables(self, override=False):
249 def create_tables(self, override=False):
242 """
250 """
243 Create a auth database
251 Create a auth database
244 """
252 """
245
253
246 log.info("Any existing database is going to be destroyed")
254 log.info("Any existing database is going to be destroyed")
247 if self.tests:
255 if self.tests:
248 destroy = True
256 destroy = True
249 else:
257 else:
250 destroy = ask_ok('Are you sure to destroy old database ? [y/n]')
258 destroy = ask_ok('Are you sure to destroy old database ? [y/n]')
251 if not destroy:
259 if not destroy:
252 sys.exit('Nothing tables created')
260 sys.exit('Nothing tables created')
253 if destroy:
261 if destroy:
254 Base.metadata.drop_all()
262 Base.metadata.drop_all()
255
263
256 checkfirst = not override
264 checkfirst = not override
257 Base.metadata.create_all(checkfirst=checkfirst)
265 Base.metadata.create_all(checkfirst=checkfirst)
258 log.info('Created tables for %s' % self.dbname)
266 log.info('Created tables for %s' % self.dbname)
259
267
260 def set_db_version(self):
268 def set_db_version(self):
261 ver = DbMigrateVersion()
269 ver = DbMigrateVersion()
262 ver.version = __dbversion__
270 ver.version = __dbversion__
263 ver.repository_id = 'rhodecode_db_migrations'
271 ver.repository_id = 'rhodecode_db_migrations'
264 ver.repository_path = 'versions'
272 ver.repository_path = 'versions'
265 self.sa.add(ver)
273 self.sa.add(ver)
266 log.info('db version set to: %s' % __dbversion__)
274 log.info('db version set to: %s' % __dbversion__)
267
275
268 def upgrade(self):
276 def upgrade(self):
269 """
277 """
270 Upgrades given database schema to given revision following
278 Upgrades given database schema to given revision following
271 all needed steps, to perform the upgrade
279 all needed steps, to perform the upgrade
272
280
273 """
281 """
274
282
275 from rhodecode.lib.dbmigrate.migrate.versioning import api
283 from rhodecode.lib.dbmigrate.migrate.versioning import api
276 from rhodecode.lib.dbmigrate.migrate.exceptions import \
284 from rhodecode.lib.dbmigrate.migrate.exceptions import \
277 DatabaseNotControlledError
285 DatabaseNotControlledError
278
286
279 if 'sqlite' in self.dburi:
287 if 'sqlite' in self.dburi:
280 print (
288 print (
281 '********************** WARNING **********************\n'
289 '********************** WARNING **********************\n'
282 'Make sure your version of sqlite is at least 3.7.X. \n'
290 'Make sure your version of sqlite is at least 3.7.X. \n'
283 'Earlier versions are known to fail on some migrations\n'
291 'Earlier versions are known to fail on some migrations\n'
284 '*****************************************************\n'
292 '*****************************************************\n'
285 )
293 )
286 upgrade = ask_ok('You are about to perform database upgrade, make '
294 upgrade = ask_ok('You are about to perform database upgrade, make '
287 'sure You backed up your database before. '
295 'sure You backed up your database before. '
288 'Continue ? [y/n]')
296 'Continue ? [y/n]')
289 if not upgrade:
297 if not upgrade:
290 sys.exit('No upgrade performed')
298 sys.exit('No upgrade performed')
291
299
292 repository_path = jn(dn(dn(dn(os.path.realpath(__file__)))),
300 repository_path = jn(dn(dn(dn(os.path.realpath(__file__)))),
293 'rhodecode/lib/dbmigrate')
301 'rhodecode/lib/dbmigrate')
294 db_uri = self.dburi
302 db_uri = self.dburi
295
303
296 try:
304 try:
297 curr_version = api.db_version(db_uri, repository_path)
305 curr_version = api.db_version(db_uri, repository_path)
298 msg = ('Found current database under version'
306 msg = ('Found current database under version'
299 ' control with version %s' % curr_version)
307 ' control with version %s' % curr_version)
300
308
301 except (RuntimeError, DatabaseNotControlledError):
309 except (RuntimeError, DatabaseNotControlledError):
302 curr_version = 1
310 curr_version = 1
303 msg = ('Current database is not under version control. Setting'
311 msg = ('Current database is not under version control. Setting'
304 ' as version %s' % curr_version)
312 ' as version %s' % curr_version)
305 api.version_control(db_uri, repository_path, curr_version)
313 api.version_control(db_uri, repository_path, curr_version)
306
314
307 notify(msg)
315 notify(msg)
308
316
309 if curr_version == __dbversion__:
317 if curr_version == __dbversion__:
310 sys.exit('This database is already at the newest version')
318 sys.exit('This database is already at the newest version')
311
319
312 # clear cache keys
320 # clear cache keys
313 log.info("Clearing cache keys now...")
321 log.info("Clearing cache keys now...")
314 CacheInvalidation.clear_cache()
322 CacheInvalidation.clear_cache()
315
323
316 upgrade_steps = range(curr_version + 1, __dbversion__ + 1)
324 upgrade_steps = range(curr_version + 1, __dbversion__ + 1)
317 notify('attempting to do database upgrade from '
325 notify('attempting to do database upgrade from '
318 'version %s to version %s' % (curr_version, __dbversion__))
326 'version %s to version %s' % (curr_version, __dbversion__))
319
327
320 # CALL THE PROPER ORDER OF STEPS TO PERFORM FULL UPGRADE
328 # CALL THE PROPER ORDER OF STEPS TO PERFORM FULL UPGRADE
321 _step = None
329 _step = None
322 for step in upgrade_steps:
330 for step in upgrade_steps:
323 notify('performing upgrade step %s' % step)
331 notify('performing upgrade step %s' % step)
324 time.sleep(2)
332 time.sleep(2)
325
333
326 api.upgrade(db_uri, repository_path, step)
334 api.upgrade(db_uri, repository_path, step)
327 notify('schema upgrade for step %s completed' % (step,))
335 notify('schema upgrade for step %s completed' % (step,))
328
336
329 fixture = 'step_%s' % step
337 fixture = 'step_%s' % step
330 notify('performing fixture step %s' % fixture)
338 notify('performing fixture step %s' % fixture)
331 getattr(UpgradeSteps(self), fixture)()
339 getattr(UpgradeSteps(self), fixture)()
332 self.sa.commit()
340 self.sa.commit()
333 notify('fixture %s completed' % (fixture,))
341 notify('fixture %s completed' % (fixture,))
334 _step = step
342 _step = step
335
343
336 notify('upgrade to version %s successful' % _step)
344 notify('upgrade to version %s successful' % _step)
337
345
338 def fix_repo_paths(self):
346 def fix_repo_paths(self):
339 """
347 """
340 Fixes a old rhodecode version path into new one without a '*'
348 Fixes a old rhodecode version path into new one without a '*'
341 """
349 """
342
350
343 paths = self.sa.query(RhodeCodeUi)\
351 paths = self.sa.query(RhodeCodeUi)\
344 .filter(RhodeCodeUi.ui_key == '/')\
352 .filter(RhodeCodeUi.ui_key == '/')\
345 .scalar()
353 .scalar()
346
354
347 paths.ui_value = paths.ui_value.replace('*', '')
355 paths.ui_value = paths.ui_value.replace('*', '')
348
356
349 try:
357 try:
350 self.sa.add(paths)
358 self.sa.add(paths)
351 self.sa.commit()
359 self.sa.commit()
352 except Exception:
360 except Exception:
353 self.sa.rollback()
361 self.sa.rollback()
354 raise
362 raise
355
363
356 def fix_default_user(self):
364 def fix_default_user(self):
357 """
365 """
358 Fixes a old default user with some 'nicer' default values,
366 Fixes a old default user with some 'nicer' default values,
359 used mostly for anonymous access
367 used mostly for anonymous access
360 """
368 """
361 def_user = self.sa.query(User)\
369 def_user = self.sa.query(User)\
362 .filter(User.username == 'default')\
370 .filter(User.username == 'default')\
363 .one()
371 .one()
364
372
365 def_user.name = 'Anonymous'
373 def_user.name = 'Anonymous'
366 def_user.lastname = 'User'
374 def_user.lastname = 'User'
367 def_user.email = 'anonymous@rhodecode.org'
375 def_user.email = 'anonymous@rhodecode.org'
368
376
369 try:
377 try:
370 self.sa.add(def_user)
378 self.sa.add(def_user)
371 self.sa.commit()
379 self.sa.commit()
372 except Exception:
380 except Exception:
373 self.sa.rollback()
381 self.sa.rollback()
374 raise
382 raise
375
383
376 def fix_settings(self):
384 def fix_settings(self):
377 """
385 """
378 Fixes rhodecode settings adds ga_code key for google analytics
386 Fixes rhodecode settings adds ga_code key for google analytics
379 """
387 """
380
388
381 hgsettings3 = RhodeCodeSetting('ga_code', '')
389 hgsettings3 = RhodeCodeSetting('ga_code', '')
382
390
383 try:
391 try:
384 self.sa.add(hgsettings3)
392 self.sa.add(hgsettings3)
385 self.sa.commit()
393 self.sa.commit()
386 except Exception:
394 except Exception:
387 self.sa.rollback()
395 self.sa.rollback()
388 raise
396 raise
389
397
390 def admin_prompt(self, second=False):
398 def admin_prompt(self, second=False):
391 if not self.tests:
399 if not self.tests:
392 import getpass
400 import getpass
393
401
394 # defaults
402 # defaults
395 defaults = self.cli_args
403 defaults = self.cli_args
396 username = defaults.get('username')
404 username = defaults.get('username')
397 password = defaults.get('password')
405 password = defaults.get('password')
398 email = defaults.get('email')
406 email = defaults.get('email')
399
407
400 def get_password():
408 def get_password():
401 password = getpass.getpass('Specify admin password '
409 password = getpass.getpass('Specify admin password '
402 '(min 6 chars):')
410 '(min 6 chars):')
403 confirm = getpass.getpass('Confirm password:')
411 confirm = getpass.getpass('Confirm password:')
404
412
405 if password != confirm:
413 if password != confirm:
406 log.error('passwords mismatch')
414 log.error('passwords mismatch')
407 return False
415 return False
408 if len(password) < 6:
416 if len(password) < 6:
409 log.error('password is to short use at least 6 characters')
417 log.error('password is to short use at least 6 characters')
410 return False
418 return False
411
419
412 return password
420 return password
413 if username is None:
421 if username is None:
414 username = raw_input('Specify admin username:')
422 username = raw_input('Specify admin username:')
415 if password is None:
423 if password is None:
416 password = get_password()
424 password = get_password()
417 if not password:
425 if not password:
418 #second try
426 #second try
419 password = get_password()
427 password = get_password()
420 if not password:
428 if not password:
421 sys.exit()
429 sys.exit()
422 if email is None:
430 if email is None:
423 email = raw_input('Specify admin email:')
431 email = raw_input('Specify admin email:')
424 self.create_user(username, password, email, True)
432 self.create_user(username, password, email, True)
425 else:
433 else:
426 log.info('creating admin and regular test users')
434 log.info('creating admin and regular test users')
427 from rhodecode.tests import TEST_USER_ADMIN_LOGIN, \
435 from rhodecode.tests import TEST_USER_ADMIN_LOGIN, \
428 TEST_USER_ADMIN_PASS, TEST_USER_ADMIN_EMAIL, \
436 TEST_USER_ADMIN_PASS, TEST_USER_ADMIN_EMAIL, \
429 TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS, \
437 TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS, \
430 TEST_USER_REGULAR_EMAIL, TEST_USER_REGULAR2_LOGIN, \
438 TEST_USER_REGULAR_EMAIL, TEST_USER_REGULAR2_LOGIN, \
431 TEST_USER_REGULAR2_PASS, TEST_USER_REGULAR2_EMAIL
439 TEST_USER_REGULAR2_PASS, TEST_USER_REGULAR2_EMAIL
432
440
433 self.create_user(TEST_USER_ADMIN_LOGIN, TEST_USER_ADMIN_PASS,
441 self.create_user(TEST_USER_ADMIN_LOGIN, TEST_USER_ADMIN_PASS,
434 TEST_USER_ADMIN_EMAIL, True)
442 TEST_USER_ADMIN_EMAIL, True)
435
443
436 self.create_user(TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS,
444 self.create_user(TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS,
437 TEST_USER_REGULAR_EMAIL, False)
445 TEST_USER_REGULAR_EMAIL, False)
438
446
439 self.create_user(TEST_USER_REGULAR2_LOGIN, TEST_USER_REGULAR2_PASS,
447 self.create_user(TEST_USER_REGULAR2_LOGIN, TEST_USER_REGULAR2_PASS,
440 TEST_USER_REGULAR2_EMAIL, False)
448 TEST_USER_REGULAR2_EMAIL, False)
441
449
442 def create_ui_settings(self):
450 def create_ui_settings(self):
443 """
451 """
444 Creates ui settings, fills out hooks
452 Creates ui settings, fills out hooks
445 and disables dotencode
453 and disables dotencode
446 """
454 """
447
455
448 #HOOKS
456 #HOOKS
449 hooks1_key = RhodeCodeUi.HOOK_UPDATE
457 hooks1_key = RhodeCodeUi.HOOK_UPDATE
450 hooks1_ = self.sa.query(RhodeCodeUi)\
458 hooks1_ = self.sa.query(RhodeCodeUi)\
451 .filter(RhodeCodeUi.ui_key == hooks1_key).scalar()
459 .filter(RhodeCodeUi.ui_key == hooks1_key).scalar()
452
460
453 hooks1 = RhodeCodeUi() if hooks1_ is None else hooks1_
461 hooks1 = RhodeCodeUi() if hooks1_ is None else hooks1_
454 hooks1.ui_section = 'hooks'
462 hooks1.ui_section = 'hooks'
455 hooks1.ui_key = hooks1_key
463 hooks1.ui_key = hooks1_key
456 hooks1.ui_value = 'hg update >&2'
464 hooks1.ui_value = 'hg update >&2'
457 hooks1.ui_active = False
465 hooks1.ui_active = False
458 self.sa.add(hooks1)
466 self.sa.add(hooks1)
459
467
460 hooks2_key = RhodeCodeUi.HOOK_REPO_SIZE
468 hooks2_key = RhodeCodeUi.HOOK_REPO_SIZE
461 hooks2_ = self.sa.query(RhodeCodeUi)\
469 hooks2_ = self.sa.query(RhodeCodeUi)\
462 .filter(RhodeCodeUi.ui_key == hooks2_key).scalar()
470 .filter(RhodeCodeUi.ui_key == hooks2_key).scalar()
463 hooks2 = RhodeCodeUi() if hooks2_ is None else hooks2_
471 hooks2 = RhodeCodeUi() if hooks2_ is None else hooks2_
464 hooks2.ui_section = 'hooks'
472 hooks2.ui_section = 'hooks'
465 hooks2.ui_key = hooks2_key
473 hooks2.ui_key = hooks2_key
466 hooks2.ui_value = 'python:rhodecode.lib.hooks.repo_size'
474 hooks2.ui_value = 'python:rhodecode.lib.hooks.repo_size'
467 self.sa.add(hooks2)
475 self.sa.add(hooks2)
468
476
469 hooks3 = RhodeCodeUi()
477 hooks3 = RhodeCodeUi()
470 hooks3.ui_section = 'hooks'
478 hooks3.ui_section = 'hooks'
471 hooks3.ui_key = RhodeCodeUi.HOOK_PUSH
479 hooks3.ui_key = RhodeCodeUi.HOOK_PUSH
472 hooks3.ui_value = 'python:rhodecode.lib.hooks.log_push_action'
480 hooks3.ui_value = 'python:rhodecode.lib.hooks.log_push_action'
473 self.sa.add(hooks3)
481 self.sa.add(hooks3)
474
482
475 hooks4 = RhodeCodeUi()
483 hooks4 = RhodeCodeUi()
476 hooks4.ui_section = 'hooks'
484 hooks4.ui_section = 'hooks'
477 hooks4.ui_key = RhodeCodeUi.HOOK_PRE_PUSH
485 hooks4.ui_key = RhodeCodeUi.HOOK_PRE_PUSH
478 hooks4.ui_value = 'python:rhodecode.lib.hooks.pre_push'
486 hooks4.ui_value = 'python:rhodecode.lib.hooks.pre_push'
479 self.sa.add(hooks4)
487 self.sa.add(hooks4)
480
488
481 hooks5 = RhodeCodeUi()
489 hooks5 = RhodeCodeUi()
482 hooks5.ui_section = 'hooks'
490 hooks5.ui_section = 'hooks'
483 hooks5.ui_key = RhodeCodeUi.HOOK_PULL
491 hooks5.ui_key = RhodeCodeUi.HOOK_PULL
484 hooks5.ui_value = 'python:rhodecode.lib.hooks.log_pull_action'
492 hooks5.ui_value = 'python:rhodecode.lib.hooks.log_pull_action'
485 self.sa.add(hooks5)
493 self.sa.add(hooks5)
486
494
487 hooks6 = RhodeCodeUi()
495 hooks6 = RhodeCodeUi()
488 hooks6.ui_section = 'hooks'
496 hooks6.ui_section = 'hooks'
489 hooks6.ui_key = RhodeCodeUi.HOOK_PRE_PULL
497 hooks6.ui_key = RhodeCodeUi.HOOK_PRE_PULL
490 hooks6.ui_value = 'python:rhodecode.lib.hooks.pre_pull'
498 hooks6.ui_value = 'python:rhodecode.lib.hooks.pre_pull'
491 self.sa.add(hooks6)
499 self.sa.add(hooks6)
492
500
493 # enable largefiles
501 # enable largefiles
494 largefiles = RhodeCodeUi()
502 largefiles = RhodeCodeUi()
495 largefiles.ui_section = 'extensions'
503 largefiles.ui_section = 'extensions'
496 largefiles.ui_key = 'largefiles'
504 largefiles.ui_key = 'largefiles'
497 largefiles.ui_value = ''
505 largefiles.ui_value = ''
498 self.sa.add(largefiles)
506 self.sa.add(largefiles)
499
507
500 # enable hgsubversion disabled by default
508 # enable hgsubversion disabled by default
501 hgsubversion = RhodeCodeUi()
509 hgsubversion = RhodeCodeUi()
502 hgsubversion.ui_section = 'extensions'
510 hgsubversion.ui_section = 'extensions'
503 hgsubversion.ui_key = 'hgsubversion'
511 hgsubversion.ui_key = 'hgsubversion'
504 hgsubversion.ui_value = ''
512 hgsubversion.ui_value = ''
505 hgsubversion.ui_active = False
513 hgsubversion.ui_active = False
506 self.sa.add(hgsubversion)
514 self.sa.add(hgsubversion)
507
515
508 # enable hggit disabled by default
516 # enable hggit disabled by default
509 hggit = RhodeCodeUi()
517 hggit = RhodeCodeUi()
510 hggit.ui_section = 'extensions'
518 hggit.ui_section = 'extensions'
511 hggit.ui_key = 'hggit'
519 hggit.ui_key = 'hggit'
512 hggit.ui_value = ''
520 hggit.ui_value = ''
513 hggit.ui_active = False
521 hggit.ui_active = False
514 self.sa.add(hggit)
522 self.sa.add(hggit)
515
523
516 def create_ldap_options(self, skip_existing=False):
524 def create_ldap_options(self, skip_existing=False):
517 """Creates ldap settings"""
525 """Creates ldap settings"""
518
526
519 for k, v in [('ldap_active', 'false'), ('ldap_host', ''),
527 for k, v in [('ldap_active', 'false'), ('ldap_host', ''),
520 ('ldap_port', '389'), ('ldap_tls_kind', 'PLAIN'),
528 ('ldap_port', '389'), ('ldap_tls_kind', 'PLAIN'),
521 ('ldap_tls_reqcert', ''), ('ldap_dn_user', ''),
529 ('ldap_tls_reqcert', ''), ('ldap_dn_user', ''),
522 ('ldap_dn_pass', ''), ('ldap_base_dn', ''),
530 ('ldap_dn_pass', ''), ('ldap_base_dn', ''),
523 ('ldap_filter', ''), ('ldap_search_scope', ''),
531 ('ldap_filter', ''), ('ldap_search_scope', ''),
524 ('ldap_attr_login', ''), ('ldap_attr_firstname', ''),
532 ('ldap_attr_login', ''), ('ldap_attr_firstname', ''),
525 ('ldap_attr_lastname', ''), ('ldap_attr_email', '')]:
533 ('ldap_attr_lastname', ''), ('ldap_attr_email', '')]:
526
534
527 if skip_existing and RhodeCodeSetting.get_by_name(k) is not None:
535 if skip_existing and RhodeCodeSetting.get_by_name(k) is not None:
528 log.debug('Skipping option %s' % k)
536 log.debug('Skipping option %s' % k)
529 continue
537 continue
530 setting = RhodeCodeSetting(k, v)
538 setting = RhodeCodeSetting(k, v)
531 self.sa.add(setting)
539 self.sa.add(setting)
532
540
533 def create_default_options(self, skip_existing=False):
541 def create_default_options(self, skip_existing=False):
534 """Creates default settings"""
542 """Creates default settings"""
535
543
536 for k, v in [
544 for k, v in [
537 ('default_repo_enable_locking', False),
545 ('default_repo_enable_locking', False),
538 ('default_repo_enable_downloads', False),
546 ('default_repo_enable_downloads', False),
539 ('default_repo_enable_statistics', False),
547 ('default_repo_enable_statistics', False),
540 ('default_repo_private', False),
548 ('default_repo_private', False),
541 ('default_repo_type', 'hg')]:
549 ('default_repo_type', 'hg')]:
542
550
543 if skip_existing and RhodeCodeSetting.get_by_name(k) is not None:
551 if skip_existing and RhodeCodeSetting.get_by_name(k) is not None:
544 log.debug('Skipping option %s' % k)
552 log.debug('Skipping option %s' % k)
545 continue
553 continue
546 setting = RhodeCodeSetting(k, v)
554 setting = RhodeCodeSetting(k, v)
547 self.sa.add(setting)
555 self.sa.add(setting)
548
556
549 def fixup_groups(self):
557 def fixup_groups(self):
550 def_usr = User.get_default_user()
558 def_usr = User.get_default_user()
551 for g in RepoGroup.query().all():
559 for g in RepoGroup.query().all():
552 g.group_name = g.get_new_name(g.name)
560 g.group_name = g.get_new_name(g.name)
553 self.sa.add(g)
561 self.sa.add(g)
554 # get default perm
562 # get default perm
555 default = UserRepoGroupToPerm.query()\
563 default = UserRepoGroupToPerm.query()\
556 .filter(UserRepoGroupToPerm.group == g)\
564 .filter(UserRepoGroupToPerm.group == g)\
557 .filter(UserRepoGroupToPerm.user == def_usr)\
565 .filter(UserRepoGroupToPerm.user == def_usr)\
558 .scalar()
566 .scalar()
559
567
560 if default is None:
568 if default is None:
561 log.debug('missing default permission for group %s adding' % g)
569 log.debug('missing default permission for group %s adding' % g)
562 perm_obj = ReposGroupModel()._create_default_perms(g)
570 perm_obj = ReposGroupModel()._create_default_perms(g)
563 self.sa.add(perm_obj)
571 self.sa.add(perm_obj)
564
572
565 def reset_permissions(self, username):
573 def reset_permissions(self, username):
566 """
574 """
567 Resets permissions to default state, usefull when old systems had
575 Resets permissions to default state, usefull when old systems had
568 bad permissions, we must clean them up
576 bad permissions, we must clean them up
569
577
570 :param username:
578 :param username:
571 """
579 """
572 default_user = User.get_by_username(username)
580 default_user = User.get_by_username(username)
573 if not default_user:
581 if not default_user:
574 return
582 return
575
583
576 u2p = UserToPerm.query()\
584 u2p = UserToPerm.query()\
577 .filter(UserToPerm.user == default_user).all()
585 .filter(UserToPerm.user == default_user).all()
578 fixed = False
586 fixed = False
579 if len(u2p) != len(Permission.DEFAULT_USER_PERMISSIONS):
587 if len(u2p) != len(Permission.DEFAULT_USER_PERMISSIONS):
580 for p in u2p:
588 for p in u2p:
581 Session().delete(p)
589 Session().delete(p)
582 fixed = True
590 fixed = True
583 self.populate_default_permissions()
591 self.populate_default_permissions()
584 return fixed
592 return fixed
585
593
586 def update_repo_info(self):
594 def update_repo_info(self):
587 RepoModel.update_repoinfo()
595 RepoModel.update_repoinfo()
588
596
589 def config_prompt(self, test_repo_path='', retries=3):
597 def config_prompt(self, test_repo_path='', retries=3):
590 defaults = self.cli_args
598 defaults = self.cli_args
591 _path = defaults.get('repos_location')
599 _path = defaults.get('repos_location')
592 if retries == 3:
600 if retries == 3:
593 log.info('Setting up repositories config')
601 log.info('Setting up repositories config')
594
602
595 if _path is not None:
603 if _path is not None:
596 path = _path
604 path = _path
597 elif not self.tests and not test_repo_path:
605 elif not self.tests and not test_repo_path:
598 path = raw_input(
606 path = raw_input(
599 'Enter a valid absolute path to store repositories. '
607 'Enter a valid absolute path to store repositories. '
600 'All repositories in that path will be added automatically:'
608 'All repositories in that path will be added automatically:'
601 )
609 )
602 else:
610 else:
603 path = test_repo_path
611 path = test_repo_path
604 path_ok = True
612 path_ok = True
605
613
606 # check proper dir
614 # check proper dir
607 if not os.path.isdir(path):
615 if not os.path.isdir(path):
608 path_ok = False
616 path_ok = False
609 log.error('Given path %s is not a valid directory' % path)
617 log.error('Given path %s is not a valid directory' % path)
610
618
611 elif not os.path.isabs(path):
619 elif not os.path.isabs(path):
612 path_ok = False
620 path_ok = False
613 log.error('Given path %s is not an absolute path' % path)
621 log.error('Given path %s is not an absolute path' % path)
614
622
615 # check write access
623 # check write access
616 elif not os.access(path, os.W_OK) and path_ok:
624 elif not os.access(path, os.W_OK) and path_ok:
617 path_ok = False
625 path_ok = False
618 log.error('No write permission to given path %s' % path)
626 log.error('No write permission to given path %s' % path)
619
627
620 if retries == 0:
628 if retries == 0:
621 sys.exit('max retries reached')
629 sys.exit('max retries reached')
622 if not path_ok:
630 if not path_ok:
623 retries -= 1
631 retries -= 1
624 return self.config_prompt(test_repo_path, retries)
632 return self.config_prompt(test_repo_path, retries)
625
633
626 real_path = os.path.normpath(os.path.realpath(path))
634 real_path = os.path.normpath(os.path.realpath(path))
627
635
628 if real_path != os.path.normpath(path):
636 if real_path != os.path.normpath(path):
629 if not ask_ok(('Path looks like a symlink, Rhodecode will store '
637 if not ask_ok(('Path looks like a symlink, Rhodecode will store '
630 'given path as %s ? [y/n]') % (real_path)):
638 'given path as %s ? [y/n]') % (real_path)):
631 log.error('Canceled by user')
639 log.error('Canceled by user')
632 sys.exit(-1)
640 sys.exit(-1)
633
641
634 return real_path
642 return real_path
635
643
636 def create_settings(self, path):
644 def create_settings(self, path):
637
645
638 self.create_ui_settings()
646 self.create_ui_settings()
639
647
640 ui_config = [
648 ui_config = [
641 ('web', 'push_ssl', 'false'),
649 ('web', 'push_ssl', 'false'),
642 ('web', 'allow_archive', 'gz zip bz2'),
650 ('web', 'allow_archive', 'gz zip bz2'),
643 ('web', 'allow_push', '*'),
651 ('web', 'allow_push', '*'),
644 ('web', 'baseurl', '/'),
652 ('web', 'baseurl', '/'),
645 ('paths', '/', path),
653 ('paths', '/', path),
646 #('phases', 'publish', 'false')
654 #('phases', 'publish', 'false')
647 ]
655 ]
648 for section, key, value in ui_config:
656 for section, key, value in ui_config:
649 ui_conf = RhodeCodeUi()
657 ui_conf = RhodeCodeUi()
650 setattr(ui_conf, 'ui_section', section)
658 setattr(ui_conf, 'ui_section', section)
651 setattr(ui_conf, 'ui_key', key)
659 setattr(ui_conf, 'ui_key', key)
652 setattr(ui_conf, 'ui_value', value)
660 setattr(ui_conf, 'ui_value', value)
653 self.sa.add(ui_conf)
661 self.sa.add(ui_conf)
654
662
655 settings = [
663 settings = [
656 ('realm', 'RhodeCode authentication', unicode),
664 ('realm', 'RhodeCode authentication', unicode),
657 ('title', 'RhodeCode', unicode),
665 ('title', 'RhodeCode', unicode),
658 ('ga_code', '', unicode),
666 ('ga_code', '', unicode),
659 ('show_public_icon', True, bool),
667 ('show_public_icon', True, bool),
660 ('show_private_icon', True, bool),
668 ('show_private_icon', True, bool),
661 ('stylify_metatags', False, bool),
669 ('stylify_metatags', False, bool),
662 ('dashboard_items', 100, int),
670 ('dashboard_items', 100, int),
663 ('show_version', True, bool)
671 ('show_version', True, bool)
664 ]
672 ]
665 for key, val, type_ in settings:
673 for key, val, type_ in settings:
666 sett = RhodeCodeSetting(key, val)
674 sett = RhodeCodeSetting(key, val)
667 self.sa.add(sett)
675 self.sa.add(sett)
668
676
669 self.create_ldap_options()
677 self.create_ldap_options()
670 self.create_default_options()
678 self.create_default_options()
671
679
672 log.info('created ui config')
680 log.info('created ui config')
673
681
674 def create_user(self, username, password, email='', admin=False):
682 def create_user(self, username, password, email='', admin=False):
675 log.info('creating user %s' % username)
683 log.info('creating user %s' % username)
676 UserModel().create_or_update(username, password, email,
684 UserModel().create_or_update(username, password, email,
677 firstname='RhodeCode', lastname='Admin',
685 firstname='RhodeCode', lastname='Admin',
678 active=True, admin=admin)
686 active=True, admin=admin)
679
687
680 def create_default_user(self):
688 def create_default_user(self):
681 log.info('creating default user')
689 log.info('creating default user')
682 # create default user for handling default permissions.
690 # create default user for handling default permissions.
683 UserModel().create_or_update(username='default',
691 UserModel().create_or_update(username='default',
684 password=str(uuid.uuid1())[:8],
692 password=str(uuid.uuid1())[:8],
685 email='anonymous@rhodecode.org',
693 email='anonymous@rhodecode.org',
686 firstname='Anonymous', lastname='User')
694 firstname='Anonymous', lastname='User')
687
695
688 def create_permissions(self):
696 def create_permissions(self):
689 """
697 """
690 Creates all permissions defined in the system
698 Creates all permissions defined in the system
691 """
699 """
692 # module.(access|create|change|delete)_[name]
700 # module.(access|create|change|delete)_[name]
693 # module.(none|read|write|admin)
701 # module.(none|read|write|admin)
694 log.info('creating permissions')
702 log.info('creating permissions')
695 PermissionModel(self.sa).create_permissions()
703 PermissionModel(self.sa).create_permissions()
696
704
697 def populate_default_permissions(self):
705 def populate_default_permissions(self):
698 """
706 """
699 Populate default permissions. It will create only the default
707 Populate default permissions. It will create only the default
700 permissions that are missing, and not alter already defined ones
708 permissions that are missing, and not alter already defined ones
701 """
709 """
702 log.info('creating default user permissions')
710 log.info('creating default user permissions')
703 PermissionModel(self.sa).create_default_permissions(user=User.DEFAULT_USER)
711 PermissionModel(self.sa).create_default_permissions(user=User.DEFAULT_USER)
704
712
705 @staticmethod
713 @staticmethod
706 def check_waitress():
714 def check_waitress():
707 """
715 """
708 Function executed at the end of setup
716 Function executed at the end of setup
709 """
717 """
710 if not __py_version__ >= (2, 6):
718 if not __py_version__ >= (2, 6):
711 notify('Python2.5 detected, please switch '
719 notify('Python2.5 detected, please switch '
712 'egg:waitress#main -> egg:Paste#http '
720 'egg:waitress#main -> egg:Paste#http '
713 'in your .ini file')
721 'in your .ini file')
General Comments 0
You need to be logged in to leave comments. Login now