Show More
@@ -1,109 +1,110 b'' | |||||
1 | """Pylons environment configuration""" |
|
1 | """Pylons environment configuration""" | |
2 |
|
2 | |||
3 | import os |
|
3 | import os | |
4 | import logging |
|
4 | import logging | |
5 | import rhodecode |
|
5 | import rhodecode | |
6 |
|
6 | |||
7 | from mako.lookup import TemplateLookup |
|
7 | from mako.lookup import TemplateLookup | |
8 | from pylons.configuration import PylonsConfig |
|
8 | from pylons.configuration import PylonsConfig | |
9 | from pylons.error import handle_mako_error |
|
9 | from pylons.error import handle_mako_error | |
10 |
|
10 | |||
11 | # don't remove this import it does magic for celery |
|
11 | # don't remove this import it does magic for celery | |
12 | from rhodecode.lib import celerypylons |
|
12 | from rhodecode.lib import celerypylons | |
13 |
|
13 | |||
14 | import rhodecode.lib.app_globals as app_globals |
|
14 | import rhodecode.lib.app_globals as app_globals | |
15 |
|
15 | |||
16 | from rhodecode.config.routing import make_map |
|
16 | from rhodecode.config.routing import make_map | |
17 |
|
17 | |||
18 | from rhodecode.lib import helpers |
|
18 | from rhodecode.lib import helpers | |
19 | from rhodecode.lib.auth import set_available_permissions |
|
19 | from rhodecode.lib.auth import set_available_permissions | |
20 | from rhodecode.lib.utils import repo2db_mapper, make_ui, set_rhodecode_config,\ |
|
20 | from rhodecode.lib.utils import repo2db_mapper, make_ui, set_rhodecode_config,\ | |
21 | load_rcextensions, check_git_version |
|
21 | load_rcextensions, check_git_version | |
22 | from rhodecode.lib.utils2 import engine_from_config, str2bool |
|
22 | from rhodecode.lib.utils2 import engine_from_config, str2bool | |
|
23 | from rhodecode.lib.db_manage import DbManage | |||
23 | from rhodecode.model import init_model |
|
24 | from rhodecode.model import init_model | |
24 | from rhodecode.model.scm import ScmModel |
|
25 | from rhodecode.model.scm import ScmModel | |
25 |
|
26 | |||
26 | log = logging.getLogger(__name__) |
|
27 | log = logging.getLogger(__name__) | |
27 |
|
28 | |||
28 |
|
29 | |||
29 | def load_environment(global_conf, app_conf, initial=False): |
|
30 | def load_environment(global_conf, app_conf, initial=False): | |
30 | """ |
|
31 | """ | |
31 | Configure the Pylons environment via the ``pylons.config`` |
|
32 | Configure the Pylons environment via the ``pylons.config`` | |
32 | object |
|
33 | object | |
33 | """ |
|
34 | """ | |
34 | config = PylonsConfig() |
|
35 | config = PylonsConfig() | |
35 |
|
36 | |||
36 | # Pylons paths |
|
37 | # Pylons paths | |
37 | root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
|
38 | root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
38 | paths = dict( |
|
39 | paths = dict( | |
39 | root=root, |
|
40 | root=root, | |
40 | controllers=os.path.join(root, 'controllers'), |
|
41 | controllers=os.path.join(root, 'controllers'), | |
41 | static_files=os.path.join(root, 'public'), |
|
42 | static_files=os.path.join(root, 'public'), | |
42 | templates=[os.path.join(root, 'templates')] |
|
43 | templates=[os.path.join(root, 'templates')] | |
43 | ) |
|
44 | ) | |
44 |
|
45 | |||
45 | # Initialize config with the basic options |
|
46 | # Initialize config with the basic options | |
46 | config.init_app(global_conf, app_conf, package='rhodecode', paths=paths) |
|
47 | config.init_app(global_conf, app_conf, package='rhodecode', paths=paths) | |
47 |
|
48 | |||
48 | # store some globals into rhodecode |
|
49 | # store some globals into rhodecode | |
49 | rhodecode.CELERY_ON = str2bool(config['app_conf'].get('use_celery')) |
|
50 | rhodecode.CELERY_ON = str2bool(config['app_conf'].get('use_celery')) | |
50 | rhodecode.CELERY_EAGER = str2bool(config['app_conf'].get('celery.always.eager')) |
|
51 | rhodecode.CELERY_EAGER = str2bool(config['app_conf'].get('celery.always.eager')) | |
51 |
|
52 | |||
52 | config['routes.map'] = make_map(config) |
|
53 | config['routes.map'] = make_map(config) | |
53 | config['pylons.app_globals'] = app_globals.Globals(config) |
|
54 | config['pylons.app_globals'] = app_globals.Globals(config) | |
54 | config['pylons.h'] = helpers |
|
55 | config['pylons.h'] = helpers | |
55 | rhodecode.CONFIG = config |
|
56 | rhodecode.CONFIG = config | |
56 |
|
57 | |||
57 | load_rcextensions(root_path=config['here']) |
|
58 | load_rcextensions(root_path=config['here']) | |
58 |
|
59 | |||
59 | # Setup cache object as early as possible |
|
60 | # Setup cache object as early as possible | |
60 | import pylons |
|
61 | import pylons | |
61 | pylons.cache._push_object(config['pylons.app_globals'].cache) |
|
62 | pylons.cache._push_object(config['pylons.app_globals'].cache) | |
62 |
|
63 | |||
63 | # Create the Mako TemplateLookup, with the default auto-escaping |
|
64 | # Create the Mako TemplateLookup, with the default auto-escaping | |
64 | config['pylons.app_globals'].mako_lookup = TemplateLookup( |
|
65 | config['pylons.app_globals'].mako_lookup = TemplateLookup( | |
65 | directories=paths['templates'], |
|
66 | directories=paths['templates'], | |
66 | error_handler=handle_mako_error, |
|
67 | error_handler=handle_mako_error, | |
67 | module_directory=os.path.join(app_conf['cache_dir'], 'templates'), |
|
68 | module_directory=os.path.join(app_conf['cache_dir'], 'templates'), | |
68 | input_encoding='utf-8', default_filters=['escape'], |
|
69 | input_encoding='utf-8', default_filters=['escape'], | |
69 | imports=['from webhelpers.html import escape']) |
|
70 | imports=['from webhelpers.html import escape']) | |
70 |
|
71 | |||
71 | # sets the c attribute access when don't existing attribute are accessed |
|
72 | # sets the c attribute access when don't existing attribute are accessed | |
72 | config['pylons.strict_tmpl_context'] = True |
|
73 | config['pylons.strict_tmpl_context'] = True | |
73 | test = os.path.split(config['__file__'])[-1] == 'test.ini' |
|
74 | test = os.path.split(config['__file__'])[-1] == 'test.ini' | |
74 | if test: |
|
75 | if test: | |
75 | if os.environ.get('TEST_DB'): |
|
76 | if os.environ.get('TEST_DB'): | |
76 | # swap config if we pass enviroment variable |
|
77 | # swap config if we pass enviroment variable | |
77 | config['sqlalchemy.db1.url'] = os.environ.get('TEST_DB') |
|
78 | config['sqlalchemy.db1.url'] = os.environ.get('TEST_DB') | |
78 |
|
79 | |||
79 | from rhodecode.lib.utils import create_test_env, create_test_index |
|
80 | from rhodecode.lib.utils import create_test_env, create_test_index | |
80 | from rhodecode.tests import TESTS_TMP_PATH |
|
81 | from rhodecode.tests import TESTS_TMP_PATH | |
81 | # set RC_NO_TMP_PATH=1 to disable re-creating the database and |
|
82 | # set RC_NO_TMP_PATH=1 to disable re-creating the database and | |
82 | # test repos |
|
83 | # test repos | |
83 | if not int(os.environ.get('RC_NO_TMP_PATH', 0)): |
|
84 | if not int(os.environ.get('RC_NO_TMP_PATH', 0)): | |
84 | create_test_env(TESTS_TMP_PATH, config) |
|
85 | create_test_env(TESTS_TMP_PATH, config) | |
85 | # set RC_WHOOSH_TEST_DISABLE=1 to disable whoosh index during tests |
|
86 | # set RC_WHOOSH_TEST_DISABLE=1 to disable whoosh index during tests | |
86 | if not int(os.environ.get('RC_WHOOSH_TEST_DISABLE', 0)): |
|
87 | if not int(os.environ.get('RC_WHOOSH_TEST_DISABLE', 0)): | |
87 | create_test_index(TESTS_TMP_PATH, config, True) |
|
88 | create_test_index(TESTS_TMP_PATH, config, True) | |
88 |
|
89 | |||
89 | #check git version |
|
90 | #check git version | |
90 | check_git_version() |
|
91 | check_git_version() | |
91 |
|
92 | DbManage.check_waitress() | ||
92 | # MULTIPLE DB configs |
|
93 | # MULTIPLE DB configs | |
93 | # Setup the SQLAlchemy database engine |
|
94 | # Setup the SQLAlchemy database engine | |
94 | sa_engine_db1 = engine_from_config(config, 'sqlalchemy.db1.') |
|
95 | sa_engine_db1 = engine_from_config(config, 'sqlalchemy.db1.') | |
95 | init_model(sa_engine_db1) |
|
96 | init_model(sa_engine_db1) | |
96 |
|
97 | |||
97 | repos_path = make_ui('db').configitems('paths')[0][1] |
|
98 | repos_path = make_ui('db').configitems('paths')[0][1] | |
98 | repo2db_mapper(ScmModel().repo_scan(repos_path), |
|
99 | repo2db_mapper(ScmModel().repo_scan(repos_path), | |
99 | remove_obsolete=False, install_git_hook=False) |
|
100 | remove_obsolete=False, install_git_hook=False) | |
100 | set_available_permissions(config) |
|
101 | set_available_permissions(config) | |
101 | config['base_path'] = repos_path |
|
102 | config['base_path'] = repos_path | |
102 | set_rhodecode_config(config) |
|
103 | set_rhodecode_config(config) | |
103 | # CONFIGURATION OPTIONS HERE (note: all config options will override |
|
104 | # CONFIGURATION OPTIONS HERE (note: all config options will override | |
104 | # any Pylons config options) |
|
105 | # any Pylons config options) | |
105 |
|
106 | |||
106 | # store config reference into our module to skip import magic of |
|
107 | # store config reference into our module to skip import magic of | |
107 | # pylons |
|
108 | # pylons | |
108 | rhodecode.CONFIG.update(config) |
|
109 | rhodecode.CONFIG.update(config) | |
109 | return config |
|
110 | return config |
@@ -1,714 +1,715 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 | """ |
|
2 | """ | |
3 | rhodecode.lib.db_manage |
|
3 | rhodecode.lib.db_manage | |
4 | ~~~~~~~~~~~~~~~~~~~~~~~ |
|
4 | ~~~~~~~~~~~~~~~~~~~~~~~ | |
5 |
|
5 | |||
6 | Database creation, and setup module for RhodeCode. Used for creation |
|
6 | Database creation, and setup module for RhodeCode. Used for creation | |
7 | of database as well as for migration operations |
|
7 | of database as well as for migration operations | |
8 |
|
8 | |||
9 | :created_on: Apr 10, 2010 |
|
9 | :created_on: Apr 10, 2010 | |
10 | :author: marcink |
|
10 | :author: marcink | |
11 | :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com> |
|
11 | :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com> | |
12 | :license: GPLv3, see COPYING for more details. |
|
12 | :license: GPLv3, see COPYING for more details. | |
13 | """ |
|
13 | """ | |
14 | # This program is free software: you can redistribute it and/or modify |
|
14 | # This program is free software: you can redistribute it and/or modify | |
15 | # it under the terms of the GNU General Public License as published by |
|
15 | # it under the terms of the GNU General Public License as published by | |
16 | # the Free Software Foundation, either version 3 of the License, or |
|
16 | # the Free Software Foundation, either version 3 of the License, or | |
17 | # (at your option) any later version. |
|
17 | # (at your option) any later version. | |
18 | # |
|
18 | # | |
19 | # This program is distributed in the hope that it will be useful, |
|
19 | # This program is distributed in the hope that it will be useful, | |
20 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
20 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
21 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
22 | # GNU General Public License for more details. |
|
22 | # GNU General Public License for more details. | |
23 | # |
|
23 | # | |
24 | # You should have received a copy of the GNU General Public License |
|
24 | # You should have received a copy of the GNU General Public License | |
25 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
25 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
26 |
|
26 | |||
27 | import os |
|
27 | import os | |
28 | import sys |
|
28 | import sys | |
29 | import uuid |
|
29 | import uuid | |
30 | import logging |
|
30 | import logging | |
31 | from os.path import dirname as dn, join as jn |
|
31 | from os.path import dirname as dn, join as jn | |
32 |
|
32 | |||
33 | from rhodecode import __dbversion__, __py_version__ |
|
33 | from rhodecode import __dbversion__, __py_version__ | |
34 |
|
34 | |||
35 | from rhodecode.model.user import UserModel |
|
35 | from rhodecode.model.user import UserModel | |
36 | from rhodecode.lib.utils import ask_ok |
|
36 | from rhodecode.lib.utils import ask_ok | |
37 | from rhodecode.model import init_model |
|
37 | from rhodecode.model import init_model | |
38 | from rhodecode.model.db import User, Permission, RhodeCodeUi, \ |
|
38 | from rhodecode.model.db import User, Permission, RhodeCodeUi, \ | |
39 | RhodeCodeSetting, UserToPerm, DbMigrateVersion, RepoGroup, \ |
|
39 | RhodeCodeSetting, UserToPerm, DbMigrateVersion, RepoGroup, \ | |
40 | UserRepoGroupToPerm |
|
40 | UserRepoGroupToPerm | |
41 |
|
41 | |||
42 | from sqlalchemy.engine import create_engine |
|
42 | from sqlalchemy.engine import create_engine | |
43 | from rhodecode.model.repos_group import ReposGroupModel |
|
43 | from rhodecode.model.repos_group import ReposGroupModel | |
44 | #from rhodecode.model import meta |
|
44 | #from rhodecode.model import meta | |
45 | from rhodecode.model.meta import Session, Base |
|
45 | from rhodecode.model.meta import Session, Base | |
46 |
|
46 | |||
47 |
|
47 | |||
48 | log = logging.getLogger(__name__) |
|
48 | log = logging.getLogger(__name__) | |
49 |
|
49 | |||
50 |
|
50 | |||
51 | def notify(msg): |
|
51 | def notify(msg): | |
52 | """ |
|
52 | """ | |
53 | Notification for migrations messages |
|
53 | Notification for migrations messages | |
54 | """ |
|
54 | """ | |
55 | ml = len(msg) + (4 * 2) |
|
55 | ml = len(msg) + (4 * 2) | |
56 | print >> sys.stdout, ('*** %s ***\n%s' % (msg, '*' * ml)).upper() |
|
56 | print >> sys.stdout, ('*** %s ***\n%s' % (msg, '*' * ml)).upper() | |
57 |
|
57 | |||
58 |
|
58 | |||
59 | class DbManage(object): |
|
59 | class DbManage(object): | |
60 | def __init__(self, log_sql, dbconf, root, tests=False, cli_args={}): |
|
60 | def __init__(self, log_sql, dbconf, root, tests=False, cli_args={}): | |
61 | self.dbname = dbconf.split('/')[-1] |
|
61 | self.dbname = dbconf.split('/')[-1] | |
62 | self.tests = tests |
|
62 | self.tests = tests | |
63 | self.root = root |
|
63 | self.root = root | |
64 | self.dburi = dbconf |
|
64 | self.dburi = dbconf | |
65 | self.log_sql = log_sql |
|
65 | self.log_sql = log_sql | |
66 | self.db_exists = False |
|
66 | self.db_exists = False | |
67 | self.cli_args = cli_args |
|
67 | self.cli_args = cli_args | |
68 | self.init_db() |
|
68 | self.init_db() | |
69 | global ask_ok |
|
69 | global ask_ok | |
70 |
|
70 | |||
71 | if self.cli_args.get('force_ask') is True: |
|
71 | if self.cli_args.get('force_ask') is True: | |
72 | ask_ok = lambda *args, **kwargs: True |
|
72 | ask_ok = lambda *args, **kwargs: True | |
73 | elif self.cli_args.get('force_ask') is False: |
|
73 | elif self.cli_args.get('force_ask') is False: | |
74 | ask_ok = lambda *args, **kwargs: False |
|
74 | ask_ok = lambda *args, **kwargs: False | |
75 |
|
75 | |||
76 | def init_db(self): |
|
76 | def init_db(self): | |
77 | engine = create_engine(self.dburi, echo=self.log_sql) |
|
77 | engine = create_engine(self.dburi, echo=self.log_sql) | |
78 | init_model(engine) |
|
78 | init_model(engine) | |
79 | self.sa = Session() |
|
79 | self.sa = Session() | |
80 |
|
80 | |||
81 | def create_tables(self, override=False): |
|
81 | def create_tables(self, override=False): | |
82 | """ |
|
82 | """ | |
83 | Create a auth database |
|
83 | Create a auth database | |
84 | """ |
|
84 | """ | |
85 |
|
85 | |||
86 | log.info("Any existing database is going to be destroyed") |
|
86 | log.info("Any existing database is going to be destroyed") | |
87 | if self.tests: |
|
87 | if self.tests: | |
88 | destroy = True |
|
88 | destroy = True | |
89 | else: |
|
89 | else: | |
90 | destroy = ask_ok('Are you sure to destroy old database ? [y/n]') |
|
90 | destroy = ask_ok('Are you sure to destroy old database ? [y/n]') | |
91 | if not destroy: |
|
91 | if not destroy: | |
92 | sys.exit('Nothing done') |
|
92 | sys.exit('Nothing done') | |
93 | if destroy: |
|
93 | if destroy: | |
94 | Base.metadata.drop_all() |
|
94 | Base.metadata.drop_all() | |
95 |
|
95 | |||
96 | checkfirst = not override |
|
96 | checkfirst = not override | |
97 | Base.metadata.create_all(checkfirst=checkfirst) |
|
97 | Base.metadata.create_all(checkfirst=checkfirst) | |
98 | log.info('Created tables for %s' % self.dbname) |
|
98 | log.info('Created tables for %s' % self.dbname) | |
99 |
|
99 | |||
100 | def set_db_version(self): |
|
100 | def set_db_version(self): | |
101 | ver = DbMigrateVersion() |
|
101 | ver = DbMigrateVersion() | |
102 | ver.version = __dbversion__ |
|
102 | ver.version = __dbversion__ | |
103 | ver.repository_id = 'rhodecode_db_migrations' |
|
103 | ver.repository_id = 'rhodecode_db_migrations' | |
104 | ver.repository_path = 'versions' |
|
104 | ver.repository_path = 'versions' | |
105 | self.sa.add(ver) |
|
105 | self.sa.add(ver) | |
106 | log.info('db version set to: %s' % __dbversion__) |
|
106 | log.info('db version set to: %s' % __dbversion__) | |
107 |
|
107 | |||
108 | def upgrade(self): |
|
108 | def upgrade(self): | |
109 | """ |
|
109 | """ | |
110 | Upgrades given database schema to given revision following |
|
110 | Upgrades given database schema to given revision following | |
111 | all needed steps, to perform the upgrade |
|
111 | all needed steps, to perform the upgrade | |
112 |
|
112 | |||
113 | """ |
|
113 | """ | |
114 |
|
114 | |||
115 | from rhodecode.lib.dbmigrate.migrate.versioning import api |
|
115 | from rhodecode.lib.dbmigrate.migrate.versioning import api | |
116 | from rhodecode.lib.dbmigrate.migrate.exceptions import \ |
|
116 | from rhodecode.lib.dbmigrate.migrate.exceptions import \ | |
117 | DatabaseNotControlledError |
|
117 | DatabaseNotControlledError | |
118 |
|
118 | |||
119 | if 'sqlite' in self.dburi: |
|
119 | if 'sqlite' in self.dburi: | |
120 | print ( |
|
120 | print ( | |
121 | '********************** WARNING **********************\n' |
|
121 | '********************** WARNING **********************\n' | |
122 | 'Make sure your version of sqlite is at least 3.7.X. \n' |
|
122 | 'Make sure your version of sqlite is at least 3.7.X. \n' | |
123 | 'Earlier versions are known to fail on some migrations\n' |
|
123 | 'Earlier versions are known to fail on some migrations\n' | |
124 | '*****************************************************\n' |
|
124 | '*****************************************************\n' | |
125 | ) |
|
125 | ) | |
126 | upgrade = ask_ok('You are about to perform database upgrade, make ' |
|
126 | upgrade = ask_ok('You are about to perform database upgrade, make ' | |
127 | 'sure You backed up your database before. ' |
|
127 | 'sure You backed up your database before. ' | |
128 | 'Continue ? [y/n]') |
|
128 | 'Continue ? [y/n]') | |
129 | if not upgrade: |
|
129 | if not upgrade: | |
130 | sys.exit('Nothing done') |
|
130 | sys.exit('Nothing done') | |
131 |
|
131 | |||
132 | repository_path = jn(dn(dn(dn(os.path.realpath(__file__)))), |
|
132 | repository_path = jn(dn(dn(dn(os.path.realpath(__file__)))), | |
133 | 'rhodecode/lib/dbmigrate') |
|
133 | 'rhodecode/lib/dbmigrate') | |
134 | db_uri = self.dburi |
|
134 | db_uri = self.dburi | |
135 |
|
135 | |||
136 | try: |
|
136 | try: | |
137 | curr_version = api.db_version(db_uri, repository_path) |
|
137 | curr_version = api.db_version(db_uri, repository_path) | |
138 | msg = ('Found current database under version' |
|
138 | msg = ('Found current database under version' | |
139 | ' control with version %s' % curr_version) |
|
139 | ' control with version %s' % curr_version) | |
140 |
|
140 | |||
141 | except (RuntimeError, DatabaseNotControlledError): |
|
141 | except (RuntimeError, DatabaseNotControlledError): | |
142 | curr_version = 1 |
|
142 | curr_version = 1 | |
143 | msg = ('Current database is not under version control. Setting' |
|
143 | msg = ('Current database is not under version control. Setting' | |
144 | ' as version %s' % curr_version) |
|
144 | ' as version %s' % curr_version) | |
145 | api.version_control(db_uri, repository_path, curr_version) |
|
145 | api.version_control(db_uri, repository_path, curr_version) | |
146 |
|
146 | |||
147 | notify(msg) |
|
147 | notify(msg) | |
148 |
|
148 | |||
149 | if curr_version == __dbversion__: |
|
149 | if curr_version == __dbversion__: | |
150 | sys.exit('This database is already at the newest version') |
|
150 | sys.exit('This database is already at the newest version') | |
151 |
|
151 | |||
152 | #====================================================================== |
|
152 | #====================================================================== | |
153 | # UPGRADE STEPS |
|
153 | # UPGRADE STEPS | |
154 | #====================================================================== |
|
154 | #====================================================================== | |
155 |
|
155 | |||
156 | class UpgradeSteps(object): |
|
156 | class UpgradeSteps(object): | |
157 | """ |
|
157 | """ | |
158 | Those steps follow schema versions so for example schema |
|
158 | Those steps follow schema versions so for example schema | |
159 | for example schema with seq 002 == step_2 and so on. |
|
159 | for example schema with seq 002 == step_2 and so on. | |
160 | """ |
|
160 | """ | |
161 |
|
161 | |||
162 | def __init__(self, klass): |
|
162 | def __init__(self, klass): | |
163 | self.klass = klass |
|
163 | self.klass = klass | |
164 |
|
164 | |||
165 | def step_0(self): |
|
165 | def step_0(self): | |
166 | # step 0 is the schema upgrade, and than follow proper upgrades |
|
166 | # step 0 is the schema upgrade, and than follow proper upgrades | |
167 | notify('attempting to do database upgrade from ' |
|
167 | notify('attempting to do database upgrade from ' | |
168 | 'version %s to version %s' %(curr_version, __dbversion__)) |
|
168 | 'version %s to version %s' %(curr_version, __dbversion__)) | |
169 | api.upgrade(db_uri, repository_path, __dbversion__) |
|
169 | api.upgrade(db_uri, repository_path, __dbversion__) | |
170 | notify('Schema upgrade completed') |
|
170 | notify('Schema upgrade completed') | |
171 |
|
171 | |||
172 | def step_1(self): |
|
172 | def step_1(self): | |
173 | pass |
|
173 | pass | |
174 |
|
174 | |||
175 | def step_2(self): |
|
175 | def step_2(self): | |
176 | notify('Patching repo paths for newer version of RhodeCode') |
|
176 | notify('Patching repo paths for newer version of RhodeCode') | |
177 | self.klass.fix_repo_paths() |
|
177 | self.klass.fix_repo_paths() | |
178 |
|
178 | |||
179 | notify('Patching default user of RhodeCode') |
|
179 | notify('Patching default user of RhodeCode') | |
180 | self.klass.fix_default_user() |
|
180 | self.klass.fix_default_user() | |
181 |
|
181 | |||
182 | log.info('Changing ui settings') |
|
182 | log.info('Changing ui settings') | |
183 | self.klass.create_ui_settings() |
|
183 | self.klass.create_ui_settings() | |
184 |
|
184 | |||
185 | def step_3(self): |
|
185 | def step_3(self): | |
186 | notify('Adding additional settings into RhodeCode db') |
|
186 | notify('Adding additional settings into RhodeCode db') | |
187 | self.klass.fix_settings() |
|
187 | self.klass.fix_settings() | |
188 | notify('Adding ldap defaults') |
|
188 | notify('Adding ldap defaults') | |
189 | self.klass.create_ldap_options(skip_existing=True) |
|
189 | self.klass.create_ldap_options(skip_existing=True) | |
190 |
|
190 | |||
191 | def step_4(self): |
|
191 | def step_4(self): | |
192 | notify('create permissions and fix groups') |
|
192 | notify('create permissions and fix groups') | |
193 | self.klass.create_permissions() |
|
193 | self.klass.create_permissions() | |
194 | self.klass.fixup_groups() |
|
194 | self.klass.fixup_groups() | |
195 |
|
195 | |||
196 | def step_5(self): |
|
196 | def step_5(self): | |
197 | pass |
|
197 | pass | |
198 |
|
198 | |||
199 | def step_6(self): |
|
199 | def step_6(self): | |
200 |
|
200 | |||
201 | notify('re-checking permissions') |
|
201 | notify('re-checking permissions') | |
202 | self.klass.create_permissions() |
|
202 | self.klass.create_permissions() | |
203 |
|
203 | |||
204 | notify('installing new UI options') |
|
204 | notify('installing new UI options') | |
205 | sett4 = RhodeCodeSetting('show_public_icon', True) |
|
205 | sett4 = RhodeCodeSetting('show_public_icon', True) | |
206 | Session().add(sett4) |
|
206 | Session().add(sett4) | |
207 | sett5 = RhodeCodeSetting('show_private_icon', True) |
|
207 | sett5 = RhodeCodeSetting('show_private_icon', True) | |
208 | Session().add(sett5) |
|
208 | Session().add(sett5) | |
209 | sett6 = RhodeCodeSetting('stylify_metatags', False) |
|
209 | sett6 = RhodeCodeSetting('stylify_metatags', False) | |
210 | Session().add(sett6) |
|
210 | Session().add(sett6) | |
211 |
|
211 | |||
212 | notify('fixing old PULL hook') |
|
212 | notify('fixing old PULL hook') | |
213 | _pull = RhodeCodeUi.get_by_key('preoutgoing.pull_logger') |
|
213 | _pull = RhodeCodeUi.get_by_key('preoutgoing.pull_logger') | |
214 | if _pull: |
|
214 | if _pull: | |
215 | _pull.ui_key = RhodeCodeUi.HOOK_PULL |
|
215 | _pull.ui_key = RhodeCodeUi.HOOK_PULL | |
216 | Session().add(_pull) |
|
216 | Session().add(_pull) | |
217 |
|
217 | |||
218 | notify('fixing old PUSH hook') |
|
218 | notify('fixing old PUSH hook') | |
219 | _push = RhodeCodeUi.get_by_key('pretxnchangegroup.push_logger') |
|
219 | _push = RhodeCodeUi.get_by_key('pretxnchangegroup.push_logger') | |
220 | if _push: |
|
220 | if _push: | |
221 | _push.ui_key = RhodeCodeUi.HOOK_PUSH |
|
221 | _push.ui_key = RhodeCodeUi.HOOK_PUSH | |
222 | Session().add(_push) |
|
222 | Session().add(_push) | |
223 |
|
223 | |||
224 | notify('installing new pre-push hook') |
|
224 | notify('installing new pre-push hook') | |
225 | hooks4 = RhodeCodeUi() |
|
225 | hooks4 = RhodeCodeUi() | |
226 | hooks4.ui_section = 'hooks' |
|
226 | hooks4.ui_section = 'hooks' | |
227 | hooks4.ui_key = RhodeCodeUi.HOOK_PRE_PUSH |
|
227 | hooks4.ui_key = RhodeCodeUi.HOOK_PRE_PUSH | |
228 | hooks4.ui_value = 'python:rhodecode.lib.hooks.pre_push' |
|
228 | hooks4.ui_value = 'python:rhodecode.lib.hooks.pre_push' | |
229 | Session().add(hooks4) |
|
229 | Session().add(hooks4) | |
230 |
|
230 | |||
231 | notify('installing new pre-pull hook') |
|
231 | notify('installing new pre-pull hook') | |
232 | hooks6 = RhodeCodeUi() |
|
232 | hooks6 = RhodeCodeUi() | |
233 | hooks6.ui_section = 'hooks' |
|
233 | hooks6.ui_section = 'hooks' | |
234 | hooks6.ui_key = RhodeCodeUi.HOOK_PRE_PULL |
|
234 | hooks6.ui_key = RhodeCodeUi.HOOK_PRE_PULL | |
235 | hooks6.ui_value = 'python:rhodecode.lib.hooks.pre_pull' |
|
235 | hooks6.ui_value = 'python:rhodecode.lib.hooks.pre_pull' | |
236 | Session().add(hooks6) |
|
236 | Session().add(hooks6) | |
237 |
|
237 | |||
238 | notify('installing hgsubversion option') |
|
238 | notify('installing hgsubversion option') | |
239 | # enable hgsubversion disabled by default |
|
239 | # enable hgsubversion disabled by default | |
240 | hgsubversion = RhodeCodeUi() |
|
240 | hgsubversion = RhodeCodeUi() | |
241 | hgsubversion.ui_section = 'extensions' |
|
241 | hgsubversion.ui_section = 'extensions' | |
242 | hgsubversion.ui_key = 'hgsubversion' |
|
242 | hgsubversion.ui_key = 'hgsubversion' | |
243 | hgsubversion.ui_value = '' |
|
243 | hgsubversion.ui_value = '' | |
244 | hgsubversion.ui_active = False |
|
244 | hgsubversion.ui_active = False | |
245 | Session().add(hgsubversion) |
|
245 | Session().add(hgsubversion) | |
246 |
|
246 | |||
247 | notify('installing hg git option') |
|
247 | notify('installing hg git option') | |
248 | # enable hggit disabled by default |
|
248 | # enable hggit disabled by default | |
249 | hggit = RhodeCodeUi() |
|
249 | hggit = RhodeCodeUi() | |
250 | hggit.ui_section = 'extensions' |
|
250 | hggit.ui_section = 'extensions' | |
251 | hggit.ui_key = 'hggit' |
|
251 | hggit.ui_key = 'hggit' | |
252 | hggit.ui_value = '' |
|
252 | hggit.ui_value = '' | |
253 | hggit.ui_active = False |
|
253 | hggit.ui_active = False | |
254 | Session().add(hggit) |
|
254 | Session().add(hggit) | |
255 |
|
255 | |||
256 | notify('re-check default permissions') |
|
256 | notify('re-check default permissions') | |
257 | default_user = User.get_by_username(User.DEFAULT_USER) |
|
257 | default_user = User.get_by_username(User.DEFAULT_USER) | |
258 | perm = Permission.get_by_key('hg.fork.repository') |
|
258 | perm = Permission.get_by_key('hg.fork.repository') | |
259 | reg_perm = UserToPerm() |
|
259 | reg_perm = UserToPerm() | |
260 | reg_perm.user = default_user |
|
260 | reg_perm.user = default_user | |
261 | reg_perm.permission = perm |
|
261 | reg_perm.permission = perm | |
262 | Session().add(reg_perm) |
|
262 | Session().add(reg_perm) | |
263 |
|
263 | |||
264 | def step_7(self): |
|
264 | def step_7(self): | |
265 | perm_fixes = self.klass.reset_permissions(User.DEFAULT_USER) |
|
265 | perm_fixes = self.klass.reset_permissions(User.DEFAULT_USER) | |
266 | Session().commit() |
|
266 | Session().commit() | |
267 | if perm_fixes: |
|
267 | if perm_fixes: | |
268 | notify('There was an inconsistent state of permissions ' |
|
268 | notify('There was an inconsistent state of permissions ' | |
269 | 'detected for default user. Permissions are now ' |
|
269 | 'detected for default user. Permissions are now ' | |
270 | 'reset to the default value for default user. ' |
|
270 | 'reset to the default value for default user. ' | |
271 | 'Please validate and check default permissions ' |
|
271 | 'Please validate and check default permissions ' | |
272 | 'in admin panel') |
|
272 | 'in admin panel') | |
273 |
|
273 | |||
274 | def step_8(self): |
|
274 | def step_8(self): | |
275 | self.klass.populate_default_permissions() |
|
275 | self.klass.populate_default_permissions() | |
276 | self.klass.create_default_options(skip_existing=True) |
|
276 | self.klass.create_default_options(skip_existing=True) | |
277 | Session().commit() |
|
277 | Session().commit() | |
278 |
|
278 | |||
279 | def step_9(self): |
|
279 | def step_9(self): | |
280 | perm_fixes = self.klass.reset_permissions(User.DEFAULT_USER) |
|
280 | perm_fixes = self.klass.reset_permissions(User.DEFAULT_USER) | |
281 | Session().commit() |
|
281 | Session().commit() | |
282 | if perm_fixes: |
|
282 | if perm_fixes: | |
283 | notify('There was an inconsistent state of permissions ' |
|
283 | notify('There was an inconsistent state of permissions ' | |
284 | 'detected for default user. Permissions are now ' |
|
284 | 'detected for default user. Permissions are now ' | |
285 | 'reset to the default value for default user. ' |
|
285 | 'reset to the default value for default user. ' | |
286 | 'Please validate and check default permissions ' |
|
286 | 'Please validate and check default permissions ' | |
287 | 'in admin panel') |
|
287 | 'in admin panel') | |
288 |
|
288 | |||
289 | def step_10(self): |
|
289 | def step_10(self): | |
290 | pass |
|
290 | pass | |
291 |
|
291 | |||
292 | upgrade_steps = [0] + range(curr_version + 1, __dbversion__ + 1) |
|
292 | upgrade_steps = [0] + range(curr_version + 1, __dbversion__ + 1) | |
293 |
|
293 | |||
294 | # CALL THE PROPER ORDER OF STEPS TO PERFORM FULL UPGRADE |
|
294 | # CALL THE PROPER ORDER OF STEPS TO PERFORM FULL UPGRADE | |
295 | _step = None |
|
295 | _step = None | |
296 | for step in upgrade_steps: |
|
296 | for step in upgrade_steps: | |
297 | notify('performing upgrade step %s' % step) |
|
297 | notify('performing upgrade step %s' % step) | |
298 | getattr(UpgradeSteps(self), 'step_%s' % step)() |
|
298 | getattr(UpgradeSteps(self), 'step_%s' % step)() | |
299 | self.sa.commit() |
|
299 | self.sa.commit() | |
300 | _step = step |
|
300 | _step = step | |
301 |
|
301 | |||
302 | notify('upgrade to version %s successful' % _step) |
|
302 | notify('upgrade to version %s successful' % _step) | |
303 |
|
303 | |||
304 | def fix_repo_paths(self): |
|
304 | def fix_repo_paths(self): | |
305 | """ |
|
305 | """ | |
306 | Fixes a old rhodecode version path into new one without a '*' |
|
306 | Fixes a old rhodecode version path into new one without a '*' | |
307 | """ |
|
307 | """ | |
308 |
|
308 | |||
309 | paths = self.sa.query(RhodeCodeUi)\ |
|
309 | paths = self.sa.query(RhodeCodeUi)\ | |
310 | .filter(RhodeCodeUi.ui_key == '/')\ |
|
310 | .filter(RhodeCodeUi.ui_key == '/')\ | |
311 | .scalar() |
|
311 | .scalar() | |
312 |
|
312 | |||
313 | paths.ui_value = paths.ui_value.replace('*', '') |
|
313 | paths.ui_value = paths.ui_value.replace('*', '') | |
314 |
|
314 | |||
315 | try: |
|
315 | try: | |
316 | self.sa.add(paths) |
|
316 | self.sa.add(paths) | |
317 | self.sa.commit() |
|
317 | self.sa.commit() | |
318 | except: |
|
318 | except: | |
319 | self.sa.rollback() |
|
319 | self.sa.rollback() | |
320 | raise |
|
320 | raise | |
321 |
|
321 | |||
322 | def fix_default_user(self): |
|
322 | def fix_default_user(self): | |
323 | """ |
|
323 | """ | |
324 | Fixes a old default user with some 'nicer' default values, |
|
324 | Fixes a old default user with some 'nicer' default values, | |
325 | used mostly for anonymous access |
|
325 | used mostly for anonymous access | |
326 | """ |
|
326 | """ | |
327 | def_user = self.sa.query(User)\ |
|
327 | def_user = self.sa.query(User)\ | |
328 | .filter(User.username == 'default')\ |
|
328 | .filter(User.username == 'default')\ | |
329 | .one() |
|
329 | .one() | |
330 |
|
330 | |||
331 | def_user.name = 'Anonymous' |
|
331 | def_user.name = 'Anonymous' | |
332 | def_user.lastname = 'User' |
|
332 | def_user.lastname = 'User' | |
333 | def_user.email = 'anonymous@rhodecode.org' |
|
333 | def_user.email = 'anonymous@rhodecode.org' | |
334 |
|
334 | |||
335 | try: |
|
335 | try: | |
336 | self.sa.add(def_user) |
|
336 | self.sa.add(def_user) | |
337 | self.sa.commit() |
|
337 | self.sa.commit() | |
338 | except: |
|
338 | except: | |
339 | self.sa.rollback() |
|
339 | self.sa.rollback() | |
340 | raise |
|
340 | raise | |
341 |
|
341 | |||
342 | def fix_settings(self): |
|
342 | def fix_settings(self): | |
343 | """ |
|
343 | """ | |
344 | Fixes rhodecode settings adds ga_code key for google analytics |
|
344 | Fixes rhodecode settings adds ga_code key for google analytics | |
345 | """ |
|
345 | """ | |
346 |
|
346 | |||
347 | hgsettings3 = RhodeCodeSetting('ga_code', '') |
|
347 | hgsettings3 = RhodeCodeSetting('ga_code', '') | |
348 |
|
348 | |||
349 | try: |
|
349 | try: | |
350 | self.sa.add(hgsettings3) |
|
350 | self.sa.add(hgsettings3) | |
351 | self.sa.commit() |
|
351 | self.sa.commit() | |
352 | except: |
|
352 | except: | |
353 | self.sa.rollback() |
|
353 | self.sa.rollback() | |
354 | raise |
|
354 | raise | |
355 |
|
355 | |||
356 | def admin_prompt(self, second=False): |
|
356 | def admin_prompt(self, second=False): | |
357 | if not self.tests: |
|
357 | if not self.tests: | |
358 | import getpass |
|
358 | import getpass | |
359 |
|
359 | |||
360 | # defaults |
|
360 | # defaults | |
361 | defaults = self.cli_args |
|
361 | defaults = self.cli_args | |
362 | username = defaults.get('username') |
|
362 | username = defaults.get('username') | |
363 | password = defaults.get('password') |
|
363 | password = defaults.get('password') | |
364 | email = defaults.get('email') |
|
364 | email = defaults.get('email') | |
365 |
|
365 | |||
366 | def get_password(): |
|
366 | def get_password(): | |
367 | password = getpass.getpass('Specify admin password ' |
|
367 | password = getpass.getpass('Specify admin password ' | |
368 | '(min 6 chars):') |
|
368 | '(min 6 chars):') | |
369 | confirm = getpass.getpass('Confirm password:') |
|
369 | confirm = getpass.getpass('Confirm password:') | |
370 |
|
370 | |||
371 | if password != confirm: |
|
371 | if password != confirm: | |
372 | log.error('passwords mismatch') |
|
372 | log.error('passwords mismatch') | |
373 | return False |
|
373 | return False | |
374 | if len(password) < 6: |
|
374 | if len(password) < 6: | |
375 | log.error('password is to short use at least 6 characters') |
|
375 | log.error('password is to short use at least 6 characters') | |
376 | return False |
|
376 | return False | |
377 |
|
377 | |||
378 | return password |
|
378 | return password | |
379 | if username is None: |
|
379 | if username is None: | |
380 | username = raw_input('Specify admin username:') |
|
380 | username = raw_input('Specify admin username:') | |
381 | if password is None: |
|
381 | if password is None: | |
382 | password = get_password() |
|
382 | password = get_password() | |
383 | if not password: |
|
383 | if not password: | |
384 | #second try |
|
384 | #second try | |
385 | password = get_password() |
|
385 | password = get_password() | |
386 | if not password: |
|
386 | if not password: | |
387 | sys.exit() |
|
387 | sys.exit() | |
388 | if email is None: |
|
388 | if email is None: | |
389 | email = raw_input('Specify admin email:') |
|
389 | email = raw_input('Specify admin email:') | |
390 | self.create_user(username, password, email, True) |
|
390 | self.create_user(username, password, email, True) | |
391 | else: |
|
391 | else: | |
392 | log.info('creating admin and regular test users') |
|
392 | log.info('creating admin and regular test users') | |
393 | from rhodecode.tests import TEST_USER_ADMIN_LOGIN, \ |
|
393 | from rhodecode.tests import TEST_USER_ADMIN_LOGIN, \ | |
394 | TEST_USER_ADMIN_PASS, TEST_USER_ADMIN_EMAIL, \ |
|
394 | TEST_USER_ADMIN_PASS, TEST_USER_ADMIN_EMAIL, \ | |
395 | TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS, \ |
|
395 | TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS, \ | |
396 | TEST_USER_REGULAR_EMAIL, TEST_USER_REGULAR2_LOGIN, \ |
|
396 | TEST_USER_REGULAR_EMAIL, TEST_USER_REGULAR2_LOGIN, \ | |
397 | TEST_USER_REGULAR2_PASS, TEST_USER_REGULAR2_EMAIL |
|
397 | TEST_USER_REGULAR2_PASS, TEST_USER_REGULAR2_EMAIL | |
398 |
|
398 | |||
399 | self.create_user(TEST_USER_ADMIN_LOGIN, TEST_USER_ADMIN_PASS, |
|
399 | self.create_user(TEST_USER_ADMIN_LOGIN, TEST_USER_ADMIN_PASS, | |
400 | TEST_USER_ADMIN_EMAIL, True) |
|
400 | TEST_USER_ADMIN_EMAIL, True) | |
401 |
|
401 | |||
402 | self.create_user(TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS, |
|
402 | self.create_user(TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS, | |
403 | TEST_USER_REGULAR_EMAIL, False) |
|
403 | TEST_USER_REGULAR_EMAIL, False) | |
404 |
|
404 | |||
405 | self.create_user(TEST_USER_REGULAR2_LOGIN, TEST_USER_REGULAR2_PASS, |
|
405 | self.create_user(TEST_USER_REGULAR2_LOGIN, TEST_USER_REGULAR2_PASS, | |
406 | TEST_USER_REGULAR2_EMAIL, False) |
|
406 | TEST_USER_REGULAR2_EMAIL, False) | |
407 |
|
407 | |||
408 | def create_ui_settings(self): |
|
408 | def create_ui_settings(self): | |
409 | """ |
|
409 | """ | |
410 | Creates ui settings, fills out hooks |
|
410 | Creates ui settings, fills out hooks | |
411 | and disables dotencode |
|
411 | and disables dotencode | |
412 | """ |
|
412 | """ | |
413 |
|
413 | |||
414 | #HOOKS |
|
414 | #HOOKS | |
415 | hooks1_key = RhodeCodeUi.HOOK_UPDATE |
|
415 | hooks1_key = RhodeCodeUi.HOOK_UPDATE | |
416 | hooks1_ = self.sa.query(RhodeCodeUi)\ |
|
416 | hooks1_ = self.sa.query(RhodeCodeUi)\ | |
417 | .filter(RhodeCodeUi.ui_key == hooks1_key).scalar() |
|
417 | .filter(RhodeCodeUi.ui_key == hooks1_key).scalar() | |
418 |
|
418 | |||
419 | hooks1 = RhodeCodeUi() if hooks1_ is None else hooks1_ |
|
419 | hooks1 = RhodeCodeUi() if hooks1_ is None else hooks1_ | |
420 | hooks1.ui_section = 'hooks' |
|
420 | hooks1.ui_section = 'hooks' | |
421 | hooks1.ui_key = hooks1_key |
|
421 | hooks1.ui_key = hooks1_key | |
422 | hooks1.ui_value = 'hg update >&2' |
|
422 | hooks1.ui_value = 'hg update >&2' | |
423 | hooks1.ui_active = False |
|
423 | hooks1.ui_active = False | |
424 | self.sa.add(hooks1) |
|
424 | self.sa.add(hooks1) | |
425 |
|
425 | |||
426 | hooks2_key = RhodeCodeUi.HOOK_REPO_SIZE |
|
426 | hooks2_key = RhodeCodeUi.HOOK_REPO_SIZE | |
427 | hooks2_ = self.sa.query(RhodeCodeUi)\ |
|
427 | hooks2_ = self.sa.query(RhodeCodeUi)\ | |
428 | .filter(RhodeCodeUi.ui_key == hooks2_key).scalar() |
|
428 | .filter(RhodeCodeUi.ui_key == hooks2_key).scalar() | |
429 | hooks2 = RhodeCodeUi() if hooks2_ is None else hooks2_ |
|
429 | hooks2 = RhodeCodeUi() if hooks2_ is None else hooks2_ | |
430 | hooks2.ui_section = 'hooks' |
|
430 | hooks2.ui_section = 'hooks' | |
431 | hooks2.ui_key = hooks2_key |
|
431 | hooks2.ui_key = hooks2_key | |
432 | hooks2.ui_value = 'python:rhodecode.lib.hooks.repo_size' |
|
432 | hooks2.ui_value = 'python:rhodecode.lib.hooks.repo_size' | |
433 | self.sa.add(hooks2) |
|
433 | self.sa.add(hooks2) | |
434 |
|
434 | |||
435 | hooks3 = RhodeCodeUi() |
|
435 | hooks3 = RhodeCodeUi() | |
436 | hooks3.ui_section = 'hooks' |
|
436 | hooks3.ui_section = 'hooks' | |
437 | hooks3.ui_key = RhodeCodeUi.HOOK_PUSH |
|
437 | hooks3.ui_key = RhodeCodeUi.HOOK_PUSH | |
438 | hooks3.ui_value = 'python:rhodecode.lib.hooks.log_push_action' |
|
438 | hooks3.ui_value = 'python:rhodecode.lib.hooks.log_push_action' | |
439 | self.sa.add(hooks3) |
|
439 | self.sa.add(hooks3) | |
440 |
|
440 | |||
441 | hooks4 = RhodeCodeUi() |
|
441 | hooks4 = RhodeCodeUi() | |
442 | hooks4.ui_section = 'hooks' |
|
442 | hooks4.ui_section = 'hooks' | |
443 | hooks4.ui_key = RhodeCodeUi.HOOK_PRE_PUSH |
|
443 | hooks4.ui_key = RhodeCodeUi.HOOK_PRE_PUSH | |
444 | hooks4.ui_value = 'python:rhodecode.lib.hooks.pre_push' |
|
444 | hooks4.ui_value = 'python:rhodecode.lib.hooks.pre_push' | |
445 | self.sa.add(hooks4) |
|
445 | self.sa.add(hooks4) | |
446 |
|
446 | |||
447 | hooks5 = RhodeCodeUi() |
|
447 | hooks5 = RhodeCodeUi() | |
448 | hooks5.ui_section = 'hooks' |
|
448 | hooks5.ui_section = 'hooks' | |
449 | hooks5.ui_key = RhodeCodeUi.HOOK_PULL |
|
449 | hooks5.ui_key = RhodeCodeUi.HOOK_PULL | |
450 | hooks5.ui_value = 'python:rhodecode.lib.hooks.log_pull_action' |
|
450 | hooks5.ui_value = 'python:rhodecode.lib.hooks.log_pull_action' | |
451 | self.sa.add(hooks5) |
|
451 | self.sa.add(hooks5) | |
452 |
|
452 | |||
453 | hooks6 = RhodeCodeUi() |
|
453 | hooks6 = RhodeCodeUi() | |
454 | hooks6.ui_section = 'hooks' |
|
454 | hooks6.ui_section = 'hooks' | |
455 | hooks6.ui_key = RhodeCodeUi.HOOK_PRE_PULL |
|
455 | hooks6.ui_key = RhodeCodeUi.HOOK_PRE_PULL | |
456 | hooks6.ui_value = 'python:rhodecode.lib.hooks.pre_pull' |
|
456 | hooks6.ui_value = 'python:rhodecode.lib.hooks.pre_pull' | |
457 | self.sa.add(hooks6) |
|
457 | self.sa.add(hooks6) | |
458 |
|
458 | |||
459 | # enable largefiles |
|
459 | # enable largefiles | |
460 | largefiles = RhodeCodeUi() |
|
460 | largefiles = RhodeCodeUi() | |
461 | largefiles.ui_section = 'extensions' |
|
461 | largefiles.ui_section = 'extensions' | |
462 | largefiles.ui_key = 'largefiles' |
|
462 | largefiles.ui_key = 'largefiles' | |
463 | largefiles.ui_value = '' |
|
463 | largefiles.ui_value = '' | |
464 | self.sa.add(largefiles) |
|
464 | self.sa.add(largefiles) | |
465 |
|
465 | |||
466 | # enable hgsubversion disabled by default |
|
466 | # enable hgsubversion disabled by default | |
467 | hgsubversion = RhodeCodeUi() |
|
467 | hgsubversion = RhodeCodeUi() | |
468 | hgsubversion.ui_section = 'extensions' |
|
468 | hgsubversion.ui_section = 'extensions' | |
469 | hgsubversion.ui_key = 'hgsubversion' |
|
469 | hgsubversion.ui_key = 'hgsubversion' | |
470 | hgsubversion.ui_value = '' |
|
470 | hgsubversion.ui_value = '' | |
471 | hgsubversion.ui_active = False |
|
471 | hgsubversion.ui_active = False | |
472 | self.sa.add(hgsubversion) |
|
472 | self.sa.add(hgsubversion) | |
473 |
|
473 | |||
474 | # enable hggit disabled by default |
|
474 | # enable hggit disabled by default | |
475 | hggit = RhodeCodeUi() |
|
475 | hggit = RhodeCodeUi() | |
476 | hggit.ui_section = 'extensions' |
|
476 | hggit.ui_section = 'extensions' | |
477 | hggit.ui_key = 'hggit' |
|
477 | hggit.ui_key = 'hggit' | |
478 | hggit.ui_value = '' |
|
478 | hggit.ui_value = '' | |
479 | hggit.ui_active = False |
|
479 | hggit.ui_active = False | |
480 | self.sa.add(hggit) |
|
480 | self.sa.add(hggit) | |
481 |
|
481 | |||
482 | def create_ldap_options(self, skip_existing=False): |
|
482 | def create_ldap_options(self, skip_existing=False): | |
483 | """Creates ldap settings""" |
|
483 | """Creates ldap settings""" | |
484 |
|
484 | |||
485 | for k, v in [('ldap_active', 'false'), ('ldap_host', ''), |
|
485 | for k, v in [('ldap_active', 'false'), ('ldap_host', ''), | |
486 | ('ldap_port', '389'), ('ldap_tls_kind', 'PLAIN'), |
|
486 | ('ldap_port', '389'), ('ldap_tls_kind', 'PLAIN'), | |
487 | ('ldap_tls_reqcert', ''), ('ldap_dn_user', ''), |
|
487 | ('ldap_tls_reqcert', ''), ('ldap_dn_user', ''), | |
488 | ('ldap_dn_pass', ''), ('ldap_base_dn', ''), |
|
488 | ('ldap_dn_pass', ''), ('ldap_base_dn', ''), | |
489 | ('ldap_filter', ''), ('ldap_search_scope', ''), |
|
489 | ('ldap_filter', ''), ('ldap_search_scope', ''), | |
490 | ('ldap_attr_login', ''), ('ldap_attr_firstname', ''), |
|
490 | ('ldap_attr_login', ''), ('ldap_attr_firstname', ''), | |
491 | ('ldap_attr_lastname', ''), ('ldap_attr_email', '')]: |
|
491 | ('ldap_attr_lastname', ''), ('ldap_attr_email', '')]: | |
492 |
|
492 | |||
493 | if skip_existing and RhodeCodeSetting.get_by_name(k) != None: |
|
493 | if skip_existing and RhodeCodeSetting.get_by_name(k) != None: | |
494 | log.debug('Skipping option %s' % k) |
|
494 | log.debug('Skipping option %s' % k) | |
495 | continue |
|
495 | continue | |
496 | setting = RhodeCodeSetting(k, v) |
|
496 | setting = RhodeCodeSetting(k, v) | |
497 | self.sa.add(setting) |
|
497 | self.sa.add(setting) | |
498 |
|
498 | |||
499 | def create_default_options(self, skip_existing=False): |
|
499 | def create_default_options(self, skip_existing=False): | |
500 | """Creates default settings""" |
|
500 | """Creates default settings""" | |
501 |
|
501 | |||
502 | for k, v in [ |
|
502 | for k, v in [ | |
503 | ('default_repo_enable_locking', False), |
|
503 | ('default_repo_enable_locking', False), | |
504 | ('default_repo_enable_downloads', False), |
|
504 | ('default_repo_enable_downloads', False), | |
505 | ('default_repo_enable_statistics', False), |
|
505 | ('default_repo_enable_statistics', False), | |
506 | ('default_repo_private', False), |
|
506 | ('default_repo_private', False), | |
507 | ('default_repo_type', 'hg')]: |
|
507 | ('default_repo_type', 'hg')]: | |
508 |
|
508 | |||
509 | if skip_existing and RhodeCodeSetting.get_by_name(k) != None: |
|
509 | if skip_existing and RhodeCodeSetting.get_by_name(k) != None: | |
510 | log.debug('Skipping option %s' % k) |
|
510 | log.debug('Skipping option %s' % k) | |
511 | continue |
|
511 | continue | |
512 | setting = RhodeCodeSetting(k, v) |
|
512 | setting = RhodeCodeSetting(k, v) | |
513 | self.sa.add(setting) |
|
513 | self.sa.add(setting) | |
514 |
|
514 | |||
515 | def fixup_groups(self): |
|
515 | def fixup_groups(self): | |
516 | def_usr = User.get_by_username('default') |
|
516 | def_usr = User.get_by_username('default') | |
517 | for g in RepoGroup.query().all(): |
|
517 | for g in RepoGroup.query().all(): | |
518 | g.group_name = g.get_new_name(g.name) |
|
518 | g.group_name = g.get_new_name(g.name) | |
519 | self.sa.add(g) |
|
519 | self.sa.add(g) | |
520 | # get default perm |
|
520 | # get default perm | |
521 | default = UserRepoGroupToPerm.query()\ |
|
521 | default = UserRepoGroupToPerm.query()\ | |
522 | .filter(UserRepoGroupToPerm.group == g)\ |
|
522 | .filter(UserRepoGroupToPerm.group == g)\ | |
523 | .filter(UserRepoGroupToPerm.user == def_usr)\ |
|
523 | .filter(UserRepoGroupToPerm.user == def_usr)\ | |
524 | .scalar() |
|
524 | .scalar() | |
525 |
|
525 | |||
526 | if default is None: |
|
526 | if default is None: | |
527 | log.debug('missing default permission for group %s adding' % g) |
|
527 | log.debug('missing default permission for group %s adding' % g) | |
528 | ReposGroupModel()._create_default_perms(g) |
|
528 | ReposGroupModel()._create_default_perms(g) | |
529 |
|
529 | |||
530 | def reset_permissions(self, username): |
|
530 | def reset_permissions(self, username): | |
531 | """ |
|
531 | """ | |
532 | Resets permissions to default state, usefull when old systems had |
|
532 | Resets permissions to default state, usefull when old systems had | |
533 | bad permissions, we must clean them up |
|
533 | bad permissions, we must clean them up | |
534 |
|
534 | |||
535 | :param username: |
|
535 | :param username: | |
536 | :type username: |
|
536 | :type username: | |
537 | """ |
|
537 | """ | |
538 | default_user = User.get_by_username(username) |
|
538 | default_user = User.get_by_username(username) | |
539 | if not default_user: |
|
539 | if not default_user: | |
540 | return |
|
540 | return | |
541 |
|
541 | |||
542 | u2p = UserToPerm.query()\ |
|
542 | u2p = UserToPerm.query()\ | |
543 | .filter(UserToPerm.user == default_user).all() |
|
543 | .filter(UserToPerm.user == default_user).all() | |
544 | fixed = False |
|
544 | fixed = False | |
545 | if len(u2p) != len(User.DEFAULT_PERMISSIONS): |
|
545 | if len(u2p) != len(User.DEFAULT_PERMISSIONS): | |
546 | for p in u2p: |
|
546 | for p in u2p: | |
547 | Session().delete(p) |
|
547 | Session().delete(p) | |
548 | fixed = True |
|
548 | fixed = True | |
549 | self.populate_default_permissions() |
|
549 | self.populate_default_permissions() | |
550 | return fixed |
|
550 | return fixed | |
551 |
|
551 | |||
552 | def config_prompt(self, test_repo_path='', retries=3): |
|
552 | def config_prompt(self, test_repo_path='', retries=3): | |
553 | defaults = self.cli_args |
|
553 | defaults = self.cli_args | |
554 | _path = defaults.get('repos_location') |
|
554 | _path = defaults.get('repos_location') | |
555 | if retries == 3: |
|
555 | if retries == 3: | |
556 | log.info('Setting up repositories config') |
|
556 | log.info('Setting up repositories config') | |
557 |
|
557 | |||
558 | if _path is not None: |
|
558 | if _path is not None: | |
559 | path = _path |
|
559 | path = _path | |
560 | elif not self.tests and not test_repo_path: |
|
560 | elif not self.tests and not test_repo_path: | |
561 | path = raw_input( |
|
561 | path = raw_input( | |
562 | 'Enter a valid absolute path to store repositories. ' |
|
562 | 'Enter a valid absolute path to store repositories. ' | |
563 | 'All repositories in that path will be added automatically:' |
|
563 | 'All repositories in that path will be added automatically:' | |
564 | ) |
|
564 | ) | |
565 | else: |
|
565 | else: | |
566 | path = test_repo_path |
|
566 | path = test_repo_path | |
567 | path_ok = True |
|
567 | path_ok = True | |
568 |
|
568 | |||
569 | # check proper dir |
|
569 | # check proper dir | |
570 | if not os.path.isdir(path): |
|
570 | if not os.path.isdir(path): | |
571 | path_ok = False |
|
571 | path_ok = False | |
572 | log.error('Given path %s is not a valid directory' % path) |
|
572 | log.error('Given path %s is not a valid directory' % path) | |
573 |
|
573 | |||
574 | elif not os.path.isabs(path): |
|
574 | elif not os.path.isabs(path): | |
575 | path_ok = False |
|
575 | path_ok = False | |
576 | log.error('Given path %s is not an absolute path' % path) |
|
576 | log.error('Given path %s is not an absolute path' % path) | |
577 |
|
577 | |||
578 | # check write access |
|
578 | # check write access | |
579 | elif not os.access(path, os.W_OK) and path_ok: |
|
579 | elif not os.access(path, os.W_OK) and path_ok: | |
580 | path_ok = False |
|
580 | path_ok = False | |
581 | log.error('No write permission to given path %s' % path) |
|
581 | log.error('No write permission to given path %s' % path) | |
582 |
|
582 | |||
583 | if retries == 0: |
|
583 | if retries == 0: | |
584 | sys.exit('max retries reached') |
|
584 | sys.exit('max retries reached') | |
585 | if path_ok is False: |
|
585 | if path_ok is False: | |
586 | retries -= 1 |
|
586 | retries -= 1 | |
587 | return self.config_prompt(test_repo_path, retries) |
|
587 | return self.config_prompt(test_repo_path, retries) | |
588 |
|
588 | |||
589 | real_path = os.path.normpath(os.path.realpath(path)) |
|
589 | real_path = os.path.normpath(os.path.realpath(path)) | |
590 |
|
590 | |||
591 | if real_path != os.path.normpath(path): |
|
591 | if real_path != os.path.normpath(path): | |
592 | if not ask_ok(('Path looks like a symlink, Rhodecode will store ' |
|
592 | if not ask_ok(('Path looks like a symlink, Rhodecode will store ' | |
593 | 'given path as %s ? [y/n]') % (real_path)): |
|
593 | 'given path as %s ? [y/n]') % (real_path)): | |
594 | log.error('Canceled by user') |
|
594 | log.error('Canceled by user') | |
595 | sys.exit(-1) |
|
595 | sys.exit(-1) | |
596 |
|
596 | |||
597 | return real_path |
|
597 | return real_path | |
598 |
|
598 | |||
599 | def create_settings(self, path): |
|
599 | def create_settings(self, path): | |
600 |
|
600 | |||
601 | self.create_ui_settings() |
|
601 | self.create_ui_settings() | |
602 |
|
602 | |||
603 | #HG UI OPTIONS |
|
603 | #HG UI OPTIONS | |
604 | web1 = RhodeCodeUi() |
|
604 | web1 = RhodeCodeUi() | |
605 | web1.ui_section = 'web' |
|
605 | web1.ui_section = 'web' | |
606 | web1.ui_key = 'push_ssl' |
|
606 | web1.ui_key = 'push_ssl' | |
607 | web1.ui_value = 'false' |
|
607 | web1.ui_value = 'false' | |
608 |
|
608 | |||
609 | web2 = RhodeCodeUi() |
|
609 | web2 = RhodeCodeUi() | |
610 | web2.ui_section = 'web' |
|
610 | web2.ui_section = 'web' | |
611 | web2.ui_key = 'allow_archive' |
|
611 | web2.ui_key = 'allow_archive' | |
612 | web2.ui_value = 'gz zip bz2' |
|
612 | web2.ui_value = 'gz zip bz2' | |
613 |
|
613 | |||
614 | web3 = RhodeCodeUi() |
|
614 | web3 = RhodeCodeUi() | |
615 | web3.ui_section = 'web' |
|
615 | web3.ui_section = 'web' | |
616 | web3.ui_key = 'allow_push' |
|
616 | web3.ui_key = 'allow_push' | |
617 | web3.ui_value = '*' |
|
617 | web3.ui_value = '*' | |
618 |
|
618 | |||
619 | web4 = RhodeCodeUi() |
|
619 | web4 = RhodeCodeUi() | |
620 | web4.ui_section = 'web' |
|
620 | web4.ui_section = 'web' | |
621 | web4.ui_key = 'baseurl' |
|
621 | web4.ui_key = 'baseurl' | |
622 | web4.ui_value = '/' |
|
622 | web4.ui_value = '/' | |
623 |
|
623 | |||
624 | paths = RhodeCodeUi() |
|
624 | paths = RhodeCodeUi() | |
625 | paths.ui_section = 'paths' |
|
625 | paths.ui_section = 'paths' | |
626 | paths.ui_key = '/' |
|
626 | paths.ui_key = '/' | |
627 | paths.ui_value = path |
|
627 | paths.ui_value = path | |
628 |
|
628 | |||
629 | phases = RhodeCodeUi() |
|
629 | phases = RhodeCodeUi() | |
630 | phases.ui_section = 'phases' |
|
630 | phases.ui_section = 'phases' | |
631 | phases.ui_key = 'publish' |
|
631 | phases.ui_key = 'publish' | |
632 | phases.ui_value = False |
|
632 | phases.ui_value = False | |
633 |
|
633 | |||
634 | sett1 = RhodeCodeSetting('realm', 'RhodeCode authentication') |
|
634 | sett1 = RhodeCodeSetting('realm', 'RhodeCode authentication') | |
635 | sett2 = RhodeCodeSetting('title', 'RhodeCode') |
|
635 | sett2 = RhodeCodeSetting('title', 'RhodeCode') | |
636 | sett3 = RhodeCodeSetting('ga_code', '') |
|
636 | sett3 = RhodeCodeSetting('ga_code', '') | |
637 |
|
637 | |||
638 | sett4 = RhodeCodeSetting('show_public_icon', True) |
|
638 | sett4 = RhodeCodeSetting('show_public_icon', True) | |
639 | sett5 = RhodeCodeSetting('show_private_icon', True) |
|
639 | sett5 = RhodeCodeSetting('show_private_icon', True) | |
640 | sett6 = RhodeCodeSetting('stylify_metatags', False) |
|
640 | sett6 = RhodeCodeSetting('stylify_metatags', False) | |
641 |
|
641 | |||
642 | self.sa.add(web1) |
|
642 | self.sa.add(web1) | |
643 | self.sa.add(web2) |
|
643 | self.sa.add(web2) | |
644 | self.sa.add(web3) |
|
644 | self.sa.add(web3) | |
645 | self.sa.add(web4) |
|
645 | self.sa.add(web4) | |
646 | self.sa.add(paths) |
|
646 | self.sa.add(paths) | |
647 | self.sa.add(sett1) |
|
647 | self.sa.add(sett1) | |
648 | self.sa.add(sett2) |
|
648 | self.sa.add(sett2) | |
649 | self.sa.add(sett3) |
|
649 | self.sa.add(sett3) | |
650 | self.sa.add(sett4) |
|
650 | self.sa.add(sett4) | |
651 | self.sa.add(sett5) |
|
651 | self.sa.add(sett5) | |
652 | self.sa.add(sett6) |
|
652 | self.sa.add(sett6) | |
653 |
|
653 | |||
654 | self.create_ldap_options() |
|
654 | self.create_ldap_options() | |
655 | self.create_default_options() |
|
655 | self.create_default_options() | |
656 |
|
656 | |||
657 | log.info('created ui config') |
|
657 | log.info('created ui config') | |
658 |
|
658 | |||
659 | def create_user(self, username, password, email='', admin=False): |
|
659 | def create_user(self, username, password, email='', admin=False): | |
660 | log.info('creating user %s' % username) |
|
660 | log.info('creating user %s' % username) | |
661 | UserModel().create_or_update(username, password, email, |
|
661 | UserModel().create_or_update(username, password, email, | |
662 | firstname='RhodeCode', lastname='Admin', |
|
662 | firstname='RhodeCode', lastname='Admin', | |
663 | active=True, admin=admin) |
|
663 | active=True, admin=admin) | |
664 |
|
664 | |||
665 | def create_default_user(self): |
|
665 | def create_default_user(self): | |
666 | log.info('creating default user') |
|
666 | log.info('creating default user') | |
667 | # create default user for handling default permissions. |
|
667 | # create default user for handling default permissions. | |
668 | UserModel().create_or_update(username='default', |
|
668 | UserModel().create_or_update(username='default', | |
669 | password=str(uuid.uuid1())[:8], |
|
669 | password=str(uuid.uuid1())[:8], | |
670 | email='anonymous@rhodecode.org', |
|
670 | email='anonymous@rhodecode.org', | |
671 | firstname='Anonymous', lastname='User') |
|
671 | firstname='Anonymous', lastname='User') | |
672 |
|
672 | |||
673 | def create_permissions(self): |
|
673 | def create_permissions(self): | |
674 | # module.(access|create|change|delete)_[name] |
|
674 | # module.(access|create|change|delete)_[name] | |
675 | # module.(none|read|write|admin) |
|
675 | # module.(none|read|write|admin) | |
676 |
|
676 | |||
677 | for p in Permission.PERMS: |
|
677 | for p in Permission.PERMS: | |
678 | if not Permission.get_by_key(p[0]): |
|
678 | if not Permission.get_by_key(p[0]): | |
679 | new_perm = Permission() |
|
679 | new_perm = Permission() | |
680 | new_perm.permission_name = p[0] |
|
680 | new_perm.permission_name = p[0] | |
681 | new_perm.permission_longname = p[0] |
|
681 | new_perm.permission_longname = p[0] | |
682 | self.sa.add(new_perm) |
|
682 | self.sa.add(new_perm) | |
683 |
|
683 | |||
684 | def populate_default_permissions(self): |
|
684 | def populate_default_permissions(self): | |
685 | log.info('creating default user permissions') |
|
685 | log.info('creating default user permissions') | |
686 |
|
686 | |||
687 | default_user = User.get_by_username('default') |
|
687 | default_user = User.get_by_username('default') | |
688 |
|
688 | |||
689 | for def_perm in User.DEFAULT_PERMISSIONS: |
|
689 | for def_perm in User.DEFAULT_PERMISSIONS: | |
690 |
|
690 | |||
691 | perm = self.sa.query(Permission)\ |
|
691 | perm = self.sa.query(Permission)\ | |
692 | .filter(Permission.permission_name == def_perm)\ |
|
692 | .filter(Permission.permission_name == def_perm)\ | |
693 | .scalar() |
|
693 | .scalar() | |
694 | if not perm: |
|
694 | if not perm: | |
695 | raise Exception( |
|
695 | raise Exception( | |
696 | 'CRITICAL: permission %s not found inside database !!' |
|
696 | 'CRITICAL: permission %s not found inside database !!' | |
697 | % def_perm |
|
697 | % def_perm | |
698 | ) |
|
698 | ) | |
699 | if not UserToPerm.query()\ |
|
699 | if not UserToPerm.query()\ | |
700 | .filter(UserToPerm.permission == perm)\ |
|
700 | .filter(UserToPerm.permission == perm)\ | |
701 | .filter(UserToPerm.user == default_user).scalar(): |
|
701 | .filter(UserToPerm.user == default_user).scalar(): | |
702 | reg_perm = UserToPerm() |
|
702 | reg_perm = UserToPerm() | |
703 | reg_perm.user = default_user |
|
703 | reg_perm.user = default_user | |
704 | reg_perm.permission = perm |
|
704 | reg_perm.permission = perm | |
705 | self.sa.add(reg_perm) |
|
705 | self.sa.add(reg_perm) | |
706 |
|
706 | |||
707 | def finish(self): |
|
707 | @staticmethod | |
|
708 | def check_waitress(): | |||
708 | """ |
|
709 | """ | |
709 | Function executed at the end of setup |
|
710 | Function executed at the end of setup | |
710 | """ |
|
711 | """ | |
711 | if not __py_version__ >= (2, 6): |
|
712 | if not __py_version__ >= (2, 6): | |
712 | notify('Python2.5 detected, please switch ' |
|
713 | notify('Python2.5 detected, please switch ' | |
713 | 'egg:waitress#main -> egg:Paste#http ' |
|
714 | 'egg:waitress#main -> egg:Paste#http ' | |
714 | 'in your .ini file') |
|
715 | 'in your .ini file') |
@@ -1,51 +1,51 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 | """ |
|
2 | """ | |
3 | rhodecode.websetup |
|
3 | rhodecode.websetup | |
4 | ~~~~~~~~~~~~~~~~~~ |
|
4 | ~~~~~~~~~~~~~~~~~~ | |
5 |
|
5 | |||
6 | Weboperations and setup for rhodecode |
|
6 | Weboperations and setup for rhodecode | |
7 |
|
7 | |||
8 | :created_on: Dec 11, 2010 |
|
8 | :created_on: Dec 11, 2010 | |
9 | :author: marcink |
|
9 | :author: marcink | |
10 | :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com> |
|
10 | :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com> | |
11 | :license: GPLv3, see COPYING for more details. |
|
11 | :license: GPLv3, see COPYING for more details. | |
12 | """ |
|
12 | """ | |
13 | # This program is free software: you can redistribute it and/or modify |
|
13 | # This program is free software: you can redistribute it and/or modify | |
14 | # it under the terms of the GNU General Public License as published by |
|
14 | # it under the terms of the GNU General Public License as published by | |
15 | # the Free Software Foundation, either version 3 of the License, or |
|
15 | # the Free Software Foundation, either version 3 of the License, or | |
16 | # (at your option) any later version. |
|
16 | # (at your option) any later version. | |
17 | # |
|
17 | # | |
18 | # This program is distributed in the hope that it will be useful, |
|
18 | # This program is distributed in the hope that it will be useful, | |
19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 | # GNU General Public License for more details. |
|
21 | # GNU General Public License for more details. | |
22 | # |
|
22 | # | |
23 | # You should have received a copy of the GNU General Public License |
|
23 | # You should have received a copy of the GNU General Public License | |
24 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
24 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
25 |
|
25 | |||
26 | import logging |
|
26 | import logging | |
27 |
|
27 | |||
28 | from rhodecode.config.environment import load_environment |
|
28 | from rhodecode.config.environment import load_environment | |
29 | from rhodecode.lib.db_manage import DbManage |
|
29 | from rhodecode.lib.db_manage import DbManage | |
30 | from rhodecode.model.meta import Session |
|
30 | from rhodecode.model.meta import Session | |
31 |
|
31 | |||
32 |
|
32 | |||
33 | log = logging.getLogger(__name__) |
|
33 | log = logging.getLogger(__name__) | |
34 |
|
34 | |||
35 |
|
35 | |||
36 | def setup_app(command, conf, vars): |
|
36 | def setup_app(command, conf, vars): | |
37 | """Place any commands to setup rhodecode here""" |
|
37 | """Place any commands to setup rhodecode here""" | |
38 | dbconf = conf['sqlalchemy.db1.url'] |
|
38 | dbconf = conf['sqlalchemy.db1.url'] | |
39 | dbmanage = DbManage(log_sql=True, dbconf=dbconf, root=conf['here'], |
|
39 | dbmanage = DbManage(log_sql=True, dbconf=dbconf, root=conf['here'], | |
40 | tests=False, cli_args=command.options.__dict__) |
|
40 | tests=False, cli_args=command.options.__dict__) | |
41 | dbmanage.create_tables(override=True) |
|
41 | dbmanage.create_tables(override=True) | |
42 | dbmanage.set_db_version() |
|
42 | dbmanage.set_db_version() | |
43 | opts = dbmanage.config_prompt(None) |
|
43 | opts = dbmanage.config_prompt(None) | |
44 | dbmanage.create_settings(opts) |
|
44 | dbmanage.create_settings(opts) | |
45 | dbmanage.create_default_user() |
|
45 | dbmanage.create_default_user() | |
46 | dbmanage.admin_prompt() |
|
46 | dbmanage.admin_prompt() | |
47 | dbmanage.create_permissions() |
|
47 | dbmanage.create_permissions() | |
48 | dbmanage.populate_default_permissions() |
|
48 | dbmanage.populate_default_permissions() | |
49 | Session().commit() |
|
49 | Session().commit() | |
50 | load_environment(conf.global_conf, conf.local_conf, initial=True) |
|
50 | load_environment(conf.global_conf, conf.local_conf, initial=True) | |
51 |
|
|
51 | DbManage.check_waitress() |
General Comments 0
You need to be logged in to leave comments.
Login now