annotate rhodecode/lib/db_manage.py @ 858:508b3976345e beta

bumped development version
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 18 Dec 2010 15:03:18 +0100
parents 3b21ba5f7cb0
children 042d38683d42 af6ca51fb80f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
835
08d2dcd71666 fixed imports on migrate, added getting current version from database
Marcin Kuzminski <marcin@python-works.com>
parents: 834
diff changeset
1 # -*- coding: utf-8 -*-
08d2dcd71666 fixed imports on migrate, added getting current version from database
Marcin Kuzminski <marcin@python-works.com>
parents: 834
diff changeset
2 """
08d2dcd71666 fixed imports on migrate, added getting current version from database
Marcin Kuzminski <marcin@python-works.com>
parents: 834
diff changeset
3 rhodecode.lib.db_manage
08d2dcd71666 fixed imports on migrate, added getting current version from database
Marcin Kuzminski <marcin@python-works.com>
parents: 834
diff changeset
4 ~~~~~~~~~~~~~~~~~~~~~~~
08d2dcd71666 fixed imports on migrate, added getting current version from database
Marcin Kuzminski <marcin@python-works.com>
parents: 834
diff changeset
5
838
12eb1a018199 db migrations:
Marcin Kuzminski <marcin@python-works.com>
parents: 837
diff changeset
6 Database creation, and setup module for RhodeCode. Used for creation
12eb1a018199 db migrations:
Marcin Kuzminski <marcin@python-works.com>
parents: 837
diff changeset
7 of database as well as for migration operations
835
08d2dcd71666 fixed imports on migrate, added getting current version from database
Marcin Kuzminski <marcin@python-works.com>
parents: 834
diff changeset
8
08d2dcd71666 fixed imports on migrate, added getting current version from database
Marcin Kuzminski <marcin@python-works.com>
parents: 834
diff changeset
9 :created_on: Apr 10, 2010
08d2dcd71666 fixed imports on migrate, added getting current version from database
Marcin Kuzminski <marcin@python-works.com>
parents: 834
diff changeset
10 :author: marcink
08d2dcd71666 fixed imports on migrate, added getting current version from database
Marcin Kuzminski <marcin@python-works.com>
parents: 834
diff changeset
11 :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
08d2dcd71666 fixed imports on migrate, added getting current version from database
Marcin Kuzminski <marcin@python-works.com>
parents: 834
diff changeset
12 :license: GPLv3, see COPYING for more details.
08d2dcd71666 fixed imports on migrate, added getting current version from database
Marcin Kuzminski <marcin@python-works.com>
parents: 834
diff changeset
13 """
252
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 249
diff changeset
14 # This program is free software; you can redistribute it and/or
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 249
diff changeset
15 # modify it under the terms of the GNU General Public License
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 249
diff changeset
16 # as published by the Free Software Foundation; version 2
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 249
diff changeset
17 # of the License or (at your opinion) any later version of the license.
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 249
diff changeset
18 #
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 249
diff changeset
19 # This program is distributed in the hope that it will be useful,
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 249
diff changeset
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 249
diff changeset
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 249
diff changeset
22 # GNU General Public License for more details.
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 249
diff changeset
23 #
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 249
diff changeset
24 # You should have received a copy of the GNU General Public License
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 249
diff changeset
25 # along with this program; if not, write to the Free Software
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 249
diff changeset
26 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 249
diff changeset
27 # MA 02110-1301, USA.
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 249
diff changeset
28
249
bad9ccac26b7 fixed import errors on db_manage
Marcin Kuzminski <marcin@python-works.com>
parents: 243
diff changeset
29 import os
bad9ccac26b7 fixed import errors on db_manage
Marcin Kuzminski <marcin@python-works.com>
parents: 243
diff changeset
30 import sys
327
0e87466a117e updated installation instruction, made more user friendly way of creating all needed configs. All is done now from paster setup-app
Marcin Kuzminski <marcin@python-works.com>
parents: 307
diff changeset
31 import uuid
835
08d2dcd71666 fixed imports on migrate, added getting current version from database
Marcin Kuzminski <marcin@python-works.com>
parents: 834
diff changeset
32 import logging
08d2dcd71666 fixed imports on migrate, added getting current version from database
Marcin Kuzminski <marcin@python-works.com>
parents: 834
diff changeset
33 from os.path import dirname as dn, join as jn
08d2dcd71666 fixed imports on migrate, added getting current version from database
Marcin Kuzminski <marcin@python-works.com>
parents: 834
diff changeset
34
08d2dcd71666 fixed imports on migrate, added getting current version from database
Marcin Kuzminski <marcin@python-works.com>
parents: 834
diff changeset
35 from rhodecode import __dbversion__
08d2dcd71666 fixed imports on migrate, added getting current version from database
Marcin Kuzminski <marcin@python-works.com>
parents: 834
diff changeset
36 from rhodecode.model import meta
249
bad9ccac26b7 fixed import errors on db_manage
Marcin Kuzminski <marcin@python-works.com>
parents: 243
diff changeset
37
547
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
38 from rhodecode.lib.auth import get_crypt_password
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
39 from rhodecode.lib.utils import ask_ok
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
40 from rhodecode.model import init_model
549
f99075170eb4 more renames for rhode code !!
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
41 from rhodecode.model.db import User, Permission, RhodeCodeUi, RhodeCodeSettings, \
835
08d2dcd71666 fixed imports on migrate, added getting current version from database
Marcin Kuzminski <marcin@python-works.com>
parents: 834
diff changeset
42 UserToPerm, DbMigrateVersion
08d2dcd71666 fixed imports on migrate, added getting current version from database
Marcin Kuzminski <marcin@python-works.com>
parents: 834
diff changeset
43
239
b18f89d6d17f Adde draft for permissions systems, made all needed decorators, and checks. For future usage in the system.
Marcin Kuzminski <marcin@python-works.com>
parents: 234
diff changeset
44 from sqlalchemy.engine import create_engine
835
08d2dcd71666 fixed imports on migrate, added getting current version from database
Marcin Kuzminski <marcin@python-works.com>
parents: 834
diff changeset
45
351
d09381593b12 updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents: 350
diff changeset
46 log = logging.getLogger(__name__)
66
163464441e0d updated db manage script for creating interactive admin account and db
Marcin Kuzminski <marcin@python-blog.com>
parents: 59
diff changeset
47
226
c6526b7531e9 rewritten db manage script to use sqlalchemy. Fixed sqlalchemy models to more generic.
Marcin Kuzminski <marcin@python-works.com>
parents: 88
diff changeset
48 class DbManage(object):
781
7ae66bddf48d fixed db manage, to work on other databases than sqlite
Marcin Kuzminski <marcin@python-works.com>
parents: 773
diff changeset
49 def __init__(self, log_sql, dbconf, root, tests=False):
7ae66bddf48d fixed db manage, to work on other databases than sqlite
Marcin Kuzminski <marcin@python-works.com>
parents: 773
diff changeset
50 self.dbname = dbconf.split('/')[-1]
459
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
51 self.tests = tests
552
2642f128ad46 removed egg info, update files for distutils build
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
52 self.root = root
781
7ae66bddf48d fixed db manage, to work on other databases than sqlite
Marcin Kuzminski <marcin@python-works.com>
parents: 773
diff changeset
53 self.dburi = dbconf
7ae66bddf48d fixed db manage, to work on other databases than sqlite
Marcin Kuzminski <marcin@python-works.com>
parents: 773
diff changeset
54 engine = create_engine(self.dburi, echo=log_sql)
226
c6526b7531e9 rewritten db manage script to use sqlalchemy. Fixed sqlalchemy models to more generic.
Marcin Kuzminski <marcin@python-works.com>
parents: 88
diff changeset
55 init_model(engine)
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
56 self.sa = meta.Session()
243
9d64df490248 fixed bug when there was no dbfile, and dbmanage raise an exception
Marcin Kuzminski <marcin@python-works.com>
parents: 240
diff changeset
57 self.db_exists = False
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
58
226
c6526b7531e9 rewritten db manage script to use sqlalchemy. Fixed sqlalchemy models to more generic.
Marcin Kuzminski <marcin@python-works.com>
parents: 88
diff changeset
59 def check_for_db(self, override):
552
2642f128ad46 removed egg info, update files for distutils build
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
60 db_path = jn(self.root, self.dbname)
781
7ae66bddf48d fixed db manage, to work on other databases than sqlite
Marcin Kuzminski <marcin@python-works.com>
parents: 773
diff changeset
61 if self.dburi.startswith('sqlite'):
7ae66bddf48d fixed db manage, to work on other databases than sqlite
Marcin Kuzminski <marcin@python-works.com>
parents: 773
diff changeset
62 log.info('checking for existing db in %s', db_path)
7ae66bddf48d fixed db manage, to work on other databases than sqlite
Marcin Kuzminski <marcin@python-works.com>
parents: 773
diff changeset
63 if os.path.isfile(db_path):
7ae66bddf48d fixed db manage, to work on other databases than sqlite
Marcin Kuzminski <marcin@python-works.com>
parents: 773
diff changeset
64
7ae66bddf48d fixed db manage, to work on other databases than sqlite
Marcin Kuzminski <marcin@python-works.com>
parents: 773
diff changeset
65 self.db_exists = True
7ae66bddf48d fixed db manage, to work on other databases than sqlite
Marcin Kuzminski <marcin@python-works.com>
parents: 773
diff changeset
66 if not override:
7ae66bddf48d fixed db manage, to work on other databases than sqlite
Marcin Kuzminski <marcin@python-works.com>
parents: 773
diff changeset
67 raise Exception('database already exists')
229
69a29242ba61 db manage added more logging, set custom logger and add optional print sql statments
Marcin Kuzminski <marcin@python-works.com>
parents: 228
diff changeset
68
226
c6526b7531e9 rewritten db manage script to use sqlalchemy. Fixed sqlalchemy models to more generic.
Marcin Kuzminski <marcin@python-works.com>
parents: 88
diff changeset
69 def create_tables(self, override=False):
837
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
70 """Create a auth database
226
c6526b7531e9 rewritten db manage script to use sqlalchemy. Fixed sqlalchemy models to more generic.
Marcin Kuzminski <marcin@python-works.com>
parents: 88
diff changeset
71 """
837
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
72
226
c6526b7531e9 rewritten db manage script to use sqlalchemy. Fixed sqlalchemy models to more generic.
Marcin Kuzminski <marcin@python-works.com>
parents: 88
diff changeset
73 self.check_for_db(override)
597
53128b6b9a4d added password validation, second try on paster setup-app,
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
74 if self.db_exists:
552
2642f128ad46 removed egg info, update files for distutils build
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
75 log.info("database exist and it's going to be destroyed")
459
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
76 if self.tests:
491
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 471
diff changeset
77 destroy = True
459
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
78 else:
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
79 destroy = ask_ok('Are you sure to destroy old database ? [y/n]')
351
d09381593b12 updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents: 350
diff changeset
80 if not destroy:
d09381593b12 updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents: 350
diff changeset
81 sys.exit()
d09381593b12 updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents: 350
diff changeset
82 if self.db_exists and destroy:
552
2642f128ad46 removed egg info, update files for distutils build
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
83 os.remove(jn(self.root, self.dbname))
351
d09381593b12 updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents: 350
diff changeset
84 checkfirst = not override
d09381593b12 updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents: 350
diff changeset
85 meta.Base.metadata.create_all(checkfirst=checkfirst)
229
69a29242ba61 db manage added more logging, set custom logger and add optional print sql statments
Marcin Kuzminski <marcin@python-works.com>
parents: 228
diff changeset
86 log.info('Created tables for %s', self.dbname)
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
87
834
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 781
diff changeset
88
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 781
diff changeset
89
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 781
diff changeset
90 def set_db_version(self):
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 781
diff changeset
91 try:
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 781
diff changeset
92 ver = DbMigrateVersion()
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 781
diff changeset
93 ver.version = __dbversion__
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 781
diff changeset
94 ver.repository_id = 'rhodecode_db_migrations'
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 781
diff changeset
95 ver.repository_path = 'versions'
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 781
diff changeset
96 self.sa.add(ver)
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 781
diff changeset
97 self.sa.commit()
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 781
diff changeset
98 except:
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 781
diff changeset
99 self.sa.rollback()
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 781
diff changeset
100 raise
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 781
diff changeset
101 log.info('db version set to: %s', __dbversion__)
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 781
diff changeset
102
839
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
103
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
104 def upgrade(self):
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
105 """Upgrades given database schema to given revision following
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
106 all needed steps,
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
107
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
108 :param revision: revision to upgrade to
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
109 """
841
78b3d2d730f2 fixed import problems
Marcin Kuzminski <marcin@python-works.com>
parents: 839
diff changeset
110
78b3d2d730f2 fixed import problems
Marcin Kuzminski <marcin@python-works.com>
parents: 839
diff changeset
111 from rhodecode.lib.dbmigrate.migrate.versioning import api
78b3d2d730f2 fixed import problems
Marcin Kuzminski <marcin@python-works.com>
parents: 839
diff changeset
112 from rhodecode.lib.dbmigrate.migrate.exceptions import \
78b3d2d730f2 fixed import problems
Marcin Kuzminski <marcin@python-works.com>
parents: 839
diff changeset
113 DatabaseNotControlledError
78b3d2d730f2 fixed import problems
Marcin Kuzminski <marcin@python-works.com>
parents: 839
diff changeset
114
839
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
115 upgrade = ask_ok('You are about to perform database upgrade, make '
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
116 'sure You backed up your database before. '
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
117 'Continue ? [y/n]')
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
118 if not upgrade:
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
119 sys.exit('Nothing done')
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
120
843
3b21ba5f7cb0 fixed path issues in upgrade script
Marcin Kuzminski <marcin@python-works.com>
parents: 841
diff changeset
121 repository_path = jn(dn(dn(dn(os.path.realpath(__file__)))),
3b21ba5f7cb0 fixed path issues in upgrade script
Marcin Kuzminski <marcin@python-works.com>
parents: 841
diff changeset
122 'rhodecode/lib/dbmigrate')
839
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
123 db_uri = self.dburi
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
124
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
125 try:
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
126 curr_version = api.db_version(db_uri, repository_path)
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
127 msg = ('Found current database under version'
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
128 ' control with version %s' % curr_version)
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
129
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
130 except (RuntimeError, DatabaseNotControlledError), e:
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
131 curr_version = 1
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
132 msg = ('Current database is not under version control. Setting'
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
133 ' as version %s' % curr_version)
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
134 api.version_control(db_uri, repository_path, curr_version)
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
135
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
136 print (msg)
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
137
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
138 if curr_version == __dbversion__:
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
139 sys.exit('This database is already at the newest version')
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
140
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
141 #======================================================================
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
142 # UPGRADE STEPS
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
143 #======================================================================
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
144 class UpgradeSteps(object):
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
145
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
146 def __init__(self, klass):
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
147 self.klass = klass
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
148
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
149 def step_0(self):
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
150 #step 0 is the schema upgrade, and than follow proper upgrades
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
151 print ('attempting to do database upgrade to version %s' \
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
152 % __dbversion__)
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
153 api.upgrade(db_uri, repository_path, __dbversion__)
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
154 print ('Schema upgrade completed')
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
155
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
156 def step_1(self):
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
157 pass
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
158
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
159 def step_2(self):
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
160 print ('Patching repo paths for newer version of RhodeCode')
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
161 self.klass.fix_repo_paths()
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
162
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
163 print ('Patching default user of RhodeCode')
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
164 self.klass.fix_default_user()
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
165
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
166 log.info('Changing ui settings')
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
167 self.klass.create_ui_settings()
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
168
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
169
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
170 upgrade_steps = [0] + range(curr_version + 1, __dbversion__ + 1)
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
171
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
172 #CALL THE PROPER ORDER OF STEPS TO PERFORM FULL UPGRADE
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
173 for step in upgrade_steps:
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
174 print ('performing upgrade step %s' % step)
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
175 callable = getattr(UpgradeSteps(self), 'step_%s' % step)()
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
176
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
177
ad66bd0e5601 moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents: 838
diff changeset
178
837
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
179 def fix_repo_paths(self):
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
180 """Fixes a old rhodecode version path into new one without a '*'
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
181 """
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
182
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
183 paths = self.sa.query(RhodeCodeUi)\
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
184 .filter(RhodeCodeUi.ui_key == '/')\
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
185 .scalar()
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
186
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
187 paths.ui_value = paths.ui_value.replace('*', '')
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
188
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
189 try:
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
190 self.sa.add(paths)
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
191 self.sa.commit()
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
192 except:
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
193 self.sa.rollback()
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
194 raise
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
195
838
12eb1a018199 db migrations:
Marcin Kuzminski <marcin@python-works.com>
parents: 837
diff changeset
196 def fix_default_user(self):
12eb1a018199 db migrations:
Marcin Kuzminski <marcin@python-works.com>
parents: 837
diff changeset
197 """Fixes a old default user with some 'nicer' default values,
12eb1a018199 db migrations:
Marcin Kuzminski <marcin@python-works.com>
parents: 837
diff changeset
198 used mostly for anonymous access
12eb1a018199 db migrations:
Marcin Kuzminski <marcin@python-works.com>
parents: 837
diff changeset
199 """
12eb1a018199 db migrations:
Marcin Kuzminski <marcin@python-works.com>
parents: 837
diff changeset
200 def_user = self.sa.query(User)\
12eb1a018199 db migrations:
Marcin Kuzminski <marcin@python-works.com>
parents: 837
diff changeset
201 .filter(User.username == 'default')\
12eb1a018199 db migrations:
Marcin Kuzminski <marcin@python-works.com>
parents: 837
diff changeset
202 .one()
12eb1a018199 db migrations:
Marcin Kuzminski <marcin@python-works.com>
parents: 837
diff changeset
203
12eb1a018199 db migrations:
Marcin Kuzminski <marcin@python-works.com>
parents: 837
diff changeset
204 def_user.name = 'Anonymous'
12eb1a018199 db migrations:
Marcin Kuzminski <marcin@python-works.com>
parents: 837
diff changeset
205 def_user.lastname = 'User'
12eb1a018199 db migrations:
Marcin Kuzminski <marcin@python-works.com>
parents: 837
diff changeset
206 def_user.email = 'anonymous@rhodecode.org'
12eb1a018199 db migrations:
Marcin Kuzminski <marcin@python-works.com>
parents: 837
diff changeset
207
12eb1a018199 db migrations:
Marcin Kuzminski <marcin@python-works.com>
parents: 837
diff changeset
208 try:
12eb1a018199 db migrations:
Marcin Kuzminski <marcin@python-works.com>
parents: 837
diff changeset
209 self.sa.add(def_user)
12eb1a018199 db migrations:
Marcin Kuzminski <marcin@python-works.com>
parents: 837
diff changeset
210 self.sa.commit()
12eb1a018199 db migrations:
Marcin Kuzminski <marcin@python-works.com>
parents: 837
diff changeset
211 except:
12eb1a018199 db migrations:
Marcin Kuzminski <marcin@python-works.com>
parents: 837
diff changeset
212 self.sa.rollback()
12eb1a018199 db migrations:
Marcin Kuzminski <marcin@python-works.com>
parents: 837
diff changeset
213 raise
12eb1a018199 db migrations:
Marcin Kuzminski <marcin@python-works.com>
parents: 837
diff changeset
214
837
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
215
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
216
597
53128b6b9a4d added password validation, second try on paster setup-app,
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
217 def admin_prompt(self, second=False):
459
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
218 if not self.tests:
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
219 import getpass
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
220
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
221
597
53128b6b9a4d added password validation, second try on paster setup-app,
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
222 def get_password():
53128b6b9a4d added password validation, second try on paster setup-app,
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
223 password = getpass.getpass('Specify admin password (min 6 chars):')
53128b6b9a4d added password validation, second try on paster setup-app,
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
224 confirm = getpass.getpass('Confirm password:')
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
225
597
53128b6b9a4d added password validation, second try on paster setup-app,
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
226 if password != confirm:
53128b6b9a4d added password validation, second try on paster setup-app,
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
227 log.error('passwords mismatch')
53128b6b9a4d added password validation, second try on paster setup-app,
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
228 return False
53128b6b9a4d added password validation, second try on paster setup-app,
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
229 if len(password) < 6:
53128b6b9a4d added password validation, second try on paster setup-app,
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
230 log.error('password is to short use at least 6 characters')
53128b6b9a4d added password validation, second try on paster setup-app,
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
231 return False
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
232
597
53128b6b9a4d added password validation, second try on paster setup-app,
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
233 return password
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
234
459
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
235 username = raw_input('Specify admin username:')
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
236
597
53128b6b9a4d added password validation, second try on paster setup-app,
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
237 password = get_password()
53128b6b9a4d added password validation, second try on paster setup-app,
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
238 if not password:
53128b6b9a4d added password validation, second try on paster setup-app,
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
239 #second try
53128b6b9a4d added password validation, second try on paster setup-app,
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
240 password = get_password()
53128b6b9a4d added password validation, second try on paster setup-app,
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
241 if not password:
53128b6b9a4d added password validation, second try on paster setup-app,
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
242 sys.exit()
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
243
491
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 471
diff changeset
244 email = raw_input('Specify admin email:')
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 471
diff changeset
245 self.create_user(username, password, email, True)
459
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
246 else:
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
247 log.info('creating admin and regular test users')
533
53aa1ee1af86 updated tests for new version 6char password etc...
Marcin Kuzminski <marcin@python-works.com>
parents: 491
diff changeset
248 self.create_user('test_admin', 'test12', 'test_admin@mail.com', True)
53aa1ee1af86 updated tests for new version 6char password etc...
Marcin Kuzminski <marcin@python-works.com>
parents: 491
diff changeset
249 self.create_user('test_regular', 'test12', 'test_regular@mail.com', False)
53aa1ee1af86 updated tests for new version 6char password etc...
Marcin Kuzminski <marcin@python-works.com>
parents: 491
diff changeset
250 self.create_user('test_regular2', 'test12', 'test_regular2@mail.com', False)
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
251
837
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
252 def create_ui_settings(self):
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
253 """Creates ui settings, fills out hooks
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
254 and disables dotencode
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
255
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
256 """
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
257 #HOOKS
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
258 hooks1_key = 'changegroup.update'
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
259 hooks1_ = self.sa.query(RhodeCodeUi)\
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
260 .filter(RhodeCodeUi.ui_key == hooks1_key).scalar()
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
261
837
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
262 hooks1 = RhodeCodeUi() if hooks1_ is None else hooks1_
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
263 hooks1.ui_section = 'hooks'
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
264 hooks1.ui_key = hooks1_key
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
265 hooks1.ui_value = 'hg update >&2'
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
266 hooks1.ui_active = False
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
267
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
268 hooks2_key = 'changegroup.repo_size'
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
269 hooks2_ = self.sa.query(RhodeCodeUi)\
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
270 .filter(RhodeCodeUi.ui_key == hooks2_key).scalar()
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
271
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
272 hooks2 = RhodeCodeUi() if hooks2_ is None else hooks2_
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
273 hooks2.ui_section = 'hooks'
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
274 hooks2.ui_key = hooks2_key
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
275 hooks2.ui_value = 'python:rhodecode.lib.hooks.repo_size'
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
276
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
277 hooks3 = RhodeCodeUi()
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
278 hooks3.ui_section = 'hooks'
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
279 hooks3.ui_key = 'pretxnchangegroup.push_logger'
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
280 hooks3.ui_value = 'python:rhodecode.lib.hooks.log_push_action'
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
281
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
282 hooks4 = RhodeCodeUi()
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
283 hooks4.ui_section = 'hooks'
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
284 hooks4.ui_key = 'preoutgoing.pull_logger'
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
285 hooks4.ui_value = 'python:rhodecode.lib.hooks.log_pull_action'
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
286
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
287 #For mercurial 1.7 set backward comapatibility with format
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
288 dotencode_disable = RhodeCodeUi()
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
289 dotencode_disable.ui_section = 'format'
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
290 dotencode_disable.ui_key = 'dotencode'
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
291 dotencode_disable.ui_value = 'false'
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
292
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
293 try:
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
294 self.sa.add(hooks1)
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
295 self.sa.add(hooks2)
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
296 self.sa.add(hooks3)
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
297 self.sa.add(hooks4)
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
298 self.sa.add(dotencode_disable)
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
299 self.sa.commit()
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
300 except:
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
301 self.sa.rollback()
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
302 raise
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
303
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
304
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
305 def create_ldap_options(self):
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
306 """Creates ldap settings"""
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
307
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
308 try:
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
309 for k in ['ldap_active', 'ldap_host', 'ldap_port', 'ldap_ldaps',
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
310 'ldap_dn_user', 'ldap_dn_pass', 'ldap_base_dn']:
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
311
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
312 setting = RhodeCodeSettings(k, '')
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
313 self.sa.add(setting)
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
314 self.sa.commit()
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
315 except:
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
316 self.sa.rollback()
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
317 raise
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
318
491
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 471
diff changeset
319 def config_prompt(self, test_repo_path=''):
345
bb8f45f6d8f9 updated hg-app db manage and global settings
Marcin Kuzminski <marcin@python-works.com>
parents: 341
diff changeset
320 log.info('Setting up repositories config')
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
321
459
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
322 if not self.tests and not test_repo_path:
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
323 path = raw_input('Specify valid full path to your repositories'
351
d09381593b12 updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents: 350
diff changeset
324 ' you can change this later in application settings:')
459
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
325 else:
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
326 path = test_repo_path
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
327
341
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 327
diff changeset
328 if not os.path.isdir(path):
491
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 471
diff changeset
329 log.error('You entered wrong path: %s', path)
341
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 327
diff changeset
330 sys.exit()
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
331
837
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
332 self.create_ui_settings()
673
dd532af216d9 #49 Enabled anonymous access for web interface controllable from permissions pannel
Marcin Kuzminski <marcin@python-works.com>
parents: 657
diff changeset
333
837
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
334 #HG UI OPTIONS
549
f99075170eb4 more renames for rhode code !!
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
335 web1 = RhodeCodeUi()
341
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 327
diff changeset
336 web1.ui_section = 'web'
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 327
diff changeset
337 web1.ui_key = 'push_ssl'
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 327
diff changeset
338 web1.ui_value = 'false'
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
339
549
f99075170eb4 more renames for rhode code !!
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
340 web2 = RhodeCodeUi()
341
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 327
diff changeset
341 web2.ui_section = 'web'
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 327
diff changeset
342 web2.ui_key = 'allow_archive'
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 327
diff changeset
343 web2.ui_value = 'gz zip bz2'
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
344
549
f99075170eb4 more renames for rhode code !!
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
345 web3 = RhodeCodeUi()
341
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 327
diff changeset
346 web3.ui_section = 'web'
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 327
diff changeset
347 web3.ui_key = 'allow_push'
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 327
diff changeset
348 web3.ui_value = '*'
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
349
549
f99075170eb4 more renames for rhode code !!
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
350 web4 = RhodeCodeUi()
341
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 327
diff changeset
351 web4.ui_section = 'web'
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 327
diff changeset
352 web4.ui_key = 'baseurl'
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
353 web4.ui_value = '/'
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
354
549
f99075170eb4 more renames for rhode code !!
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
355 paths = RhodeCodeUi()
341
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 327
diff changeset
356 paths.ui_section = 'paths'
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 327
diff changeset
357 paths.ui_key = '/'
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
358 paths.ui_value = path
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
359
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
360
704
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents: 673
diff changeset
361 hgsettings1 = RhodeCodeSettings('realm', 'RhodeCode authentication')
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents: 673
diff changeset
362 hgsettings2 = RhodeCodeSettings('title', 'RhodeCode')
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
363
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
364
341
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 327
diff changeset
365 try:
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 327
diff changeset
366 self.sa.add(web1)
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 327
diff changeset
367 self.sa.add(web2)
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 327
diff changeset
368 self.sa.add(web3)
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 327
diff changeset
369 self.sa.add(web4)
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 327
diff changeset
370 self.sa.add(paths)
381
55377fdc1fc6 cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents: 371
diff changeset
371 self.sa.add(hgsettings1)
55377fdc1fc6 cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents: 371
diff changeset
372 self.sa.add(hgsettings2)
704
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents: 673
diff changeset
373
341
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 327
diff changeset
374 self.sa.commit()
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 327
diff changeset
375 except:
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 327
diff changeset
376 self.sa.rollback()
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
377 raise
837
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
378
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
379 self.create_ldap_options()
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 835
diff changeset
380
341
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 327
diff changeset
381 log.info('created ui config')
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
382
491
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 471
diff changeset
383 def create_user(self, username, password, email='', admin=False):
229
69a29242ba61 db manage added more logging, set custom logger and add optional print sql statments
Marcin Kuzminski <marcin@python-works.com>
parents: 228
diff changeset
384 log.info('creating administrator user %s', username)
234
a0116e944da1 changed naming convention for db modules.
Marcin Kuzminski <marcin@python-works.com>
parents: 229
diff changeset
385 new_user = User()
226
c6526b7531e9 rewritten db manage script to use sqlalchemy. Fixed sqlalchemy models to more generic.
Marcin Kuzminski <marcin@python-works.com>
parents: 88
diff changeset
386 new_user.username = username
c6526b7531e9 rewritten db manage script to use sqlalchemy. Fixed sqlalchemy models to more generic.
Marcin Kuzminski <marcin@python-works.com>
parents: 88
diff changeset
387 new_user.password = get_crypt_password(password)
555
03676d39dd0a added fault tolerant case when celeryconfig is not present in the directory.
Marcin Kuzminski <marcin@python-works.com>
parents: 552
diff changeset
388 new_user.name = 'RhodeCode'
262
a4be1ebb214f updated db manage with some defaults
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
389 new_user.lastname = 'Admin'
491
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 471
diff changeset
390 new_user.email = email
226
c6526b7531e9 rewritten db manage script to use sqlalchemy. Fixed sqlalchemy models to more generic.
Marcin Kuzminski <marcin@python-works.com>
parents: 88
diff changeset
391 new_user.admin = admin
c6526b7531e9 rewritten db manage script to use sqlalchemy. Fixed sqlalchemy models to more generic.
Marcin Kuzminski <marcin@python-works.com>
parents: 88
diff changeset
392 new_user.active = True
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
393
226
c6526b7531e9 rewritten db manage script to use sqlalchemy. Fixed sqlalchemy models to more generic.
Marcin Kuzminski <marcin@python-works.com>
parents: 88
diff changeset
394 try:
459
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
395 self.sa.add(new_user)
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
396 self.sa.commit()
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
397 except:
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
398 self.sa.rollback()
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
399 raise
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
400
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
401 def create_default_user(self):
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
402 log.info('creating default user')
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
403 #create default user for handling default permissions.
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
404 def_user = User()
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
405 def_user.username = 'default'
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
406 def_user.password = get_crypt_password(str(uuid.uuid1())[:8])
673
dd532af216d9 #49 Enabled anonymous access for web interface controllable from permissions pannel
Marcin Kuzminski <marcin@python-works.com>
parents: 657
diff changeset
407 def_user.name = 'Anonymous'
dd532af216d9 #49 Enabled anonymous access for web interface controllable from permissions pannel
Marcin Kuzminski <marcin@python-works.com>
parents: 657
diff changeset
408 def_user.lastname = 'User'
dd532af216d9 #49 Enabled anonymous access for web interface controllable from permissions pannel
Marcin Kuzminski <marcin@python-works.com>
parents: 657
diff changeset
409 def_user.email = 'anonymous@rhodecode.org'
459
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
410 def_user.admin = False
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
411 def_user.active = False
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
412 try:
341
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 327
diff changeset
413 self.sa.add(def_user)
226
c6526b7531e9 rewritten db manage script to use sqlalchemy. Fixed sqlalchemy models to more generic.
Marcin Kuzminski <marcin@python-works.com>
parents: 88
diff changeset
414 self.sa.commit()
c6526b7531e9 rewritten db manage script to use sqlalchemy. Fixed sqlalchemy models to more generic.
Marcin Kuzminski <marcin@python-works.com>
parents: 88
diff changeset
415 except:
c6526b7531e9 rewritten db manage script to use sqlalchemy. Fixed sqlalchemy models to more generic.
Marcin Kuzminski <marcin@python-works.com>
parents: 88
diff changeset
416 self.sa.rollback()
c6526b7531e9 rewritten db manage script to use sqlalchemy. Fixed sqlalchemy models to more generic.
Marcin Kuzminski <marcin@python-works.com>
parents: 88
diff changeset
417 raise
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
418
239
b18f89d6d17f Adde draft for permissions systems, made all needed decorators, and checks. For future usage in the system.
Marcin Kuzminski <marcin@python-works.com>
parents: 234
diff changeset
419 def create_permissions(self):
240
7c4fa2a66195 small fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 239
diff changeset
420 #module.(access|create|change|delete)_[name]
296
29370bb76fa6 first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents: 264
diff changeset
421 #module.(read|write|owner)
29370bb76fa6 first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents: 264
diff changeset
422 perms = [('repository.none', 'Repository no access'),
29370bb76fa6 first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents: 264
diff changeset
423 ('repository.read', 'Repository read access'),
29370bb76fa6 first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents: 264
diff changeset
424 ('repository.write', 'Repository write access'),
29370bb76fa6 first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents: 264
diff changeset
425 ('repository.admin', 'Repository admin access'),
307
504feff57b49 added permission functions to webhelpers, updated dbmanage permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 296
diff changeset
426 ('hg.admin', 'Hg Administrator'),
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
427 ('hg.create.repository', 'Repository create'),
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
428 ('hg.create.none', 'Repository creation disabled'),
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
429 ('hg.register.none', 'Register disabled'),
549
f99075170eb4 more renames for rhode code !!
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
430 ('hg.register.manual_activate', 'Register new user with rhodecode without manual activation'),
f99075170eb4 more renames for rhode code !!
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
431 ('hg.register.auto_activate', 'Register new user with rhodecode without auto activation'),
371
5cd6616b8673 routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents: 367
diff changeset
432 ]
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
433
239
b18f89d6d17f Adde draft for permissions systems, made all needed decorators, and checks. For future usage in the system.
Marcin Kuzminski <marcin@python-works.com>
parents: 234
diff changeset
434 for p in perms:
b18f89d6d17f Adde draft for permissions systems, made all needed decorators, and checks. For future usage in the system.
Marcin Kuzminski <marcin@python-works.com>
parents: 234
diff changeset
435 new_perm = Permission()
b18f89d6d17f Adde draft for permissions systems, made all needed decorators, and checks. For future usage in the system.
Marcin Kuzminski <marcin@python-works.com>
parents: 234
diff changeset
436 new_perm.permission_name = p[0]
b18f89d6d17f Adde draft for permissions systems, made all needed decorators, and checks. For future usage in the system.
Marcin Kuzminski <marcin@python-works.com>
parents: 234
diff changeset
437 new_perm.permission_longname = p[1]
b18f89d6d17f Adde draft for permissions systems, made all needed decorators, and checks. For future usage in the system.
Marcin Kuzminski <marcin@python-works.com>
parents: 234
diff changeset
438 try:
b18f89d6d17f Adde draft for permissions systems, made all needed decorators, and checks. For future usage in the system.
Marcin Kuzminski <marcin@python-works.com>
parents: 234
diff changeset
439 self.sa.add(new_perm)
b18f89d6d17f Adde draft for permissions systems, made all needed decorators, and checks. For future usage in the system.
Marcin Kuzminski <marcin@python-works.com>
parents: 234
diff changeset
440 self.sa.commit()
b18f89d6d17f Adde draft for permissions systems, made all needed decorators, and checks. For future usage in the system.
Marcin Kuzminski <marcin@python-works.com>
parents: 234
diff changeset
441 except:
b18f89d6d17f Adde draft for permissions systems, made all needed decorators, and checks. For future usage in the system.
Marcin Kuzminski <marcin@python-works.com>
parents: 234
diff changeset
442 self.sa.rollback()
b18f89d6d17f Adde draft for permissions systems, made all needed decorators, and checks. For future usage in the system.
Marcin Kuzminski <marcin@python-works.com>
parents: 234
diff changeset
443 raise
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
444
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
445 def populate_default_permissions(self):
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
446 log.info('creating default user permissions')
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
447
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
448 default_user = self.sa.query(User)\
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
449 .filter(User.username == 'default').scalar()
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
450
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
451 reg_perm = UserToPerm()
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
452 reg_perm.user = default_user
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
453 reg_perm.permission = self.sa.query(Permission)\
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
454 .filter(Permission.permission_name == 'hg.register.manual_activate')\
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
455 .scalar()
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
456
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
457 create_repo_perm = UserToPerm()
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
458 create_repo_perm.user = default_user
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
459 create_repo_perm.permission = self.sa.query(Permission)\
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
460 .filter(Permission.permission_name == 'hg.create.repository')\
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
461 .scalar()
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
462
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
463 default_repo_perm = UserToPerm()
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
464 default_repo_perm.user = default_user
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
465 default_repo_perm.permission = self.sa.query(Permission)\
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
466 .filter(Permission.permission_name == 'repository.read')\
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
467 .scalar()
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
468
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
469 try:
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
470 self.sa.add(reg_perm)
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
471 self.sa.add(create_repo_perm)
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
472 self.sa.add(default_repo_perm)
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
473 self.sa.commit()
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
474 except:
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
475 self.sa.rollback()
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
476 raise
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
477