Show More
@@ -1,69 +1,70 b'' | |||||
1 | """Pylons environment configuration""" |
|
1 | """Pylons environment configuration""" | |
2 | from mako.lookup import TemplateLookup |
|
2 | from mako.lookup import TemplateLookup | |
3 | from pylons.configuration import PylonsConfig |
|
3 | from pylons.configuration import PylonsConfig | |
4 | from pylons.error import handle_mako_error |
|
4 | from pylons.error import handle_mako_error | |
5 | from pylons_app.config.routing import make_map |
|
5 | from pylons_app.config.routing import make_map | |
6 | from pylons_app.lib.auth import set_available_permissions |
|
6 | from pylons_app.lib.auth import set_available_permissions | |
7 | from pylons_app.lib.utils import repo2db_mapper |
|
7 | from pylons_app.lib.utils import repo2db_mapper | |
8 | from pylons_app.model import init_model |
|
8 | from pylons_app.model import init_model | |
9 | from pylons_app.model.hg_model import _get_repos_cached_initial |
|
9 | from pylons_app.model.hg_model import _get_repos_cached_initial | |
10 | from sqlalchemy import engine_from_config |
|
10 | from sqlalchemy import engine_from_config | |
11 | import logging |
|
11 | import logging | |
12 | import os |
|
12 | import os | |
13 | import pylons_app.lib.app_globals as app_globals |
|
13 | import pylons_app.lib.app_globals as app_globals | |
14 | import pylons_app.lib.helpers |
|
14 | import pylons_app.lib.helpers | |
15 |
|
15 | |||
16 | log = logging.getLogger(__name__) |
|
16 | log = logging.getLogger(__name__) | |
17 |
|
17 | |||
18 | def load_environment(global_conf, app_conf): |
|
18 | def load_environment(global_conf, app_conf): | |
19 | """Configure the Pylons environment via the ``pylons.config`` |
|
19 | """Configure the Pylons environment via the ``pylons.config`` | |
20 | object |
|
20 | object | |
21 | """ |
|
21 | """ | |
22 | config = PylonsConfig() |
|
22 | config = PylonsConfig() | |
23 |
|
23 | |||
24 | # Pylons paths |
|
24 | # Pylons paths | |
25 | root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
|
25 | root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
26 | paths = dict(root=root, |
|
26 | paths = dict(root=root, | |
27 | controllers=os.path.join(root, 'controllers'), |
|
27 | controllers=os.path.join(root, 'controllers'), | |
28 | static_files=os.path.join(root, 'public'), |
|
28 | static_files=os.path.join(root, 'public'), | |
29 | templates=[os.path.join(root, 'templates')]) |
|
29 | templates=[os.path.join(root, 'templates')]) | |
30 |
|
30 | |||
31 | # Initialize config with the basic options |
|
31 | # Initialize config with the basic options | |
32 | config.init_app(global_conf, app_conf, package='pylons_app', paths=paths) |
|
32 | config.init_app(global_conf, app_conf, package='pylons_app', paths=paths) | |
33 |
|
33 | |||
34 | config['routes.map'] = make_map(config) |
|
34 | config['routes.map'] = make_map(config) | |
35 | config['pylons.app_globals'] = app_globals.Globals(config) |
|
35 | config['pylons.app_globals'] = app_globals.Globals(config) | |
36 | config['pylons.h'] = pylons_app.lib.helpers |
|
36 | config['pylons.h'] = pylons_app.lib.helpers | |
37 |
|
37 | |||
38 | # Setup cache object as early as possible |
|
38 | # Setup cache object as early as possible | |
39 | import pylons |
|
39 | import pylons | |
40 | pylons.cache._push_object(config['pylons.app_globals'].cache) |
|
40 | pylons.cache._push_object(config['pylons.app_globals'].cache) | |
41 |
|
41 | |||
42 | # Create the Mako TemplateLookup, with the default auto-escaping |
|
42 | # Create the Mako TemplateLookup, with the default auto-escaping | |
43 | config['pylons.app_globals'].mako_lookup = TemplateLookup( |
|
43 | config['pylons.app_globals'].mako_lookup = TemplateLookup( | |
44 | directories=paths['templates'], |
|
44 | directories=paths['templates'], | |
45 | error_handler=handle_mako_error, |
|
45 | error_handler=handle_mako_error, | |
46 | module_directory=os.path.join(app_conf['cache_dir'], 'templates'), |
|
46 | module_directory=os.path.join(app_conf['cache_dir'], 'templates'), | |
47 | input_encoding='utf-8', default_filters=['escape'], |
|
47 | input_encoding='utf-8', default_filters=['escape'], | |
48 | imports=['from webhelpers.html import escape']) |
|
48 | imports=['from webhelpers.html import escape']) | |
49 |
|
49 | |||
50 | #sets the c attribute access when don't existing attribute are accessed |
|
50 | #sets the c attribute access when don't existing attribute are accessed | |
51 | config['pylons.strict_tmpl_context'] = True |
|
51 | config['pylons.strict_tmpl_context'] = True | |
52 |
|
52 | |||
53 | #MULTIPLE DB configs |
|
53 | #MULTIPLE DB configs | |
54 | # Setup the SQLAlchemy database engine |
|
54 | # Setup the SQLAlchemy database engine | |
55 | if config['debug']: |
|
55 | if config['debug']: | |
56 | #use query time debugging. |
|
56 | #use query time debugging. | |
57 | from pylons_app.lib.timerproxy import TimerProxy |
|
57 | from pylons_app.lib.timerproxy import TimerProxy | |
58 | sa_engine_db1 = engine_from_config(config, 'sqlalchemy.db1.', |
|
58 | sa_engine_db1 = engine_from_config(config, 'sqlalchemy.db1.', | |
59 | proxy=TimerProxy()) |
|
59 | proxy=TimerProxy()) | |
60 | else: |
|
60 | else: | |
61 | sa_engine_db1 = engine_from_config(config, 'sqlalchemy.db1.') |
|
61 | sa_engine_db1 = engine_from_config(config, 'sqlalchemy.db1.') | |
62 |
|
62 | |||
63 | init_model(sa_engine_db1) |
|
63 | init_model(sa_engine_db1) | |
64 | repo2db_mapper(_get_repos_cached_initial(config['pylons.app_globals'])) |
|
64 | repo2db_mapper(_get_repos_cached_initial(config['pylons.app_globals'])) | |
65 | set_available_permissions(config) |
|
65 | set_available_permissions(config) | |
|
66 | config['base_path'] = config['pylons.app_globals'].base_path | |||
66 | # CONFIGURATION OPTIONS HERE (note: all config options will override |
|
67 | # CONFIGURATION OPTIONS HERE (note: all config options will override | |
67 | # any Pylons config options) |
|
68 | # any Pylons config options) | |
68 |
|
69 | |||
69 | return config |
|
70 | return config |
@@ -1,94 +1,118 b'' | |||||
1 | """Routes configuration |
|
1 | """Routes configuration | |
2 |
|
2 | |||
3 | The more specific and detailed routes should be defined first so they |
|
3 | The more specific and detailed routes should be defined first so they | |
4 | may take precedent over the more generic routes. For more information |
|
4 | may take precedent over the more generic routes. For more information | |
5 | refer to the routes manual at http://routes.groovie.org/docs/ |
|
5 | refer to the routes manual at http://routes.groovie.org/docs/ | |
6 | """ |
|
6 | """ | |
7 | from routes import Mapper |
|
7 | from routes import Mapper | |
|
8 | from pylons_app.lib.utils import check_repo as cr | |||
8 |
|
9 | |||
9 | def make_map(config): |
|
10 | def make_map(config): | |
10 | """Create, configure and return the routes Mapper""" |
|
11 | """Create, configure and return the routes Mapper""" | |
11 | map = Mapper(directory=config['pylons.paths']['controllers'], |
|
12 | map = Mapper(directory=config['pylons.paths']['controllers'], | |
12 | always_scan=config['debug']) |
|
13 | always_scan=config['debug']) | |
13 | map.minimization = False |
|
14 | map.minimization = False | |
14 | map.explicit = False |
|
15 | map.explicit = False | |
15 |
|
16 | |||
16 | # The ErrorController route (handles 404/500 error pages); it should |
|
17 | # The ErrorController route (handles 404/500 error pages); it should | |
17 | # likely stay at the top, ensuring it can always be resolved |
|
18 | # likely stay at the top, ensuring it can always be resolved | |
18 | map.connect('/error/{action}', controller='error') |
|
19 | map.connect('/error/{action}', controller='error') | |
19 | map.connect('/error/{action}/{id}', controller='error') |
|
20 | map.connect('/error/{action}/{id}', controller='error') | |
20 |
|
21 | |||
21 | # CUSTOM ROUTES HERE |
|
22 | # CUSTOM ROUTES HERE | |
22 | map.connect('hg_home', '/', controller='hg', action='index') |
|
23 | map.connect('hg_home', '/', controller='hg', action='index') | |
23 |
|
24 | |||
|
25 | def check_repo(environ, match_dict): | |||
|
26 | """ | |||
|
27 | check for valid repository for proper 404 handling | |||
|
28 | @param environ: | |||
|
29 | @param match_dict: | |||
|
30 | """ | |||
|
31 | repo_name = match_dict.get('repo_name') | |||
|
32 | return not cr(repo_name, config['base_path']) | |||
24 |
|
33 | |||
25 | #REST routes |
|
34 | #REST routes | |
26 | with map.submapper(path_prefix='/_admin', controller='repos') as m: |
|
35 | with map.submapper(path_prefix='/_admin', controller='repos') as m: | |
27 | m.connect("repos", "/repos", |
|
36 | m.connect("repos", "/repos", | |
28 | action="create", conditions=dict(method=["POST"])) |
|
37 | action="create", conditions=dict(method=["POST"])) | |
29 | m.connect("repos", "/repos", |
|
38 | m.connect("repos", "/repos", | |
30 | action="index", conditions=dict(method=["GET"])) |
|
39 | action="index", conditions=dict(method=["GET"])) | |
31 | m.connect("formatted_repos", "/repos.{format}", |
|
40 | m.connect("formatted_repos", "/repos.{format}", | |
32 | action="index", |
|
41 | action="index", | |
33 | conditions=dict(method=["GET"])) |
|
42 | conditions=dict(method=["GET"])) | |
34 | m.connect("new_repo", "/repos/new", |
|
43 | m.connect("new_repo", "/repos/new", | |
35 | action="new", conditions=dict(method=["GET"])) |
|
44 | action="new", conditions=dict(method=["GET"])) | |
36 | m.connect("formatted_new_repo", "/repos/new.{format}", |
|
45 | m.connect("formatted_new_repo", "/repos/new.{format}", | |
37 | action="new", conditions=dict(method=["GET"])) |
|
46 | action="new", conditions=dict(method=["GET"])) | |
38 | m.connect("/repos/{repo_name:.*}", |
|
47 | m.connect("/repos/{repo_name:.*}", | |
39 |
action="update", conditions=dict(method=["PUT"] |
|
48 | action="update", conditions=dict(method=["PUT"], | |
|
49 | function=check_repo)) | |||
40 | m.connect("/repos/{repo_name:.*}", |
|
50 | m.connect("/repos/{repo_name:.*}", | |
41 |
action="delete", conditions=dict(method=["DELETE"] |
|
51 | action="delete", conditions=dict(method=["DELETE"], | |
|
52 | function=check_repo)) | |||
42 | m.connect("edit_repo", "/repos/{repo_name:.*}/edit", |
|
53 | m.connect("edit_repo", "/repos/{repo_name:.*}/edit", | |
43 |
action="edit", conditions=dict(method=["GET"] |
|
54 | action="edit", conditions=dict(method=["GET"], | |
|
55 | function=check_repo)) | |||
44 | m.connect("formatted_edit_repo", "/repos/{repo_name:.*}.{format}/edit", |
|
56 | m.connect("formatted_edit_repo", "/repos/{repo_name:.*}.{format}/edit", | |
45 |
action="edit", conditions=dict(method=["GET"] |
|
57 | action="edit", conditions=dict(method=["GET"], | |
|
58 | function=check_repo)) | |||
46 | m.connect("repo", "/repos/{repo_name:.*}", |
|
59 | m.connect("repo", "/repos/{repo_name:.*}", | |
47 |
action="show", conditions=dict(method=["GET"] |
|
60 | action="show", conditions=dict(method=["GET"], | |
|
61 | function=check_repo)) | |||
48 | m.connect("formatted_repo", "/repos/{repo_name:.*}.{format}", |
|
62 | m.connect("formatted_repo", "/repos/{repo_name:.*}.{format}", | |
49 |
action="show", conditions=dict(method=["GET"] |
|
63 | action="show", conditions=dict(method=["GET"], | |
|
64 | function=check_repo)) | |||
50 | #ajax delete repo perm user |
|
65 | #ajax delete repo perm user | |
51 | m.connect('delete_repo_user', "/repos_delete_user/{repo_name:.*}", |
|
66 | m.connect('delete_repo_user', "/repos_delete_user/{repo_name:.*}", | |
52 |
action="delete_perm_user", conditions=dict(method=["DELETE"] |
|
67 | action="delete_perm_user", conditions=dict(method=["DELETE"], | |
|
68 | function=check_repo)) | |||
53 |
|
69 | |||
54 | map.resource('user', 'users', path_prefix='/_admin') |
|
70 | map.resource('user', 'users', path_prefix='/_admin') | |
55 | map.resource('permission', 'permissions', path_prefix='/_admin') |
|
71 | map.resource('permission', 'permissions', path_prefix='/_admin') | |
56 |
|
72 | |||
57 | #ADMIN |
|
73 | #ADMIN | |
58 | with map.submapper(path_prefix='/_admin', controller='admin') as m: |
|
74 | with map.submapper(path_prefix='/_admin', controller='admin') as m: | |
59 | m.connect('admin_home', '/', action='index')#main page |
|
75 | m.connect('admin_home', '/', action='index')#main page | |
60 | m.connect('admin_add_repo', '/add_repo/{new_repo:[a-z0-9\. _-]*}', |
|
76 | m.connect('admin_add_repo', '/add_repo/{new_repo:[a-z0-9\. _-]*}', | |
61 | action='add_repo') |
|
77 | action='add_repo') | |
62 |
|
78 | |||
63 | #FEEDS |
|
79 | #FEEDS | |
64 | map.connect('rss_feed_home', '/{repo_name:.*}/feed/rss', |
|
80 | map.connect('rss_feed_home', '/{repo_name:.*}/feed/rss', | |
65 |
controller='feed', action='rss' |
|
81 | controller='feed', action='rss', | |
|
82 | conditions=dict(function=check_repo)) | |||
66 | map.connect('atom_feed_home', '/{repo_name:.*}/feed/atom', |
|
83 | map.connect('atom_feed_home', '/{repo_name:.*}/feed/atom', | |
67 |
controller='feed', action='atom' |
|
84 | controller='feed', action='atom', | |
|
85 | conditions=dict(function=check_repo)) | |||
68 |
|
86 | |||
69 | map.connect('login_home', '/login', controller='login') |
|
87 | map.connect('login_home', '/login', controller='login') | |
70 | map.connect('logout_home', '/logout', controller='login', action='logout') |
|
88 | map.connect('logout_home', '/logout', controller='login', action='logout') | |
71 |
|
89 | |||
72 | map.connect('changeset_home', '/{repo_name:.*}/changeset/{revision}', |
|
90 | map.connect('changeset_home', '/{repo_name:.*}/changeset/{revision}', | |
73 |
controller='changeset', revision='tip' |
|
91 | controller='changeset', revision='tip', | |
|
92 | conditions=dict(function=check_repo)) | |||
74 | map.connect('summary_home', '/{repo_name:.*}/summary', |
|
93 | map.connect('summary_home', '/{repo_name:.*}/summary', | |
75 | controller='summary') |
|
94 | controller='summary', conditions=dict(function=check_repo)) | |
76 | map.connect('shortlog_home', '/{repo_name:.*}/shortlog', |
|
95 | map.connect('shortlog_home', '/{repo_name:.*}/shortlog', | |
77 | controller='shortlog') |
|
96 | controller='shortlog', conditions=dict(function=check_repo)) | |
78 | map.connect('branches_home', '/{repo_name:.*}/branches', |
|
97 | map.connect('branches_home', '/{repo_name:.*}/branches', | |
79 | controller='branches') |
|
98 | controller='branches', conditions=dict(function=check_repo)) | |
80 | map.connect('tags_home', '/{repo_name:.*}/tags', |
|
99 | map.connect('tags_home', '/{repo_name:.*}/tags', | |
81 | controller='tags') |
|
100 | controller='tags', conditions=dict(function=check_repo)) | |
82 | map.connect('changelog_home', '/{repo_name:.*}/changelog', |
|
101 | map.connect('changelog_home', '/{repo_name:.*}/changelog', | |
83 | controller='changelog') |
|
102 | controller='changelog', conditions=dict(function=check_repo)) | |
84 | map.connect('files_home', '/{repo_name:.*}/files/{revision}/{f_path:.*}', |
|
103 | map.connect('files_home', '/{repo_name:.*}/files/{revision}/{f_path:.*}', | |
85 |
controller='files', revision='tip', f_path='' |
|
104 | controller='files', revision='tip', f_path='', | |
|
105 | conditions=dict(function=check_repo)) | |||
86 | map.connect('files_diff_home', '/{repo_name:.*}/diff/{f_path:.*}', |
|
106 | map.connect('files_diff_home', '/{repo_name:.*}/diff/{f_path:.*}', | |
87 |
controller='files', action='diff', revision='tip', f_path='' |
|
107 | controller='files', action='diff', revision='tip', f_path='', | |
|
108 | conditions=dict(function=check_repo)) | |||
88 | map.connect('files_raw_home', '/{repo_name:.*}/rawfile/{revision}/{f_path:.*}', |
|
109 | map.connect('files_raw_home', '/{repo_name:.*}/rawfile/{revision}/{f_path:.*}', | |
89 |
controller='files', action='rawfile', revision='tip', f_path='' |
|
110 | controller='files', action='rawfile', revision='tip', f_path='', | |
|
111 | conditions=dict(function=check_repo)) | |||
90 | map.connect('files_annotate_home', '/{repo_name:.*}/annotate/{revision}/{f_path:.*}', |
|
112 | map.connect('files_annotate_home', '/{repo_name:.*}/annotate/{revision}/{f_path:.*}', | |
91 |
controller='files', action='annotate', revision='tip', f_path='' |
|
113 | controller='files', action='annotate', revision='tip', f_path='', | |
|
114 | conditions=dict(function=check_repo)) | |||
92 | map.connect('files_archive_home', '/{repo_name:.*}/archive/{revision}/{fileformat}', |
|
115 | map.connect('files_archive_home', '/{repo_name:.*}/archive/{revision}/{fileformat}', | |
93 |
controller='files', action='archivefile', revision='tip' |
|
116 | controller='files', action='archivefile', revision='tip', | |
|
117 | conditions=dict(function=check_repo)) | |||
94 | return map |
|
118 | return map |
General Comments 0
You need to be logged in to leave comments.
Login now