Mercurial > public > src > rhodecode
annotate pylons_app/lib/db_manage.py @ 535:fefffd6fd5f4 celery
Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
cleaned up some codes that involves testing.
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Tue, 21 Sep 2010 01:08:01 +0200 |
parents | ac559565c6b8 |
children | 53aa1ee1af86 |
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> |
376
d09381593b12
updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents:
374
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 |
345
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:
320
diff
changeset
|
30 import uuid |
249
bad9ccac26b7
fixed import errors on db_manage
Marcin Kuzminski <marcin@python-works.com>
parents:
243
diff
changeset
|
31 ROOT = dn(dn(dn(os.path.realpath(__file__)))) |
bad9ccac26b7
fixed import errors on db_manage
Marcin Kuzminski <marcin@python-works.com>
parents:
243
diff
changeset
|
32 sys.path.append(ROOT) |
bad9ccac26b7
fixed import errors on db_manage
Marcin Kuzminski <marcin@python-works.com>
parents:
243
diff
changeset
|
33 |
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
|
34 from pylons_app.lib.auth import get_crypt_password |
376
d09381593b12
updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents:
374
diff
changeset
|
35 from pylons_app.lib.utils import ask_ok |
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
|
36 from pylons_app.model import init_model |
453
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
425
diff
changeset
|
37 from pylons_app.model.db import User, Permission, HgAppUi, HgAppSettings, \ |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
425
diff
changeset
|
38 UserToPerm |
374
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
368
diff
changeset
|
39 from pylons_app.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
|
40 from sqlalchemy.engine import create_engine |
59
736078908f37
added db_manage script
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
41 import logging |
736078908f37
added db_manage script
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff
changeset
|
42 |
376
d09381593b12
updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents:
374
diff
changeset
|
43 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
|
44 |
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
|
45 class DbManage(object): |
535
fefffd6fd5f4
Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents:
515
diff
changeset
|
46 def __init__(self, log_sql, dbname, tests=False): |
501
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
453
diff
changeset
|
47 self.dbname = dbname |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
453
diff
changeset
|
48 self.tests = tests |
234
a0116e944da1
changed naming convention for db modules.
Marcin Kuzminski <marcin@python-works.com>
parents:
229
diff
changeset
|
49 dburi = 'sqlite:////%s' % jn(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
|
50 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
|
51 init_model(engine) |
374
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
368
diff
changeset
|
52 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
|
53 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
|
54 |
c6526b7531e9
rewritten db manage script to use sqlalchemy. Fixed sqlalchemy models to more generic.
Marcin Kuzminski <marcin@python-works.com>
parents:
88
diff
changeset
|
55 def check_for_db(self, 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
|
56 log.info('checking for exisiting db') |
234
a0116e944da1
changed naming convention for db modules.
Marcin Kuzminski <marcin@python-works.com>
parents:
229
diff
changeset
|
57 if os.path.isfile(jn(ROOT, self.dbname)): |
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 |
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
|
59 log.info('database exisist') |
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: |
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
|
69 log.info("database exisist and it's going to be destroyed") |
501
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
453
diff
changeset
|
70 if self.tests: |
535
fefffd6fd5f4
Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents:
515
diff
changeset
|
71 destroy = True |
501
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
453
diff
changeset
|
72 else: |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
453
diff
changeset
|
73 destroy = ask_ok('Are you sure to destroy old database ? [y/n]') |
376
d09381593b12
updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents:
374
diff
changeset
|
74 if not destroy: |
d09381593b12
updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents:
374
diff
changeset
|
75 sys.exit() |
d09381593b12
updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents:
374
diff
changeset
|
76 if self.db_exists and destroy: |
243
9d64df490248
fixed bug when there was no dbfile, and dbmanage raise an exception
Marcin Kuzminski <marcin@python-works.com>
parents:
240
diff
changeset
|
77 os.remove(jn(ROOT, self.dbname)) |
376
d09381593b12
updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents:
374
diff
changeset
|
78 checkfirst = not override |
d09381593b12
updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents:
374
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): |
501
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
453
diff
changeset
|
83 if not self.tests: |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
453
diff
changeset
|
84 import getpass |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
453
diff
changeset
|
85 username = raw_input('Specify admin username:') |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
453
diff
changeset
|
86 password = getpass.getpass('Specify admin password:') |
535
fefffd6fd5f4
Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents:
515
diff
changeset
|
87 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:
515
diff
changeset
|
88 self.create_user(username, password, email, True) |
501
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
453
diff
changeset
|
89 else: |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
453
diff
changeset
|
90 log.info('creating admin and regular test users') |
535
fefffd6fd5f4
Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents:
515
diff
changeset
|
91 self.create_user('test_admin', 'test', 'test_admin@mail.com', True) |
fefffd6fd5f4
Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents:
515
diff
changeset
|
92 self.create_user('test_regular', 'test', 'test_regular@mail.com', False) |
fefffd6fd5f4
Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents:
515
diff
changeset
|
93 self.create_user('test_regular2', 'test', 'test_regular2@mail.com', False) |
501
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
453
diff
changeset
|
94 |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
453
diff
changeset
|
95 |
364
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:
345
diff
changeset
|
96 |
535
fefffd6fd5f4
Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents:
515
diff
changeset
|
97 def config_prompt(self, test_repo_path=''): |
368
bb8f45f6d8f9
updated hg-app db manage and global settings
Marcin Kuzminski <marcin@python-works.com>
parents:
364
diff
changeset
|
98 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
|
99 |
501
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
453
diff
changeset
|
100 if not self.tests and not test_repo_path: |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
453
diff
changeset
|
101 path = raw_input('Specify valid full path to your repositories' |
376
d09381593b12
updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents:
374
diff
changeset
|
102 ' you can change this later in application settings:') |
501
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
453
diff
changeset
|
103 else: |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
453
diff
changeset
|
104 path = test_repo_path |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
453
diff
changeset
|
105 |
364
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:
345
diff
changeset
|
106 if not os.path.isdir(path): |
535
fefffd6fd5f4
Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents:
515
diff
changeset
|
107 log.error('You entered wrong path: %s', path) |
364
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:
345
diff
changeset
|
108 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:
345
diff
changeset
|
109 |
425
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
413
diff
changeset
|
110 hooks1 = HgAppUi() |
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
413
diff
changeset
|
111 hooks1.ui_section = 'hooks' |
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
413
diff
changeset
|
112 hooks1.ui_key = 'changegroup.update' |
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
413
diff
changeset
|
113 hooks1.ui_value = 'hg update >&2' |
364
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:
345
diff
changeset
|
114 |
425
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
413
diff
changeset
|
115 hooks2 = HgAppUi() |
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
413
diff
changeset
|
116 hooks2.ui_section = 'hooks' |
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
413
diff
changeset
|
117 hooks2.ui_key = 'changegroup.repo_size' |
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
413
diff
changeset
|
118 hooks2.ui_value = 'python:pylons_app.lib.hooks.repo_size' |
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
413
diff
changeset
|
119 |
364
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:
345
diff
changeset
|
120 web1 = HgAppUi() |
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:
345
diff
changeset
|
121 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:
345
diff
changeset
|
122 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:
345
diff
changeset
|
123 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:
345
diff
changeset
|
124 |
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:
345
diff
changeset
|
125 web2 = HgAppUi() |
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:
345
diff
changeset
|
126 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:
345
diff
changeset
|
127 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:
345
diff
changeset
|
128 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:
345
diff
changeset
|
129 |
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:
345
diff
changeset
|
130 web3 = HgAppUi() |
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:
345
diff
changeset
|
131 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:
345
diff
changeset
|
132 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:
345
diff
changeset
|
133 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:
345
diff
changeset
|
134 |
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:
345
diff
changeset
|
135 web4 = HgAppUi() |
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:
345
diff
changeset
|
136 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:
345
diff
changeset
|
137 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:
345
diff
changeset
|
138 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:
345
diff
changeset
|
139 |
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:
345
diff
changeset
|
140 paths = HgAppUi() |
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:
345
diff
changeset
|
141 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:
345
diff
changeset
|
142 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:
345
diff
changeset
|
143 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:
345
diff
changeset
|
144 |
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:
345
diff
changeset
|
145 |
413
55377fdc1fc6
cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents:
401
diff
changeset
|
146 hgsettings1 = HgAppSettings() |
55377fdc1fc6
cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents:
401
diff
changeset
|
147 |
55377fdc1fc6
cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents:
401
diff
changeset
|
148 hgsettings1.app_settings_name = 'realm' |
55377fdc1fc6
cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents:
401
diff
changeset
|
149 hgsettings1.app_settings_value = 'hg-app authentication' |
55377fdc1fc6
cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents:
401
diff
changeset
|
150 |
55377fdc1fc6
cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents:
401
diff
changeset
|
151 hgsettings2 = HgAppSettings() |
55377fdc1fc6
cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents:
401
diff
changeset
|
152 hgsettings2.app_settings_name = 'title' |
55377fdc1fc6
cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents:
401
diff
changeset
|
153 hgsettings2.app_settings_value = 'hg-app' |
368
bb8f45f6d8f9
updated hg-app db manage and global settings
Marcin Kuzminski <marcin@python-works.com>
parents:
364
diff
changeset
|
154 |
364
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:
345
diff
changeset
|
155 try: |
425
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
413
diff
changeset
|
156 self.sa.add(hooks1) |
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
413
diff
changeset
|
157 self.sa.add(hooks2) |
364
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:
345
diff
changeset
|
158 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:
345
diff
changeset
|
159 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:
345
diff
changeset
|
160 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:
345
diff
changeset
|
161 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:
345
diff
changeset
|
162 self.sa.add(paths) |
413
55377fdc1fc6
cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents:
401
diff
changeset
|
163 self.sa.add(hgsettings1) |
55377fdc1fc6
cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents:
401
diff
changeset
|
164 self.sa.add(hgsettings2) |
364
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:
345
diff
changeset
|
165 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:
345
diff
changeset
|
166 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:
345
diff
changeset
|
167 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:
345
diff
changeset
|
168 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:
345
diff
changeset
|
169 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:
345
diff
changeset
|
170 |
535
fefffd6fd5f4
Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents:
515
diff
changeset
|
171 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
|
172 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
|
173 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
|
174 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
|
175 new_user.password = get_crypt_password(password) |
309
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
264
diff
changeset
|
176 new_user.name = 'Hg' |
262
a4be1ebb214f
updated db manage with some defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
252
diff
changeset
|
177 new_user.lastname = 'Admin' |
535
fefffd6fd5f4
Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents:
515
diff
changeset
|
178 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
|
179 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
|
180 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
|
181 |
c6526b7531e9
rewritten db manage script to use sqlalchemy. Fixed sqlalchemy models to more generic.
Marcin Kuzminski <marcin@python-works.com>
parents:
88
diff
changeset
|
182 try: |
501
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
453
diff
changeset
|
183 self.sa.add(new_user) |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
453
diff
changeset
|
184 self.sa.commit() |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
453
diff
changeset
|
185 except: |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
453
diff
changeset
|
186 self.sa.rollback() |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
453
diff
changeset
|
187 raise |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
453
diff
changeset
|
188 |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
453
diff
changeset
|
189 def create_default_user(self): |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
453
diff
changeset
|
190 log.info('creating default user') |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
453
diff
changeset
|
191 #create default user for handling default permissions. |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
453
diff
changeset
|
192 def_user = User() |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
453
diff
changeset
|
193 def_user.username = 'default' |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
453
diff
changeset
|
194 def_user.password = get_crypt_password(str(uuid.uuid1())[:8]) |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
453
diff
changeset
|
195 def_user.name = 'default' |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
453
diff
changeset
|
196 def_user.lastname = 'default' |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
453
diff
changeset
|
197 def_user.email = 'default@default.com' |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
453
diff
changeset
|
198 def_user.admin = False |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
453
diff
changeset
|
199 def_user.active = False |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
453
diff
changeset
|
200 try: |
364
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:
345
diff
changeset
|
201 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
|
202 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
|
203 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
|
204 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
|
205 raise |
66
163464441e0d
updated db manage script for creating interactive admin account and db
Marcin Kuzminski <marcin@python-blog.com>
parents:
59
diff
changeset
|
206 |
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
|
207 def create_permissions(self): |
240 | 208 #module.(access|create|change|delete)_[name] |
309
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
264
diff
changeset
|
209 #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
|
210 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
|
211 ('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
|
212 ('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
|
213 ('repository.admin', 'Repository admin access'), |
320
504feff57b49
added permission functions to webhelpers, updated dbmanage permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
309
diff
changeset
|
214 ('hg.admin', 'Hg Administrator'), |
453
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
425
diff
changeset
|
215 ('hg.create.repository', 'Repository create'), |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
425
diff
changeset
|
216 ('hg.create.none', 'Repository creation disabled'), |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
425
diff
changeset
|
217 ('hg.register.none', 'Register disabled'), |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
425
diff
changeset
|
218 ('hg.register.manual_activate', 'Register new user with hg-app without manual activation'), |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
425
diff
changeset
|
219 ('hg.register.auto_activate', 'Register new user with hg-app without auto activation'), |
401
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
393
diff
changeset
|
220 ] |
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
|
221 |
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
|
222 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
|
223 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
|
224 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
|
225 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
|
226 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
|
227 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
|
228 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
|
229 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
|
230 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
|
231 raise |
453
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
425
diff
changeset
|
232 |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
425
diff
changeset
|
233 def populate_default_permissions(self): |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
425
diff
changeset
|
234 log.info('creating default user permissions') |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
425
diff
changeset
|
235 |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
425
diff
changeset
|
236 default_user = self.sa.query(User)\ |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
425
diff
changeset
|
237 .filter(User.username == 'default').scalar() |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
425
diff
changeset
|
238 |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
425
diff
changeset
|
239 reg_perm = UserToPerm() |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
425
diff
changeset
|
240 reg_perm.user = default_user |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
425
diff
changeset
|
241 reg_perm.permission = self.sa.query(Permission)\ |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
425
diff
changeset
|
242 .filter(Permission.permission_name == 'hg.register.manual_activate')\ |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
425
diff
changeset
|
243 .scalar() |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
425
diff
changeset
|
244 |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
425
diff
changeset
|
245 create_repo_perm = UserToPerm() |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
425
diff
changeset
|
246 create_repo_perm.user = default_user |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
425
diff
changeset
|
247 create_repo_perm.permission = self.sa.query(Permission)\ |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
425
diff
changeset
|
248 .filter(Permission.permission_name == 'hg.create.repository')\ |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
425
diff
changeset
|
249 .scalar() |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
425
diff
changeset
|
250 |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
425
diff
changeset
|
251 default_repo_perm = UserToPerm() |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
425
diff
changeset
|
252 default_repo_perm.user = default_user |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
425
diff
changeset
|
253 default_repo_perm.permission = self.sa.query(Permission)\ |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
425
diff
changeset
|
254 .filter(Permission.permission_name == 'repository.read')\ |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
425
diff
changeset
|
255 .scalar() |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
425
diff
changeset
|
256 |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
425
diff
changeset
|
257 try: |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
425
diff
changeset
|
258 self.sa.add(reg_perm) |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
425
diff
changeset
|
259 self.sa.add(create_repo_perm) |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
425
diff
changeset
|
260 self.sa.add(default_repo_perm) |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
425
diff
changeset
|
261 self.sa.commit() |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
425
diff
changeset
|
262 except: |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
425
diff
changeset
|
263 self.sa.rollback() |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
425
diff
changeset
|
264 raise |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
425
diff
changeset
|
265 |