annotate rhodecode/lib/db_manage.py @ 834:8924ed0e4f36 beta

added current db version into rhodecode, added auto versioning of newly created databases
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 11 Dec 2010 02:15:29 +0100
parents 7ae66bddf48d
children 08d2dcd71666
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
252
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 249
diff changeset
1 #!/usr/bin/env python
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 249
diff changeset
2 # encoding: utf-8
569
000b675e7c1d bumped version, some spelling fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 560
diff changeset
3 # database management for RhodeCode
252
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 249
diff changeset
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
351
d09381593b12 updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents: 350
diff changeset
5 #
252
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 249
diff changeset
6 # 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
7 # 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
8 # as published by the Free Software Foundation; version 2
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 249
diff changeset
9 # 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
10 #
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 249
diff changeset
11 # 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
12 # 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
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 249
diff changeset
14 # GNU General Public License for more details.
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 249
diff changeset
15 #
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 249
diff changeset
16 # 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
17 # 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
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 249
diff changeset
19 # MA 02110-1301, USA.
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 249
diff changeset
20
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 249
diff changeset
21 """
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 249
diff changeset
22 Created on April 10, 2010
569
000b675e7c1d bumped version, some spelling fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 560
diff changeset
23 database management and creation for RhodeCode
252
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 249
diff changeset
24 @author: marcink
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 249
diff changeset
25 """
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 249
diff changeset
26
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
27 from os.path import dirname as dn, join as jn
249
bad9ccac26b7 fixed import errors on db_manage
Marcin Kuzminski <marcin@python-works.com>
parents: 243
diff changeset
28 import os
bad9ccac26b7 fixed import errors on db_manage
Marcin Kuzminski <marcin@python-works.com>
parents: 243
diff changeset
29 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
30 import uuid
249
bad9ccac26b7 fixed import errors on db_manage
Marcin Kuzminski <marcin@python-works.com>
parents: 243
diff changeset
31
547
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
32 from rhodecode.lib.auth import get_crypt_password
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
33 from rhodecode.lib.utils import ask_ok
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
34 from rhodecode.model import init_model
549
f99075170eb4 more renames for rhode code !!
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
35 from rhodecode.model.db import User, Permission, RhodeCodeUi, RhodeCodeSettings, \
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
36 UserToPerm
547
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
37 from rhodecode.model import meta
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
38 from sqlalchemy.engine import create_engine
59
736078908f37 added db_manage script
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
39 import logging
736078908f37 added db_manage script
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
40
351
d09381593b12 updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents: 350
diff changeset
41 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
42
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
43 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
44 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
45 self.dbname = dbconf.split('/')[-1]
459
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
46 self.tests = tests
552
2642f128ad46 removed egg info, update files for distutils build
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
47 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
48 self.dburi = dbconf
7ae66bddf48d fixed db manage, to work on other databases than sqlite
Marcin Kuzminski <marcin@python-works.com>
parents: 773
diff changeset
49 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
50 init_model(engine)
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
51 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
52 self.db_exists = False
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
53
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
54 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
55 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
56 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
57 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
58 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
59
7ae66bddf48d fixed db manage, to work on other databases than sqlite
Marcin Kuzminski <marcin@python-works.com>
parents: 773
diff changeset
60 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
61 if not override:
7ae66bddf48d fixed db manage, to work on other databases than sqlite
Marcin Kuzminski <marcin@python-works.com>
parents: 773
diff changeset
62 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
63
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
64 def create_tables(self, override=False):
c6526b7531e9 rewritten db manage script to use sqlalchemy. Fixed sqlalchemy models to more generic.
Marcin Kuzminski <marcin@python-works.com>
parents: 88
diff changeset
65 """
c6526b7531e9 rewritten db manage script to use sqlalchemy. Fixed sqlalchemy models to more generic.
Marcin Kuzminski <marcin@python-works.com>
parents: 88
diff changeset
66 Create a auth database
c6526b7531e9 rewritten db manage script to use sqlalchemy. Fixed sqlalchemy models to more generic.
Marcin Kuzminski <marcin@python-works.com>
parents: 88
diff changeset
67 """
c6526b7531e9 rewritten db manage script to use sqlalchemy. Fixed sqlalchemy models to more generic.
Marcin Kuzminski <marcin@python-works.com>
parents: 88
diff changeset
68 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
69 if self.db_exists:
552
2642f128ad46 removed egg info, update files for distutils build
Marcin Kuzminski <marcin@python-works.com>
parents: 549
diff changeset
70 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
71 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
72 destroy = True
459
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
73 else:
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
74 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
75 if not destroy:
d09381593b12 updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents: 350
diff changeset
76 sys.exit()
d09381593b12 updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents: 350
diff changeset
77 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
78 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
79 checkfirst = not override
d09381593b12 updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents: 350
diff changeset
80 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
81 log.info('Created tables for %s', self.dbname)
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
82
834
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 781
diff changeset
83
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 781
diff changeset
84
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 781
diff changeset
85 def set_db_version(self):
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 781
diff changeset
86 from rhodecode import __dbversion__
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 781
diff changeset
87 from rhodecode.model.db import DbMigrateVersion
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 781
diff changeset
88 try:
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 781
diff changeset
89 ver = DbMigrateVersion()
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 781
diff changeset
90 ver.version = __dbversion__
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 781
diff changeset
91 ver.repository_id = 'rhodecode_db_migrations'
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 781
diff changeset
92 ver.repository_path = 'versions'
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 781
diff changeset
93 self.sa.add(ver)
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 781
diff changeset
94 self.sa.commit()
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 781
diff changeset
95 except:
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 781
diff changeset
96 self.sa.rollback()
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 781
diff changeset
97 raise
8924ed0e4f36 added current db version into rhodecode,
Marcin Kuzminski <marcin@python-works.com>
parents: 781
diff changeset
98 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
99
597
53128b6b9a4d added password validation, second try on paster setup-app,
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
100 def admin_prompt(self, second=False):
459
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
101 if not self.tests:
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
102 import getpass
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
103
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
104
597
53128b6b9a4d added password validation, second try on paster setup-app,
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
105 def get_password():
53128b6b9a4d added password validation, second try on paster setup-app,
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
106 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
107 confirm = getpass.getpass('Confirm password:')
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
108
597
53128b6b9a4d added password validation, second try on paster setup-app,
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
109 if password != confirm:
53128b6b9a4d added password validation, second try on paster setup-app,
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
110 log.error('passwords mismatch')
53128b6b9a4d added password validation, second try on paster setup-app,
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
111 return False
53128b6b9a4d added password validation, second try on paster setup-app,
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
112 if len(password) < 6:
53128b6b9a4d added password validation, second try on paster setup-app,
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
113 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
114 return False
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
115
597
53128b6b9a4d added password validation, second try on paster setup-app,
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
116 return password
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
117
459
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
118 username = raw_input('Specify admin username:')
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
119
597
53128b6b9a4d added password validation, second try on paster setup-app,
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
120 password = get_password()
53128b6b9a4d added password validation, second try on paster setup-app,
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
121 if not password:
53128b6b9a4d added password validation, second try on paster setup-app,
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
122 #second try
53128b6b9a4d added password validation, second try on paster setup-app,
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
123 password = get_password()
53128b6b9a4d added password validation, second try on paster setup-app,
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
124 if not password:
53128b6b9a4d added password validation, second try on paster setup-app,
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
125 sys.exit()
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
126
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
127 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
128 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
129 else:
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
130 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
131 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
132 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
133 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
134
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
135
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
136
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
137 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
138 log.info('Setting up repositories config')
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
139
459
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
140 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
141 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
142 ' 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
143 else:
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
144 path = test_repo_path
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
145
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
146 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
147 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
148 sys.exit()
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
149
549
f99075170eb4 more renames for rhode code !!
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
150 hooks1 = RhodeCodeUi()
392
b27d32cb3157 Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
151 hooks1.ui_section = 'hooks'
b27d32cb3157 Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
152 hooks1.ui_key = 'changegroup.update'
b27d32cb3157 Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
153 hooks1.ui_value = 'hg update >&2'
560
3072935bdeed rewrote whoosh indexing to run internal repository.walk() instead of filesystem.
Marcin Kuzminski <marcin@python-works.com>
parents: 555
diff changeset
154 hooks1.ui_active = False
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
155
549
f99075170eb4 more renames for rhode code !!
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
156 hooks2 = RhodeCodeUi()
392
b27d32cb3157 Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
157 hooks2.ui_section = 'hooks'
b27d32cb3157 Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
158 hooks2.ui_key = 'changegroup.repo_size'
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
159 hooks2.ui_value = 'python:rhodecode.lib.hooks.repo_size'
673
dd532af216d9 #49 Enabled anonymous access for web interface controllable from permissions pannel
Marcin Kuzminski <marcin@python-works.com>
parents: 657
diff changeset
160
657
212f97c2d2b7 installed new hooks for #48
Marcin Kuzminski <marcin@python-works.com>
parents: 631
diff changeset
161 hooks3 = RhodeCodeUi()
212f97c2d2b7 installed new hooks for #48
Marcin Kuzminski <marcin@python-works.com>
parents: 631
diff changeset
162 hooks3.ui_section = 'hooks'
212f97c2d2b7 installed new hooks for #48
Marcin Kuzminski <marcin@python-works.com>
parents: 631
diff changeset
163 hooks3.ui_key = 'pretxnchangegroup.push_logger'
212f97c2d2b7 installed new hooks for #48
Marcin Kuzminski <marcin@python-works.com>
parents: 631
diff changeset
164 hooks3.ui_value = 'python:rhodecode.lib.hooks.log_push_action'
673
dd532af216d9 #49 Enabled anonymous access for web interface controllable from permissions pannel
Marcin Kuzminski <marcin@python-works.com>
parents: 657
diff changeset
165
657
212f97c2d2b7 installed new hooks for #48
Marcin Kuzminski <marcin@python-works.com>
parents: 631
diff changeset
166 hooks4 = RhodeCodeUi()
212f97c2d2b7 installed new hooks for #48
Marcin Kuzminski <marcin@python-works.com>
parents: 631
diff changeset
167 hooks4.ui_section = 'hooks'
212f97c2d2b7 installed new hooks for #48
Marcin Kuzminski <marcin@python-works.com>
parents: 631
diff changeset
168 hooks4.ui_key = 'preoutgoing.pull_logger'
212f97c2d2b7 installed new hooks for #48
Marcin Kuzminski <marcin@python-works.com>
parents: 631
diff changeset
169 hooks4.ui_value = 'python:rhodecode.lib.hooks.log_pull_action'
673
dd532af216d9 #49 Enabled anonymous access for web interface controllable from permissions pannel
Marcin Kuzminski <marcin@python-works.com>
parents: 657
diff changeset
170
773
876776983c3c disabled dotencode format for mercurial 1.7 usage and hg <=1.6 compatibility
Marcin Kuzminski <marcin@python-works.com>
parents: 704
diff changeset
171 #for mercurial 1.7 set backward comapatibility with format
876776983c3c disabled dotencode format for mercurial 1.7 usage and hg <=1.6 compatibility
Marcin Kuzminski <marcin@python-works.com>
parents: 704
diff changeset
172
876776983c3c disabled dotencode format for mercurial 1.7 usage and hg <=1.6 compatibility
Marcin Kuzminski <marcin@python-works.com>
parents: 704
diff changeset
173 dotencode_disable = RhodeCodeUi()
876776983c3c disabled dotencode format for mercurial 1.7 usage and hg <=1.6 compatibility
Marcin Kuzminski <marcin@python-works.com>
parents: 704
diff changeset
174 dotencode_disable.ui_section = 'format'
876776983c3c disabled dotencode format for mercurial 1.7 usage and hg <=1.6 compatibility
Marcin Kuzminski <marcin@python-works.com>
parents: 704
diff changeset
175 dotencode_disable.ui_key = 'dotencode'
876776983c3c disabled dotencode format for mercurial 1.7 usage and hg <=1.6 compatibility
Marcin Kuzminski <marcin@python-works.com>
parents: 704
diff changeset
176 dotencode_disable.ui_section = 'false'
876776983c3c disabled dotencode format for mercurial 1.7 usage and hg <=1.6 compatibility
Marcin Kuzminski <marcin@python-works.com>
parents: 704
diff changeset
177
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
178
549
f99075170eb4 more renames for rhode code !!
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
179 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
180 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
181 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
182 web1.ui_value = 'false'
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
183
549
f99075170eb4 more renames for rhode code !!
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
184 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
185 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
186 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
187 web2.ui_value = 'gz zip bz2'
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
188
549
f99075170eb4 more renames for rhode code !!
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
189 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
190 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
191 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
192 web3.ui_value = '*'
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
193
549
f99075170eb4 more renames for rhode code !!
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
194 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
195 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
196 web4.ui_key = 'baseurl'
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
197 web4.ui_value = '/'
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
198
549
f99075170eb4 more renames for rhode code !!
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
199 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
200 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
201 paths.ui_key = '/'
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
202 paths.ui_value = path
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
203
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
204
704
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents: 673
diff changeset
205 hgsettings1 = RhodeCodeSettings('realm', 'RhodeCode authentication')
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents: 673
diff changeset
206 hgsettings2 = RhodeCodeSettings('title', 'RhodeCode')
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
207
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
208
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
209 try:
392
b27d32cb3157 Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
210 self.sa.add(hooks1)
b27d32cb3157 Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
211 self.sa.add(hooks2)
657
212f97c2d2b7 installed new hooks for #48
Marcin Kuzminski <marcin@python-works.com>
parents: 631
diff changeset
212 self.sa.add(hooks3)
212f97c2d2b7 installed new hooks for #48
Marcin Kuzminski <marcin@python-works.com>
parents: 631
diff changeset
213 self.sa.add(hooks4)
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
214 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
215 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
216 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
217 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
218 self.sa.add(paths)
381
55377fdc1fc6 cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents: 371
diff changeset
219 self.sa.add(hgsettings1)
55377fdc1fc6 cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents: 371
diff changeset
220 self.sa.add(hgsettings2)
773
876776983c3c disabled dotencode format for mercurial 1.7 usage and hg <=1.6 compatibility
Marcin Kuzminski <marcin@python-works.com>
parents: 704
diff changeset
221 self.sa.add(dotencode_disable)
704
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents: 673
diff changeset
222 for k in ['ldap_active', 'ldap_host', 'ldap_port', 'ldap_ldaps',
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents: 673
diff changeset
223 'ldap_dn_user', 'ldap_dn_pass', 'ldap_base_dn']:
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents: 673
diff changeset
224
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents: 673
diff changeset
225 setting = RhodeCodeSettings(k, '')
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents: 673
diff changeset
226 self.sa.add(setting)
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents: 673
diff changeset
227
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
228 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
229 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
230 self.sa.rollback()
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
231 raise
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
232 log.info('created ui config')
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
233
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
234 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
235 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
236 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
237 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
238 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
239 new_user.name = 'RhodeCode'
262
a4be1ebb214f updated db manage with some defaults
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
240 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
241 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
242 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
243 new_user.active = True
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
244
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
245 try:
459
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
246 self.sa.add(new_user)
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
247 self.sa.commit()
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
248 except:
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
249 self.sa.rollback()
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
250 raise
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
251
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
252 def create_default_user(self):
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
253 log.info('creating default user')
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
254 #create default user for handling default permissions.
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
255 def_user = User()
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
256 def_user.username = 'default'
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
257 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
258 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
259 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
260 def_user.email = 'anonymous@rhodecode.org'
459
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
261 def_user.admin = False
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
262 def_user.active = False
7c978511c951 implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
263 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
264 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
265 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
266 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
267 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
268 raise
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
269
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
270 def create_permissions(self):
240
7c4fa2a66195 small fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 239
diff changeset
271 #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
272 #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
273 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
274 ('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
275 ('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
276 ('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
277 ('hg.admin', 'Hg Administrator'),
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
278 ('hg.create.repository', 'Repository create'),
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
279 ('hg.create.none', 'Repository creation disabled'),
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
280 ('hg.register.none', 'Register disabled'),
549
f99075170eb4 more renames for rhode code !!
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
281 ('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
282 ('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
283 ]
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
284
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
285 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
286 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
287 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
288 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
289 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
290 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
291 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
292 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
293 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
294 raise
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
295
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
296 def populate_default_permissions(self):
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
297 log.info('creating default user permissions')
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
298
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
299 default_user = self.sa.query(User)\
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
300 .filter(User.username == 'default').scalar()
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
301
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
302 reg_perm = UserToPerm()
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
303 reg_perm.user = default_user
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
304 reg_perm.permission = self.sa.query(Permission)\
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
305 .filter(Permission.permission_name == 'hg.register.manual_activate')\
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
306 .scalar()
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
307
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
308 create_repo_perm = UserToPerm()
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
309 create_repo_perm.user = default_user
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
310 create_repo_perm.permission = self.sa.query(Permission)\
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
311 .filter(Permission.permission_name == 'hg.create.repository')\
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
312 .scalar()
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
313
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
314 default_repo_perm = UserToPerm()
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
315 default_repo_perm.user = default_user
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
316 default_repo_perm.permission = self.sa.query(Permission)\
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
317 .filter(Permission.permission_name == 'repository.read')\
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
318 .scalar()
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
319
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
320 try:
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
321 self.sa.add(reg_perm)
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
322 self.sa.add(create_repo_perm)
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
323 self.sa.add(default_repo_perm)
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
324 self.sa.commit()
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
325 except:
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
326 self.sa.rollback()
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
327 raise
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 597
diff changeset
328