Mercurial > kallithea
annotate pylons_app/lib/db_manage.py @ 483:a9e50dce3081 celery
Removed config names from whoosh and celery,
celery is now configured based on the config name it's using
on celeryconfig. And whoosh uses it's own logger configured just for whoosh
Test creates a fresh whoosh index now, for more accurate checks
fixed tests for searching
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Fri, 17 Sep 2010 22:54:30 +0200 |
parents | ac559565c6b8 |
children | fefffd6fd5f4 |
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 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 |
351
d09381593b12
updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents:
350
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 |
417
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
37 from pylons_app.model.db import User, Permission, HgAppUi, HgAppSettings, \ |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
38 UserToPerm |
350
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
345
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 |
351
d09381593b12
updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents:
350
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): |
459
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
46 def __init__(self, log_sql, dbname,tests=False): |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
47 self.dbname = dbname |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
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) |
350
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
345
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") |
459
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
70 if self.tests: |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
71 destroy=True |
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: |
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)) |
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:') |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
87 self.create_user(username, password, True) |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
88 else: |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
89 log.info('creating admin and regular test users') |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
90 self.create_user('test_admin', 'test', True) |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
91 self.create_user('test_regular', 'test', False) |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
92 |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
93 |
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
|
94 |
459
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
95 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
|
96 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
|
97 |
459
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
98 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
|
99 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
|
100 ' 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
|
101 else: |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
102 path = test_repo_path |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
103 |
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
|
104 if not os.path.isdir(path): |
459
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
105 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
|
106 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
|
107 |
392
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
108 hooks1 = HgAppUi() |
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
109 hooks1.ui_section = 'hooks' |
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
110 hooks1.ui_key = 'changegroup.update' |
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
111 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
|
112 |
392
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
113 hooks2 = HgAppUi() |
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
114 hooks2.ui_section = 'hooks' |
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
115 hooks2.ui_key = 'changegroup.repo_size' |
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
116 hooks2.ui_value = 'python:pylons_app.lib.hooks.repo_size' |
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
117 |
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 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:
327
diff
changeset
|
119 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
|
120 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
|
121 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
|
122 |
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
|
123 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:
327
diff
changeset
|
124 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
|
125 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
|
126 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
|
127 |
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 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:
327
diff
changeset
|
129 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
|
130 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
|
131 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
|
132 |
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 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:
327
diff
changeset
|
134 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
|
135 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
|
136 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
|
137 |
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 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:
327
diff
changeset
|
139 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
|
140 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
|
141 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
|
142 |
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 |
381
55377fdc1fc6
cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents:
371
diff
changeset
|
144 hgsettings1 = HgAppSettings() |
55377fdc1fc6
cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents:
371
diff
changeset
|
145 |
55377fdc1fc6
cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents:
371
diff
changeset
|
146 hgsettings1.app_settings_name = 'realm' |
55377fdc1fc6
cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents:
371
diff
changeset
|
147 hgsettings1.app_settings_value = 'hg-app authentication' |
55377fdc1fc6
cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents:
371
diff
changeset
|
148 |
55377fdc1fc6
cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents:
371
diff
changeset
|
149 hgsettings2 = HgAppSettings() |
55377fdc1fc6
cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents:
371
diff
changeset
|
150 hgsettings2.app_settings_name = 'title' |
55377fdc1fc6
cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents:
371
diff
changeset
|
151 hgsettings2.app_settings_value = 'hg-app' |
345
bb8f45f6d8f9
updated hg-app db manage and global settings
Marcin Kuzminski <marcin@python-works.com>
parents:
341
diff
changeset
|
152 |
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
|
153 try: |
392
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
154 self.sa.add(hooks1) |
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
155 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
|
156 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
|
157 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
|
158 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
|
159 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
|
160 self.sa.add(paths) |
381
55377fdc1fc6
cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents:
371
diff
changeset
|
161 self.sa.add(hgsettings1) |
55377fdc1fc6
cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents:
371
diff
changeset
|
162 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
|
163 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
|
164 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
|
165 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
|
166 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
|
167 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
|
168 |
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
|
169 def create_user(self, username, password, 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
|
170 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
|
171 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
|
172 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
|
173 new_user.password = get_crypt_password(password) |
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
|
174 new_user.name = 'Hg' |
262
a4be1ebb214f
updated db manage with some defaults
Marcin Kuzminski <marcin@python-works.com>
parents:
252
diff
changeset
|
175 new_user.lastname = 'Admin' |
471
ac559565c6b8
config change little style fix for form buttons
Marcin Kuzminski <marcin@python-works.com>
parents:
459
diff
changeset
|
176 new_user.email = 'admin@localhost.com' |
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
|
177 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
|
178 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
|
179 |
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 try: |
459
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
181 self.sa.add(new_user) |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
182 self.sa.commit() |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
183 except: |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
184 self.sa.rollback() |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
185 raise |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
186 |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
187 def create_default_user(self): |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
188 log.info('creating default user') |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
189 #create default user for handling default permissions. |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
190 def_user = User() |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
191 def_user.username = 'default' |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
192 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
|
193 def_user.name = 'default' |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
194 def_user.lastname = 'default' |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
195 def_user.email = 'default@default.com' |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
196 def_user.admin = False |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
197 def_user.active = False |
7c978511c951
implemented basic (startup) nose test suite.
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
198 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
|
199 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
|
200 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
|
201 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
|
202 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
|
203 raise |
66
163464441e0d
updated db manage script for creating interactive admin account and db
Marcin Kuzminski <marcin@python-blog.com>
parents:
59
diff
changeset
|
204 |
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
|
205 def create_permissions(self): |
240 | 206 #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
|
207 #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
|
208 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
|
209 ('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
|
210 ('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
|
211 ('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
|
212 ('hg.admin', 'Hg Administrator'), |
417
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
213 ('hg.create.repository', 'Repository create'), |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
214 ('hg.create.none', 'Repository creation disabled'), |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
215 ('hg.register.none', 'Register disabled'), |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
216 ('hg.register.manual_activate', 'Register new user with hg-app without manual activation'), |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
217 ('hg.register.auto_activate', 'Register new user with hg-app without auto activation'), |
371
5cd6616b8673
routes python 2.5 compatible
Marcin Kuzminski <marcin@python-works.com>
parents:
367
diff
changeset
|
218 ] |
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
|
219 |
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
|
220 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
|
221 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
|
222 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
|
223 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
|
224 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
|
225 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
|
226 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
|
227 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
|
228 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
|
229 raise |
417
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
230 |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
231 def populate_default_permissions(self): |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
232 log.info('creating default user permissions') |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
233 |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
234 default_user = self.sa.query(User)\ |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
235 .filter(User.username == 'default').scalar() |
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 reg_perm = UserToPerm() |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
238 reg_perm.user = default_user |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
239 reg_perm.permission = self.sa.query(Permission)\ |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
240 .filter(Permission.permission_name == 'hg.register.manual_activate')\ |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
241 .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 create_repo_perm = UserToPerm() |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
244 create_repo_perm.user = default_user |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
245 create_repo_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.create.repository')\ |
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 default_repo_perm = UserToPerm() |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
250 default_repo_perm.user = default_user |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
251 default_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 == 'repository.read')\ |
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 try: |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
256 self.sa.add(reg_perm) |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
257 self.sa.add(create_repo_perm) |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
258 self.sa.add(default_repo_perm) |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
259 self.sa.commit() |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
260 except: |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
261 self.sa.rollback() |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
262 raise |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
263 |