Mercurial > kallithea
annotate rhodecode/lib/db_manage.py @ 559:bc4633a41967
make rhodecode reuse current session when not running on celery
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Thu, 07 Oct 2010 22:01:51 +0200 |
parents | 03676d39dd0a |
children | 3072935bdeed |
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 |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
249
diff
changeset
|
3 # database managment for hg app |
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 |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
249
diff
changeset
|
23 database managment and creation for hg app |
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): |
552
2642f128ad46
removed egg info, update files for distutils build
Marcin Kuzminski <marcin@python-works.com>
parents:
549
diff
changeset
|
44 def __init__(self, log_sql, dbname, root, tests=False): |
459
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
45 self.dbname = dbname |
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 |
2642f128ad46
removed egg info, update files for distutils build
Marcin Kuzminski <marcin@python-works.com>
parents:
549
diff
changeset
|
48 dburi = 'sqlite:////%s' % jn(self.root, self.dbname) |
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
|
49 engine = create_engine(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) |
350
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
345
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 |
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
|
53 |
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) |
2642f128ad46
removed egg info, update files for distutils build
Marcin Kuzminski <marcin@python-works.com>
parents:
549
diff
changeset
|
56 log.info('checking for existing db in %s', db_path) |
2642f128ad46
removed egg info, update files for distutils build
Marcin Kuzminski <marcin@python-works.com>
parents:
549
diff
changeset
|
57 if os.path.isfile(db_path): |
243
9d64df490248
fixed bug when there was no dbfile, and dbmanage raise an exception
Marcin Kuzminski <marcin@python-works.com>
parents:
240
diff
changeset
|
58 self.db_exists = True |
552
2642f128ad46
removed egg info, update files for distutils build
Marcin Kuzminski <marcin@python-works.com>
parents:
549
diff
changeset
|
59 log.info('database exist') |
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
|
60 if not override: |
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
|
61 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
|
62 |
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
|
63 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
|
64 """ |
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 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
|
66 """ |
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 self.check_for_db(override) |
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 if override: |
552
2642f128ad46
removed egg info, update files for distutils build
Marcin Kuzminski <marcin@python-works.com>
parents:
549
diff
changeset
|
69 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
|
70 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
|
71 destroy = True |
459
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
72 else: |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
73 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
|
74 if not destroy: |
d09381593b12
updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents:
350
diff
changeset
|
75 sys.exit() |
d09381593b12
updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents:
350
diff
changeset
|
76 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
|
77 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
|
78 checkfirst = not override |
d09381593b12
updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents:
350
diff
changeset
|
79 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
|
80 log.info('Created tables for %s', self.dbname) |
59
736078908f37
added db_manage script
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
81 |
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
|
82 def admin_prompt(self): |
459
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
83 if not self.tests: |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
84 import getpass |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
85 username = raw_input('Specify admin username:') |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
86 password = getpass.getpass('Specify admin password:') |
552
2642f128ad46
removed egg info, update files for distutils build
Marcin Kuzminski <marcin@python-works.com>
parents:
549
diff
changeset
|
87 confirm = getpass.getpass('Confirm password:') |
2642f128ad46
removed egg info, update files for distutils build
Marcin Kuzminski <marcin@python-works.com>
parents:
549
diff
changeset
|
88 if password != confirm: |
2642f128ad46
removed egg info, update files for distutils build
Marcin Kuzminski <marcin@python-works.com>
parents:
549
diff
changeset
|
89 log.error('passwords mismatch') |
2642f128ad46
removed egg info, update files for distutils build
Marcin Kuzminski <marcin@python-works.com>
parents:
549
diff
changeset
|
90 sys.exit() |
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
|
91 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
|
92 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
|
93 else: |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
94 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
|
95 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
|
96 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
|
97 self.create_user('test_regular2', 'test12', 'test_regular2@mail.com', False) |
459
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
98 |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
99 |
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
|
100 |
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
|
101 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
|
102 log.info('Setting up repositories config') |
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
|
103 |
459
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
104 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
|
105 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
|
106 ' 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
|
107 else: |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
108 path = test_repo_path |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
109 |
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
|
110 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
|
111 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
|
112 sys.exit() |
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
|
113 |
549
f99075170eb4
more renames for rhode code !!
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
114 hooks1 = RhodeCodeUi() |
392
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
115 hooks1.ui_section = 'hooks' |
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
116 hooks1.ui_key = 'changegroup.update' |
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
117 hooks1.ui_value = 'hg update >&2' |
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
|
118 |
549
f99075170eb4
more renames for rhode code !!
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
119 hooks2 = RhodeCodeUi() |
392
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
120 hooks2.ui_section = 'hooks' |
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
121 hooks2.ui_key = 'changegroup.repo_size' |
547
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
533
diff
changeset
|
122 hooks2.ui_value = 'python:rhodecode.lib.hooks.repo_size' |
392
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
123 |
549
f99075170eb4
more renames for rhode code !!
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
124 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
|
125 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
|
126 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
|
127 web1.ui_value = 'false' |
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
|
128 |
549
f99075170eb4
more renames for rhode code !!
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
129 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
|
130 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
|
131 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
|
132 web2.ui_value = 'gz zip bz2' |
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
|
133 |
549
f99075170eb4
more renames for rhode code !!
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
134 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
|
135 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
|
136 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
|
137 web3.ui_value = '*' |
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
|
138 |
549
f99075170eb4
more renames for rhode code !!
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
139 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
|
140 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
|
141 web4.ui_key = 'baseurl' |
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
|
142 web4.ui_value = '/' |
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
|
143 |
549
f99075170eb4
more renames for rhode code !!
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
144 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
|
145 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
|
146 paths.ui_key = '/' |
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
|
147 paths.ui_value = os.path.join(path, '*') |
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 |
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
|
149 |
549
f99075170eb4
more renames for rhode code !!
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
150 hgsettings1 = RhodeCodeSettings() |
381
55377fdc1fc6
cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents:
371
diff
changeset
|
151 |
55377fdc1fc6
cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents:
371
diff
changeset
|
152 hgsettings1.app_settings_name = 'realm' |
555
03676d39dd0a
added fault tolerant case when celeryconfig is not present in the directory.
Marcin Kuzminski <marcin@python-works.com>
parents:
552
diff
changeset
|
153 hgsettings1.app_settings_value = 'RhodeCode authentication' |
381
55377fdc1fc6
cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents:
371
diff
changeset
|
154 |
549
f99075170eb4
more renames for rhode code !!
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
155 hgsettings2 = RhodeCodeSettings() |
381
55377fdc1fc6
cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents:
371
diff
changeset
|
156 hgsettings2.app_settings_name = 'title' |
555
03676d39dd0a
added fault tolerant case when celeryconfig is not present in the directory.
Marcin Kuzminski <marcin@python-works.com>
parents:
552
diff
changeset
|
157 hgsettings2.app_settings_value = 'RhodeCode' |
345
bb8f45f6d8f9
updated hg-app db manage and global settings
Marcin Kuzminski <marcin@python-works.com>
parents:
341
diff
changeset
|
158 |
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
|
159 try: |
392
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
160 self.sa.add(hooks1) |
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
161 self.sa.add(hooks2) |
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
|
162 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
|
163 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
|
164 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
|
165 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
|
166 self.sa.add(paths) |
381
55377fdc1fc6
cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents:
371
diff
changeset
|
167 self.sa.add(hgsettings1) |
55377fdc1fc6
cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents:
371
diff
changeset
|
168 self.sa.add(hgsettings2) |
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
|
169 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
|
170 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
|
171 self.sa.rollback() |
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
|
172 raise |
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
|
173 log.info('created ui config') |
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
|
174 |
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
|
175 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
|
176 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
|
177 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
|
178 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
|
179 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
|
180 new_user.name = 'RhodeCode' |
262
a4be1ebb214f
updated db manage with some defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
252
diff
changeset
|
181 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
|
182 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
|
183 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
|
184 new_user.active = True |
c6526b7531e9
rewritten db manage script to use sqlalchemy. Fixed sqlalchemy models to more generic.
Marcin Kuzminski <marcin@python-works.com>
parents:
88
diff
changeset
|
185 |
c6526b7531e9
rewritten db manage script to use sqlalchemy. Fixed sqlalchemy models to more generic.
Marcin Kuzminski <marcin@python-works.com>
parents:
88
diff
changeset
|
186 try: |
459
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
187 self.sa.add(new_user) |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
188 self.sa.commit() |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
189 except: |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
190 self.sa.rollback() |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
191 raise |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
192 |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
193 def create_default_user(self): |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
194 log.info('creating default user') |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
195 #create default user for handling default permissions. |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
196 def_user = User() |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
197 def_user.username = 'default' |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
198 def_user.password = get_crypt_password(str(uuid.uuid1())[:8]) |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
199 def_user.name = 'default' |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
200 def_user.lastname = 'default' |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
201 def_user.email = 'default@default.com' |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
202 def_user.admin = False |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
203 def_user.active = False |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
204 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
|
205 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
|
206 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
|
207 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
|
208 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
|
209 raise |
66
163464441e0d
updated db manage script for creating interactive admin account and db
Marcin Kuzminski <marcin@python-blog.com>
parents:
59
diff
changeset
|
210 |
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
|
211 def create_permissions(self): |
240 | 212 #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
|
213 #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
|
214 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
|
215 ('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
|
216 ('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
|
217 ('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
|
218 ('hg.admin', 'Hg Administrator'), |
417
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
219 ('hg.create.repository', 'Repository create'), |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
220 ('hg.create.none', 'Repository creation disabled'), |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
221 ('hg.register.none', 'Register disabled'), |
549
f99075170eb4
more renames for rhode code !!
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
222 ('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
|
223 ('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
|
224 ] |
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
|
225 |
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
|
226 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
|
227 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
|
228 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
|
229 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
|
230 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
|
231 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
|
232 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
|
233 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
|
234 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
|
235 raise |
417
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
236 |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
237 def populate_default_permissions(self): |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
238 log.info('creating default user permissions') |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
239 |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
240 default_user = self.sa.query(User)\ |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
241 .filter(User.username == 'default').scalar() |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
242 |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
243 reg_perm = UserToPerm() |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
244 reg_perm.user = default_user |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
245 reg_perm.permission = self.sa.query(Permission)\ |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
246 .filter(Permission.permission_name == 'hg.register.manual_activate')\ |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
247 .scalar() |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
248 |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
249 create_repo_perm = UserToPerm() |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
250 create_repo_perm.user = default_user |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
251 create_repo_perm.permission = self.sa.query(Permission)\ |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
252 .filter(Permission.permission_name == 'hg.create.repository')\ |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
253 .scalar() |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
254 |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
255 default_repo_perm = UserToPerm() |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
256 default_repo_perm.user = default_user |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
257 default_repo_perm.permission = self.sa.query(Permission)\ |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
258 .filter(Permission.permission_name == 'repository.read')\ |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
259 .scalar() |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
260 |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
261 try: |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
262 self.sa.add(reg_perm) |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
263 self.sa.add(create_repo_perm) |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
264 self.sa.add(default_repo_perm) |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
265 self.sa.commit() |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
266 except: |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
267 self.sa.rollback() |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
268 raise |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
269 |