##// END OF EJS Templates
rhodecode config module refactoring
marcink -
r1018:da5075ce beta
parent child Browse files
Show More
@@ -6,6 +6,7 b' import logging'
6 from mako.lookup import TemplateLookup
6 from mako.lookup import TemplateLookup
7 from pylons.configuration import PylonsConfig
7 from pylons.configuration import PylonsConfig
8 from pylons.error import handle_mako_error
8 from pylons.error import handle_mako_error
9 from sqlalchemy import engine_from_config
9
10
10 import rhodecode.lib.app_globals as app_globals
11 import rhodecode.lib.app_globals as app_globals
11 import rhodecode.lib.helpers
12 import rhodecode.lib.helpers
@@ -16,7 +17,7 b' from rhodecode.lib.auth import set_avail'
16 from rhodecode.lib.utils import repo2db_mapper, make_ui, set_rhodecode_config
17 from rhodecode.lib.utils import repo2db_mapper, make_ui, set_rhodecode_config
17 from rhodecode.model import init_model
18 from rhodecode.model import init_model
18 from rhodecode.model.scm import ScmModel
19 from rhodecode.model.scm import ScmModel
19 from sqlalchemy import engine_from_config
20 from rhodecode.lib.timerproxy import TimerProxy
20
21
21 log = logging.getLogger(__name__)
22 log = logging.getLogger(__name__)
22
23
@@ -65,7 +66,6 b' def load_environment(global_conf, app_co'
65 # Setup the SQLAlchemy database engine
66 # Setup the SQLAlchemy database engine
66 if config['debug'] and not test:
67 if config['debug'] and not test:
67 #use query time debugging.
68 #use query time debugging.
68 from rhodecode.lib.timerproxy import TimerProxy
69 sa_engine_db1 = engine_from_config(config, 'sqlalchemy.db1.',
69 sa_engine_db1 = engine_from_config(config, 'sqlalchemy.db1.',
70 proxy=TimerProxy())
70 proxy=TimerProxy())
71 else:
71 else:
@@ -1,17 +1,20 b''
1 """Pylons middleware initialization"""
1 """Pylons middleware initialization"""
2
2 from beaker.middleware import SessionMiddleware
3 from beaker.middleware import SessionMiddleware
4 from routes.middleware import RoutesMiddleware
3 from paste.cascade import Cascade
5 from paste.cascade import Cascade
4 from paste.registry import RegistryManager
6 from paste.registry import RegistryManager
5 from paste.urlparser import StaticURLParser
7 from paste.urlparser import StaticURLParser
6 from paste.deploy.converters import asbool
8 from paste.deploy.converters import asbool
9 from paste.gzipper import make_gzip_middleware
10
7 from pylons.middleware import ErrorHandler, StatusCodeRedirect
11 from pylons.middleware import ErrorHandler, StatusCodeRedirect
8 from pylons.wsgiapp import PylonsApp
12 from pylons.wsgiapp import PylonsApp
9 from routes.middleware import RoutesMiddleware
13
10 from rhodecode.lib.middleware.simplehg import SimpleHg
14 from rhodecode.lib.middleware.simplehg import SimpleHg
11 from rhodecode.lib.middleware.simplegit import SimpleGit
15 from rhodecode.lib.middleware.simplegit import SimpleGit
12 from rhodecode.lib.middleware.https_fixup import HttpsFixup
16 from rhodecode.lib.middleware.https_fixup import HttpsFixup
13 from rhodecode.config.environment import load_environment
17 from rhodecode.config.environment import load_environment
14 from paste.gzipper import make_gzip_middleware
15
18
16 def make_app(global_conf, full_stack=True, static_files=True, **app_conf):
19 def make_app(global_conf, full_stack=True, static_files=True, **app_conf):
17 """Create a Pylons WSGI application and return it
20 """Create a Pylons WSGI application and return it
@@ -11,14 +11,15 b' from rhodecode.lib.utils import check_re'
11
11
12 def make_map(config):
12 def make_map(config):
13 """Create, configure and return the routes Mapper"""
13 """Create, configure and return the routes Mapper"""
14 map = Mapper(directory=config['pylons.paths']['controllers'],
14 routes_map = Mapper(directory=config['pylons.paths']['controllers'],
15 always_scan=config['debug'])
15 always_scan=config['debug'])
16 map.minimization = False
16 routes_map.minimization = False
17 map.explicit = False
17 routes_map.explicit = False
18
18
19 def check_repo(environ, match_dict):
19 def check_repo(environ, match_dict):
20 """
20 """
21 check for valid repository for proper 404 handling
21 check for valid repository for proper 404 handling
22
22 :param environ:
23 :param environ:
23 :param match_dict:
24 :param match_dict:
24 """
25 """
@@ -27,19 +28,19 b' def make_map(config):'
27
28
28 # The ErrorController route (handles 404/500 error pages); it should
29 # The ErrorController route (handles 404/500 error pages); it should
29 # likely stay at the top, ensuring it can always be resolved
30 # likely stay at the top, ensuring it can always be resolved
30 map.connect('/error/{action}', controller='error')
31 routes_map.connect('/error/{action}', controller='error')
31 map.connect('/error/{action}/{id}', controller='error')
32 routes_map.connect('/error/{action}/{id}', controller='error')
32
33
33 #==========================================================================
34 #==========================================================================
34 # CUSTOM ROUTES HERE
35 # CUSTOM ROUTES HERE
35 #==========================================================================
36 #==========================================================================
36
37
37 #MAIN PAGE
38 #MAIN PAGE
38 map.connect('home', '/', controller='home', action='index')
39 routes_map.connect('home', '/', controller='home', action='index')
39 map.connect('bugtracker', "http://bitbucket.org/marcinkuzminski/rhodecode/issues", _static=True)
40 routes_map.connect('bugtracker', "http://bitbucket.org/marcinkuzminski/rhodecode/issues", _static=True)
40 map.connect('gpl_license', "http://www.gnu.org/licenses/gpl.html", _static=True)
41 routes_map.connect('gpl_license', "http://www.gnu.org/licenses/gpl.html", _static=True)
41 #ADMIN REPOSITORY REST ROUTES
42 #ADMIN REPOSITORY REST ROUTES
42 with map.submapper(path_prefix='/_admin', controller='admin/repos') as m:
43 with routes_map.submapper(path_prefix='/_admin', controller='admin/repos') as m:
43 m.connect("repos", "/repos",
44 m.connect("repos", "/repos",
44 action="create", conditions=dict(method=["POST"]))
45 action="create", conditions=dict(method=["POST"]))
45 m.connect("repos", "/repos",
46 m.connect("repos", "/repos",
@@ -87,25 +88,25 b' def make_map(config):'
87 function=check_repo))
88 function=check_repo))
88
89
89 #ADMIN USER REST ROUTES
90 #ADMIN USER REST ROUTES
90 map.resource('user', 'users', controller='admin/users', path_prefix='/_admin')
91 routes_map.resource('user', 'users', controller='admin/users', path_prefix='/_admin')
91
92
92 #ADMIN USER REST ROUTES
93 #ADMIN USER REST ROUTES
93 map.resource('users_group', 'users_groups', controller='admin/users_groups', path_prefix='/_admin')
94 routes_map.resource('users_group', 'users_groups', controller='admin/users_groups', path_prefix='/_admin')
94
95
95 #ADMIN GROUP REST ROUTES
96 #ADMIN GROUP REST ROUTES
96 map.resource('group', 'groups', controller='admin/groups', path_prefix='/_admin')
97 routes_map.resource('group', 'groups', controller='admin/groups', path_prefix='/_admin')
97
98
98 #ADMIN PERMISSIONS REST ROUTES
99 #ADMIN PERMISSIONS REST ROUTES
99 map.resource('permission', 'permissions', controller='admin/permissions', path_prefix='/_admin')
100 routes_map.resource('permission', 'permissions', controller='admin/permissions', path_prefix='/_admin')
100
101
101 ##ADMIN LDAP SETTINGS
102 ##ADMIN LDAP SETTINGS
102 map.connect('ldap_settings', '/_admin/ldap', controller='admin/ldap_settings',
103 routes_map.connect('ldap_settings', '/_admin/ldap', controller='admin/ldap_settings',
103 action='ldap_settings', conditions=dict(method=["POST"]))
104 action='ldap_settings', conditions=dict(method=["POST"]))
104 map.connect('ldap_home', '/_admin/ldap', controller='admin/ldap_settings',)
105 routes_map.connect('ldap_home', '/_admin/ldap', controller='admin/ldap_settings',)
105
106
106
107
107 #ADMIN SETTINGS REST ROUTES
108 #ADMIN SETTINGS REST ROUTES
108 with map.submapper(path_prefix='/_admin', controller='admin/settings') as m:
109 with routes_map.submapper(path_prefix='/_admin', controller='admin/settings') as m:
109 m.connect("admin_settings", "/settings",
110 m.connect("admin_settings", "/settings",
110 action="create", conditions=dict(method=["POST"]))
111 action="create", conditions=dict(method=["POST"]))
111 m.connect("admin_settings", "/settings",
112 m.connect("admin_settings", "/settings",
@@ -136,89 +137,89 b' def make_map(config):'
136 action="create_repository", conditions=dict(method=["GET"]))
137 action="create_repository", conditions=dict(method=["GET"]))
137
138
138 #ADMIN MAIN PAGES
139 #ADMIN MAIN PAGES
139 with map.submapper(path_prefix='/_admin', controller='admin/admin') as m:
140 with routes_map.submapper(path_prefix='/_admin', controller='admin/admin') as m:
140 m.connect('admin_home', '', action='index')#main page
141 m.connect('admin_home', '', action='index')#main page
141 m.connect('admin_add_repo', '/add_repo/{new_repo:[a-z0-9\. _-]*}',
142 m.connect('admin_add_repo', '/add_repo/{new_repo:[a-z0-9\. _-]*}',
142 action='add_repo')
143 action='add_repo')
143
144
144
145
145 #USER JOURNAL
146 #USER JOURNAL
146 map.connect('journal', '/_admin/journal', controller='journal',)
147 routes_map.connect('journal', '/_admin/journal', controller='journal',)
147 map.connect('toggle_following', '/_admin/toggle_following', controller='journal',
148 routes_map.connect('toggle_following', '/_admin/toggle_following', controller='journal',
148 action='toggle_following', conditions=dict(method=["POST"]))
149 action='toggle_following', conditions=dict(method=["POST"]))
149
150
150
151
151 #SEARCH
152 #SEARCH
152 map.connect('search', '/_admin/search', controller='search',)
153 routes_map.connect('search', '/_admin/search', controller='search',)
153 map.connect('search_repo', '/_admin/search/{search_repo:.*}', controller='search')
154 routes_map.connect('search_repo', '/_admin/search/{search_repo:.*}', controller='search')
154
155
155 #LOGIN/LOGOUT/REGISTER/SIGN IN
156 #LOGIN/LOGOUT/REGISTER/SIGN IN
156 map.connect('login_home', '/_admin/login', controller='login')
157 routes_map.connect('login_home', '/_admin/login', controller='login')
157 map.connect('logout_home', '/_admin/logout', controller='login', action='logout')
158 routes_map.connect('logout_home', '/_admin/logout', controller='login', action='logout')
158 map.connect('register', '/_admin/register', controller='login', action='register')
159 routes_map.connect('register', '/_admin/register', controller='login', action='register')
159 map.connect('reset_password', '/_admin/password_reset', controller='login', action='password_reset')
160 routes_map.connect('reset_password', '/_admin/password_reset', controller='login', action='password_reset')
160
161
161 #FEEDS
162 #FEEDS
162 map.connect('rss_feed_home', '/{repo_name:.*}/feed/rss',
163 routes_map.connect('rss_feed_home', '/{repo_name:.*}/feed/rss',
163 controller='feed', action='rss',
164 controller='feed', action='rss',
164 conditions=dict(function=check_repo))
165 conditions=dict(function=check_repo))
165 map.connect('atom_feed_home', '/{repo_name:.*}/feed/atom',
166 routes_map.connect('atom_feed_home', '/{repo_name:.*}/feed/atom',
166 controller='feed', action='atom',
167 controller='feed', action='atom',
167 conditions=dict(function=check_repo))
168 conditions=dict(function=check_repo))
168
169
169
170
170 #REPOSITORY ROUTES
171 #REPOSITORY ROUTES
171 map.connect('changeset_home', '/{repo_name:.*}/changeset/{revision}',
172 routes_map.connect('changeset_home', '/{repo_name:.*}/changeset/{revision}',
172 controller='changeset', revision='tip',
173 controller='changeset', revision='tip',
173 conditions=dict(function=check_repo))
174 conditions=dict(function=check_repo))
174 map.connect('raw_changeset_home', '/{repo_name:.*}/raw-changeset/{revision}',
175 routes_map.connect('raw_changeset_home', '/{repo_name:.*}/raw-changeset/{revision}',
175 controller='changeset', action='raw_changeset', revision='tip',
176 controller='changeset', action='raw_changeset', revision='tip',
176 conditions=dict(function=check_repo))
177 conditions=dict(function=check_repo))
177 map.connect('summary_home', '/{repo_name:.*}',
178 routes_map.connect('summary_home', '/{repo_name:.*}',
178 controller='summary', conditions=dict(function=check_repo))
179 controller='summary', conditions=dict(function=check_repo))
179 map.connect('summary_home', '/{repo_name:.*}/summary',
180 routes_map.connect('summary_home', '/{repo_name:.*}/summary',
180 controller='summary', conditions=dict(function=check_repo))
181 controller='summary', conditions=dict(function=check_repo))
181 map.connect('shortlog_home', '/{repo_name:.*}/shortlog',
182 routes_map.connect('shortlog_home', '/{repo_name:.*}/shortlog',
182 controller='shortlog', conditions=dict(function=check_repo))
183 controller='shortlog', conditions=dict(function=check_repo))
183 map.connect('branches_home', '/{repo_name:.*}/branches',
184 routes_map.connect('branches_home', '/{repo_name:.*}/branches',
184 controller='branches', conditions=dict(function=check_repo))
185 controller='branches', conditions=dict(function=check_repo))
185 map.connect('tags_home', '/{repo_name:.*}/tags',
186 routes_map.connect('tags_home', '/{repo_name:.*}/tags',
186 controller='tags', conditions=dict(function=check_repo))
187 controller='tags', conditions=dict(function=check_repo))
187 map.connect('changelog_home', '/{repo_name:.*}/changelog',
188 routes_map.connect('changelog_home', '/{repo_name:.*}/changelog',
188 controller='changelog', conditions=dict(function=check_repo))
189 controller='changelog', conditions=dict(function=check_repo))
189 map.connect('files_home', '/{repo_name:.*}/files/{revision}/{f_path:.*}',
190 routes_map.connect('files_home', '/{repo_name:.*}/files/{revision}/{f_path:.*}',
190 controller='files', revision='tip', f_path='',
191 controller='files', revision='tip', f_path='',
191 conditions=dict(function=check_repo))
192 conditions=dict(function=check_repo))
192 map.connect('files_diff_home', '/{repo_name:.*}/diff/{f_path:.*}',
193 routes_map.connect('files_diff_home', '/{repo_name:.*}/diff/{f_path:.*}',
193 controller='files', action='diff', revision='tip', f_path='',
194 controller='files', action='diff', revision='tip', f_path='',
194 conditions=dict(function=check_repo))
195 conditions=dict(function=check_repo))
195 map.connect('files_rawfile_home', '/{repo_name:.*}/rawfile/{revision}/{f_path:.*}',
196 routes_map.connect('files_rawfile_home', '/{repo_name:.*}/rawfile/{revision}/{f_path:.*}',
196 controller='files', action='rawfile', revision='tip', f_path='',
197 controller='files', action='rawfile', revision='tip', f_path='',
197 conditions=dict(function=check_repo))
198 conditions=dict(function=check_repo))
198 map.connect('files_raw_home', '/{repo_name:.*}/raw/{revision}/{f_path:.*}',
199 routes_map.connect('files_raw_home', '/{repo_name:.*}/raw/{revision}/{f_path:.*}',
199 controller='files', action='raw', revision='tip', f_path='',
200 controller='files', action='raw', revision='tip', f_path='',
200 conditions=dict(function=check_repo))
201 conditions=dict(function=check_repo))
201 map.connect('files_annotate_home', '/{repo_name:.*}/annotate/{revision}/{f_path:.*}',
202 routes_map.connect('files_annotate_home', '/{repo_name:.*}/annotate/{revision}/{f_path:.*}',
202 controller='files', action='annotate', revision='tip', f_path='',
203 controller='files', action='annotate', revision='tip', f_path='',
203 conditions=dict(function=check_repo))
204 conditions=dict(function=check_repo))
204 map.connect('files_archive_home', '/{repo_name:.*}/archive/{fname}',
205 routes_map.connect('files_archive_home', '/{repo_name:.*}/archive/{fname}',
205 controller='files', action='archivefile',
206 controller='files', action='archivefile',
206 conditions=dict(function=check_repo))
207 conditions=dict(function=check_repo))
207 map.connect('repo_settings_delete', '/{repo_name:.*}/settings',
208 routes_map.connect('repo_settings_delete', '/{repo_name:.*}/settings',
208 controller='settings', action="delete",
209 controller='settings', action="delete",
209 conditions=dict(method=["DELETE"], function=check_repo))
210 conditions=dict(method=["DELETE"], function=check_repo))
210 map.connect('repo_settings_update', '/{repo_name:.*}/settings',
211 routes_map.connect('repo_settings_update', '/{repo_name:.*}/settings',
211 controller='settings', action="update",
212 controller='settings', action="update",
212 conditions=dict(method=["PUT"], function=check_repo))
213 conditions=dict(method=["PUT"], function=check_repo))
213 map.connect('repo_settings_home', '/{repo_name:.*}/settings',
214 routes_map.connect('repo_settings_home', '/{repo_name:.*}/settings',
214 controller='settings', action='index',
215 controller='settings', action='index',
215 conditions=dict(function=check_repo))
216 conditions=dict(function=check_repo))
216
217
217 map.connect('repo_fork_create_home', '/{repo_name:.*}/fork',
218 routes_map.connect('repo_fork_create_home', '/{repo_name:.*}/fork',
218 controller='settings', action='fork_create',
219 controller='settings', action='fork_create',
219 conditions=dict(function=check_repo, method=["POST"]))
220 conditions=dict(function=check_repo, method=["POST"]))
220 map.connect('repo_fork_home', '/{repo_name:.*}/fork',
221 routes_map.connect('repo_fork_home', '/{repo_name:.*}/fork',
221 controller='settings', action='fork',
222 controller='settings', action='fork',
222 conditions=dict(function=check_repo))
223 conditions=dict(function=check_repo))
223
224
224 return map
225 return routes_map
General Comments 0
You need to be logged in to leave comments. Login now