Show More
@@ -1,154 +1,154 b'' | |||
|
1 | 1 | |
|
2 | 2 | /****************************************************************************** |
|
3 | 3 | * * |
|
4 | 4 | * DO NOT CHANGE THIS FILE MANUALLY * |
|
5 | 5 | * * |
|
6 | 6 | * * |
|
7 | 7 | * This file is automatically generated when the app starts up with * |
|
8 | 8 | * generate_js_files = true * |
|
9 | 9 | * * |
|
10 | 10 | * To add a route here pass jsroute=True to the route definition in the app * |
|
11 | 11 | * * |
|
12 | 12 | ******************************************************************************/ |
|
13 | 13 | function registerRCRoutes() { |
|
14 | 14 | // routes registration |
|
15 | 15 | pyroutes.register('new_repo', '/_admin/create_repository', []); |
|
16 | 16 | pyroutes.register('edit_user', '/_admin/users/%(user_id)s/edit', ['user_id']); |
|
17 | 17 | pyroutes.register('edit_user_group_members', '/_admin/user_groups/%(user_group_id)s/edit/members', ['user_group_id']); |
|
18 | 18 | pyroutes.register('gists', '/_admin/gists', []); |
|
19 | 19 | pyroutes.register('new_gist', '/_admin/gists/new', []); |
|
20 | 20 | pyroutes.register('toggle_following', '/_admin/toggle_following', []); |
|
21 | 21 | pyroutes.register('changeset_home', '/%(repo_name)s/changeset/%(revision)s', ['repo_name', 'revision']); |
|
22 | 22 | pyroutes.register('changeset_comment', '/%(repo_name)s/changeset/%(revision)s/comment', ['repo_name', 'revision']); |
|
23 | 23 | pyroutes.register('changeset_comment_preview', '/%(repo_name)s/changeset/comment/preview', ['repo_name']); |
|
24 | 24 | pyroutes.register('changeset_comment_delete', '/%(repo_name)s/changeset/comment/%(comment_id)s/delete', ['repo_name', 'comment_id']); |
|
25 | 25 | pyroutes.register('changeset_info', '/%(repo_name)s/changeset_info/%(revision)s', ['repo_name', 'revision']); |
|
26 | 26 | pyroutes.register('compare_url', '/%(repo_name)s/compare/%(source_ref_type)s@%(source_ref)s...%(target_ref_type)s@%(target_ref)s', ['repo_name', 'source_ref_type', 'source_ref', 'target_ref_type', 'target_ref']); |
|
27 | 27 | pyroutes.register('pullrequest_home', '/%(repo_name)s/pull-request/new', ['repo_name']); |
|
28 | 28 | pyroutes.register('pullrequest', '/%(repo_name)s/pull-request/new', ['repo_name']); |
|
29 | 29 | pyroutes.register('pullrequest_repo_refs', '/%(repo_name)s/pull-request/refs/%(target_repo_name)s', ['repo_name', 'target_repo_name']); |
|
30 | 30 | pyroutes.register('pullrequest_repo_destinations', '/%(repo_name)s/pull-request/repo-destinations', ['repo_name']); |
|
31 | 31 | pyroutes.register('pullrequest_show', '/%(repo_name)s/pull-request/%(pull_request_id)s', ['repo_name', 'pull_request_id']); |
|
32 | 32 | pyroutes.register('pullrequest_update', '/%(repo_name)s/pull-request/%(pull_request_id)s', ['repo_name', 'pull_request_id']); |
|
33 | 33 | pyroutes.register('pullrequest_comment', '/%(repo_name)s/pull-request-comment/%(pull_request_id)s', ['repo_name', 'pull_request_id']); |
|
34 | 34 | pyroutes.register('pullrequest_comment_delete', '/%(repo_name)s/pull-request-comment/%(comment_id)s/delete', ['repo_name', 'comment_id']); |
|
35 | 35 | pyroutes.register('changelog_home', '/%(repo_name)s/changelog', ['repo_name']); |
|
36 | 36 | pyroutes.register('changelog_file_home', '/%(repo_name)s/changelog/%(revision)s/%(f_path)s', ['repo_name', 'revision', 'f_path']); |
|
37 | 37 | pyroutes.register('changelog_elements', '/%(repo_name)s/changelog_details', ['repo_name']); |
|
38 | 38 | pyroutes.register('files_home', '/%(repo_name)s/files/%(revision)s/%(f_path)s', ['repo_name', 'revision', 'f_path']); |
|
39 | 39 | pyroutes.register('files_history_home', '/%(repo_name)s/history/%(revision)s/%(f_path)s', ['repo_name', 'revision', 'f_path']); |
|
40 | 40 | pyroutes.register('files_authors_home', '/%(repo_name)s/authors/%(revision)s/%(f_path)s', ['repo_name', 'revision', 'f_path']); |
|
41 | 41 | pyroutes.register('files_annotate_home', '/%(repo_name)s/annotate/%(revision)s/%(f_path)s', ['repo_name', 'revision', 'f_path']); |
|
42 | 42 | pyroutes.register('files_annotate_previous', '/%(repo_name)s/annotate-previous/%(revision)s/%(f_path)s', ['repo_name', 'revision', 'f_path']); |
|
43 | 43 | pyroutes.register('files_archive_home', '/%(repo_name)s/archive/%(fname)s', ['repo_name', 'fname']); |
|
44 | 44 | pyroutes.register('files_nodelist_home', '/%(repo_name)s/nodelist/%(revision)s/%(f_path)s', ['repo_name', 'revision', 'f_path']); |
|
45 | 45 | pyroutes.register('files_nodetree_full', '/%(repo_name)s/nodetree_full/%(commit_id)s/%(f_path)s', ['repo_name', 'commit_id', 'f_path']); |
|
46 | 46 | pyroutes.register('favicon', '/favicon.ico', []); |
|
47 | 47 | pyroutes.register('robots', '/robots.txt', []); |
|
48 | 48 | pyroutes.register('auth_home', '/_admin/auth*traverse', []); |
|
49 | 49 | pyroutes.register('global_integrations_new', '/_admin/integrations/new', []); |
|
50 | 50 | pyroutes.register('global_integrations_home', '/_admin/integrations', []); |
|
51 | 51 | pyroutes.register('global_integrations_list', '/_admin/integrations/%(integration)s', ['integration']); |
|
52 | 52 | pyroutes.register('global_integrations_create', '/_admin/integrations/%(integration)s/new', ['integration']); |
|
53 | 53 | pyroutes.register('global_integrations_edit', '/_admin/integrations/%(integration)s/%(integration_id)s', ['integration', 'integration_id']); |
|
54 | pyroutes.register('repo_group_integrations_home', '%(repo_group_name)s/settings/integrations', ['repo_group_name']); | |
|
55 | pyroutes.register('repo_group_integrations_list', '%(repo_group_name)s/settings/integrations/%(integration)s', ['repo_group_name', 'integration']); | |
|
56 | pyroutes.register('repo_group_integrations_new', '%(repo_group_name)s/settings/integrations/new', ['repo_group_name']); | |
|
57 | pyroutes.register('repo_group_integrations_create', '%(repo_group_name)s/settings/integrations/%(integration)s/new', ['repo_group_name', 'integration']); | |
|
58 | pyroutes.register('repo_group_integrations_edit', '%(repo_group_name)s/settings/integrations/%(integration)s/%(integration_id)s', ['repo_group_name', 'integration', 'integration_id']); | |
|
59 | pyroutes.register('repo_integrations_home', '%(repo_name)s/settings/integrations', ['repo_name']); | |
|
60 | pyroutes.register('repo_integrations_list', '%(repo_name)s/settings/integrations/%(integration)s', ['repo_name', 'integration']); | |
|
61 | pyroutes.register('repo_integrations_new', '%(repo_name)s/settings/integrations/new', ['repo_name']); | |
|
62 | pyroutes.register('repo_integrations_create', '%(repo_name)s/settings/integrations/%(integration)s/new', ['repo_name', 'integration']); | |
|
63 | pyroutes.register('repo_integrations_edit', '%(repo_name)s/settings/integrations/%(integration)s/%(integration_id)s', ['repo_name', 'integration', 'integration_id']); | |
|
64 | pyroutes.register('ops_ping', '_admin/ops/ping', []); | |
|
54 | pyroutes.register('repo_group_integrations_home', '/%(repo_group_name)s/settings/integrations', ['repo_group_name']); | |
|
55 | pyroutes.register('repo_group_integrations_list', '/%(repo_group_name)s/settings/integrations/%(integration)s', ['repo_group_name', 'integration']); | |
|
56 | pyroutes.register('repo_group_integrations_new', '/%(repo_group_name)s/settings/integrations/new', ['repo_group_name']); | |
|
57 | pyroutes.register('repo_group_integrations_create', '/%(repo_group_name)s/settings/integrations/%(integration)s/new', ['repo_group_name', 'integration']); | |
|
58 | pyroutes.register('repo_group_integrations_edit', '/%(repo_group_name)s/settings/integrations/%(integration)s/%(integration_id)s', ['repo_group_name', 'integration', 'integration_id']); | |
|
59 | pyroutes.register('repo_integrations_home', '/%(repo_name)s/settings/integrations', ['repo_name']); | |
|
60 | pyroutes.register('repo_integrations_list', '/%(repo_name)s/settings/integrations/%(integration)s', ['repo_name', 'integration']); | |
|
61 | pyroutes.register('repo_integrations_new', '/%(repo_name)s/settings/integrations/new', ['repo_name']); | |
|
62 | pyroutes.register('repo_integrations_create', '/%(repo_name)s/settings/integrations/%(integration)s/new', ['repo_name', 'integration']); | |
|
63 | pyroutes.register('repo_integrations_edit', '/%(repo_name)s/settings/integrations/%(integration)s/%(integration_id)s', ['repo_name', 'integration', 'integration_id']); | |
|
64 | pyroutes.register('ops_ping', '/_admin/ops/ping', []); | |
|
65 | 65 | pyroutes.register('admin_home', '/_admin', []); |
|
66 | pyroutes.register('admin_audit_logs', '_admin/audit_logs', []); | |
|
67 | pyroutes.register('pull_requests_global_0', '_admin/pull_requests/%(pull_request_id)s', ['pull_request_id']); | |
|
68 | pyroutes.register('pull_requests_global_1', '_admin/pull-requests/%(pull_request_id)s', ['pull_request_id']); | |
|
69 | pyroutes.register('pull_requests_global', '_admin/pull-request/%(pull_request_id)s', ['pull_request_id']); | |
|
70 | pyroutes.register('admin_settings_open_source', '_admin/settings/open_source', []); | |
|
71 | pyroutes.register('admin_settings_vcs_svn_generate_cfg', '_admin/settings/vcs/svn_generate_cfg', []); | |
|
72 | pyroutes.register('admin_settings_system', '_admin/settings/system', []); | |
|
73 | pyroutes.register('admin_settings_system_update', '_admin/settings/system/updates', []); | |
|
74 | pyroutes.register('admin_settings_sessions', '_admin/settings/sessions', []); | |
|
75 | pyroutes.register('admin_settings_sessions_cleanup', '_admin/settings/sessions/cleanup', []); | |
|
76 | pyroutes.register('admin_permissions_ips', '_admin/permissions/ips', []); | |
|
77 | pyroutes.register('users', '_admin/users', []); | |
|
78 | pyroutes.register('users_data', '_admin/users_data', []); | |
|
79 | pyroutes.register('edit_user_auth_tokens', '_admin/users/%(user_id)s/edit/auth_tokens', ['user_id']); | |
|
80 | pyroutes.register('edit_user_auth_tokens_add', '_admin/users/%(user_id)s/edit/auth_tokens/new', ['user_id']); | |
|
81 | pyroutes.register('edit_user_auth_tokens_delete', '_admin/users/%(user_id)s/edit/auth_tokens/delete', ['user_id']); | |
|
82 | pyroutes.register('edit_user_emails', '_admin/users/%(user_id)s/edit/emails', ['user_id']); | |
|
83 | pyroutes.register('edit_user_emails_add', '_admin/users/%(user_id)s/edit/emails/new', ['user_id']); | |
|
84 | pyroutes.register('edit_user_emails_delete', '_admin/users/%(user_id)s/edit/emails/delete', ['user_id']); | |
|
85 | pyroutes.register('edit_user_ips', '_admin/users/%(user_id)s/edit/ips', ['user_id']); | |
|
86 | pyroutes.register('edit_user_ips_add', '_admin/users/%(user_id)s/edit/ips/new', ['user_id']); | |
|
87 | pyroutes.register('edit_user_ips_delete', '_admin/users/%(user_id)s/edit/ips/delete', ['user_id']); | |
|
88 | pyroutes.register('edit_user_groups_management', '_admin/users/%(user_id)s/edit/groups_management', ['user_id']); | |
|
89 | pyroutes.register('edit_user_groups_management_updates', '_admin/users/%(user_id)s/edit/edit_user_groups_management/updates', ['user_id']); | |
|
90 | pyroutes.register('edit_user_audit_logs', '_admin/users/%(user_id)s/edit/audit', ['user_id']); | |
|
66 | pyroutes.register('admin_audit_logs', '/_admin/audit_logs', []); | |
|
67 | pyroutes.register('pull_requests_global_0', '/_admin/pull_requests/%(pull_request_id)s', ['pull_request_id']); | |
|
68 | pyroutes.register('pull_requests_global_1', '/_admin/pull-requests/%(pull_request_id)s', ['pull_request_id']); | |
|
69 | pyroutes.register('pull_requests_global', '/_admin/pull-request/%(pull_request_id)s', ['pull_request_id']); | |
|
70 | pyroutes.register('admin_settings_open_source', '/_admin/settings/open_source', []); | |
|
71 | pyroutes.register('admin_settings_vcs_svn_generate_cfg', '/_admin/settings/vcs/svn_generate_cfg', []); | |
|
72 | pyroutes.register('admin_settings_system', '/_admin/settings/system', []); | |
|
73 | pyroutes.register('admin_settings_system_update', '/_admin/settings/system/updates', []); | |
|
74 | pyroutes.register('admin_settings_sessions', '/_admin/settings/sessions', []); | |
|
75 | pyroutes.register('admin_settings_sessions_cleanup', '/_admin/settings/sessions/cleanup', []); | |
|
76 | pyroutes.register('admin_permissions_ips', '/_admin/permissions/ips', []); | |
|
77 | pyroutes.register('users', '/_admin/users', []); | |
|
78 | pyroutes.register('users_data', '/_admin/users_data', []); | |
|
79 | pyroutes.register('edit_user_auth_tokens', '/_admin/users/%(user_id)s/edit/auth_tokens', ['user_id']); | |
|
80 | pyroutes.register('edit_user_auth_tokens_add', '/_admin/users/%(user_id)s/edit/auth_tokens/new', ['user_id']); | |
|
81 | pyroutes.register('edit_user_auth_tokens_delete', '/_admin/users/%(user_id)s/edit/auth_tokens/delete', ['user_id']); | |
|
82 | pyroutes.register('edit_user_emails', '/_admin/users/%(user_id)s/edit/emails', ['user_id']); | |
|
83 | pyroutes.register('edit_user_emails_add', '/_admin/users/%(user_id)s/edit/emails/new', ['user_id']); | |
|
84 | pyroutes.register('edit_user_emails_delete', '/_admin/users/%(user_id)s/edit/emails/delete', ['user_id']); | |
|
85 | pyroutes.register('edit_user_ips', '/_admin/users/%(user_id)s/edit/ips', ['user_id']); | |
|
86 | pyroutes.register('edit_user_ips_add', '/_admin/users/%(user_id)s/edit/ips/new', ['user_id']); | |
|
87 | pyroutes.register('edit_user_ips_delete', '/_admin/users/%(user_id)s/edit/ips/delete', ['user_id']); | |
|
88 | pyroutes.register('edit_user_groups_management', '/_admin/users/%(user_id)s/edit/groups_management', ['user_id']); | |
|
89 | pyroutes.register('edit_user_groups_management_updates', '/_admin/users/%(user_id)s/edit/edit_user_groups_management/updates', ['user_id']); | |
|
90 | pyroutes.register('edit_user_audit_logs', '/_admin/users/%(user_id)s/edit/audit', ['user_id']); | |
|
91 | 91 | pyroutes.register('channelstream_connect', '/_admin/channelstream/connect', []); |
|
92 | 92 | pyroutes.register('channelstream_subscribe', '/_admin/channelstream/subscribe', []); |
|
93 | 93 | pyroutes.register('channelstream_proxy', '/_channelstream', []); |
|
94 | 94 | pyroutes.register('login', '/_admin/login', []); |
|
95 | 95 | pyroutes.register('logout', '/_admin/logout', []); |
|
96 | 96 | pyroutes.register('register', '/_admin/register', []); |
|
97 | 97 | pyroutes.register('reset_password', '/_admin/password_reset', []); |
|
98 | 98 | pyroutes.register('reset_password_confirmation', '/_admin/password_reset_confirmation', []); |
|
99 | 99 | pyroutes.register('home', '/', []); |
|
100 | 100 | pyroutes.register('user_autocomplete_data', '/_users', []); |
|
101 | 101 | pyroutes.register('user_group_autocomplete_data', '/_user_groups', []); |
|
102 | 102 | pyroutes.register('repo_list_data', '/_repos', []); |
|
103 | 103 | pyroutes.register('goto_switcher_data', '/_goto_data', []); |
|
104 | 104 | pyroutes.register('repo_summary_explicit', '/%(repo_name)s/summary', ['repo_name']); |
|
105 | 105 | pyroutes.register('repo_summary_commits', '/%(repo_name)s/summary-commits', ['repo_name']); |
|
106 | 106 | pyroutes.register('repo_commit', '/%(repo_name)s/changeset/%(commit_id)s', ['repo_name', 'commit_id']); |
|
107 | 107 | pyroutes.register('repo_refs_data', '/%(repo_name)s/refs-data', ['repo_name']); |
|
108 | 108 | pyroutes.register('repo_refs_changelog_data', '/%(repo_name)s/refs-data-changelog', ['repo_name']); |
|
109 | 109 | pyroutes.register('repo_stats', '/%(repo_name)s/repo_stats/%(commit_id)s', ['repo_name', 'commit_id']); |
|
110 | 110 | pyroutes.register('tags_home', '/%(repo_name)s/tags', ['repo_name']); |
|
111 | 111 | pyroutes.register('branches_home', '/%(repo_name)s/branches', ['repo_name']); |
|
112 | 112 | pyroutes.register('bookmarks_home', '/%(repo_name)s/bookmarks', ['repo_name']); |
|
113 | 113 | pyroutes.register('pullrequest_show', '/%(repo_name)s/pull-request/%(pull_request_id)s', ['repo_name', 'pull_request_id']); |
|
114 | 114 | pyroutes.register('pullrequest_show_all', '/%(repo_name)s/pull-request', ['repo_name']); |
|
115 | 115 | pyroutes.register('pullrequest_show_all_data', '/%(repo_name)s/pull-request-data', ['repo_name']); |
|
116 | 116 | pyroutes.register('edit_repo', '/%(repo_name)s/settings', ['repo_name']); |
|
117 | 117 | pyroutes.register('edit_repo_advanced', '/%(repo_name)s/settings/advanced', ['repo_name']); |
|
118 | 118 | pyroutes.register('edit_repo_advanced_delete', '/%(repo_name)s/settings/advanced/delete', ['repo_name']); |
|
119 | 119 | pyroutes.register('edit_repo_advanced_locking', '/%(repo_name)s/settings/advanced/locking', ['repo_name']); |
|
120 | 120 | pyroutes.register('edit_repo_advanced_journal', '/%(repo_name)s/settings/advanced/journal', ['repo_name']); |
|
121 | 121 | pyroutes.register('edit_repo_advanced_fork', '/%(repo_name)s/settings/advanced/fork', ['repo_name']); |
|
122 | 122 | pyroutes.register('edit_repo_caches', '/%(repo_name)s/settings/caches', ['repo_name']); |
|
123 | 123 | pyroutes.register('edit_repo_perms', '/%(repo_name)s/settings/permissions', ['repo_name']); |
|
124 | 124 | pyroutes.register('repo_reviewers', '/%(repo_name)s/settings/review/rules', ['repo_name']); |
|
125 | 125 | pyroutes.register('repo_default_reviewers_data', '/%(repo_name)s/settings/review/default-reviewers', ['repo_name']); |
|
126 | 126 | pyroutes.register('repo_maintenance', '/%(repo_name)s/settings/maintenance', ['repo_name']); |
|
127 | 127 | pyroutes.register('repo_maintenance_execute', '/%(repo_name)s/settings/maintenance/execute', ['repo_name']); |
|
128 | 128 | pyroutes.register('strip', '/%(repo_name)s/settings/strip', ['repo_name']); |
|
129 | 129 | pyroutes.register('strip_check', '/%(repo_name)s/settings/strip_check', ['repo_name']); |
|
130 | 130 | pyroutes.register('strip_execute', '/%(repo_name)s/settings/strip_execute', ['repo_name']); |
|
131 | 131 | pyroutes.register('repo_summary', '/%(repo_name)s', ['repo_name']); |
|
132 | 132 | pyroutes.register('repo_summary_slash', '/%(repo_name)s/', ['repo_name']); |
|
133 | 133 | pyroutes.register('repo_group_home', '/%(repo_group_name)s', ['repo_group_name']); |
|
134 | 134 | pyroutes.register('repo_group_home_slash', '/%(repo_group_name)s/', ['repo_group_name']); |
|
135 | 135 | pyroutes.register('search', '/_admin/search', []); |
|
136 | 136 | pyroutes.register('search_repo', '/%(repo_name)s/search', ['repo_name']); |
|
137 | 137 | pyroutes.register('user_profile', '/_profiles/%(username)s', ['username']); |
|
138 | 138 | pyroutes.register('my_account_profile', '/_admin/my_account/profile', []); |
|
139 | 139 | pyroutes.register('my_account_password', '/_admin/my_account/password', []); |
|
140 | 140 | pyroutes.register('my_account_password_update', '/_admin/my_account/password', []); |
|
141 | 141 | pyroutes.register('my_account_auth_tokens', '/_admin/my_account/auth_tokens', []); |
|
142 | 142 | pyroutes.register('my_account_auth_tokens_add', '/_admin/my_account/auth_tokens/new', []); |
|
143 | 143 | pyroutes.register('my_account_auth_tokens_delete', '/_admin/my_account/auth_tokens/delete', []); |
|
144 | 144 | pyroutes.register('my_account_emails', '/_admin/my_account/emails', []); |
|
145 | 145 | pyroutes.register('my_account_emails_add', '/_admin/my_account/emails/new', []); |
|
146 | 146 | pyroutes.register('my_account_emails_delete', '/_admin/my_account/emails/delete', []); |
|
147 | 147 | pyroutes.register('my_account_repos', '/_admin/my_account/repos', []); |
|
148 | 148 | pyroutes.register('my_account_watched', '/_admin/my_account/watched', []); |
|
149 | 149 | pyroutes.register('my_account_perms', '/_admin/my_account/perms', []); |
|
150 | 150 | pyroutes.register('my_account_notifications', '/_admin/my_account/notifications', []); |
|
151 | 151 | pyroutes.register('my_account_notifications_toggle_visibility', '/_admin/my_account/toggle_visibility', []); |
|
152 | 152 | pyroutes.register('my_account_notifications_test_channelstream', '/_admin/my_account/test_channelstream', []); |
|
153 | 153 | pyroutes.register('apiv2', '/_admin/api', []); |
|
154 | 154 | } |
@@ -1,312 +1,315 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | |
|
3 | 3 | # Copyright (C) 2010-2017 RhodeCode GmbH |
|
4 | 4 | # |
|
5 | 5 | # This program is free software: you can redistribute it and/or modify |
|
6 | 6 | # it under the terms of the GNU Affero General Public License, version 3 |
|
7 | 7 | # (only), as published by the Free Software Foundation. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU Affero General Public License |
|
15 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 | 16 | # |
|
17 | 17 | # This program is dual-licensed. If you wish to learn more about the |
|
18 | 18 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
19 | 19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
20 | 20 | import io |
|
21 | 21 | import re |
|
22 | 22 | import datetime |
|
23 | 23 | import logging |
|
24 | 24 | import pylons |
|
25 | 25 | import Queue |
|
26 | 26 | import subprocess32 |
|
27 | 27 | import os |
|
28 | 28 | |
|
29 | 29 | from pyramid.i18n import get_localizer |
|
30 | 30 | from pyramid.threadlocal import get_current_request |
|
31 | 31 | from pyramid.interfaces import IRoutesMapper |
|
32 | 32 | from pyramid.settings import asbool |
|
33 | 33 | from pyramid.path import AssetResolver |
|
34 | 34 | from threading import Thread |
|
35 | 35 | |
|
36 | 36 | from rhodecode.translation import _ as tsf |
|
37 | 37 | from rhodecode.config.jsroutes import generate_jsroutes_content |
|
38 | 38 | |
|
39 | 39 | import rhodecode |
|
40 | 40 | |
|
41 | 41 | from pylons.i18n.translation import _get_translator |
|
42 | 42 | from pylons.util import ContextObj |
|
43 | 43 | from routes.util import URLGenerator |
|
44 | 44 | |
|
45 | 45 | from rhodecode.lib.base import attach_context_attributes, get_auth_user |
|
46 | 46 | |
|
47 | 47 | log = logging.getLogger(__name__) |
|
48 | 48 | |
|
49 | 49 | |
|
50 | 50 | def add_renderer_globals(event): |
|
51 | 51 | # Put pylons stuff into the context. This will be removed as soon as |
|
52 | 52 | # migration to pyramid is finished. |
|
53 | 53 | conf = pylons.config._current_obj() |
|
54 | 54 | event['h'] = conf.get('pylons.h') |
|
55 | 55 | event['c'] = pylons.tmpl_context |
|
56 | 56 | event['url'] = pylons.url |
|
57 | 57 | |
|
58 | 58 | # TODO: When executed in pyramid view context the request is not available |
|
59 | 59 | # in the event. Find a better solution to get the request. |
|
60 | 60 | request = event['request'] or get_current_request() |
|
61 | 61 | |
|
62 | 62 | # Add Pyramid translation as '_' to context |
|
63 | 63 | event['_'] = request.translate |
|
64 | 64 | event['_ungettext'] = request.plularize |
|
65 | 65 | |
|
66 | 66 | |
|
67 | 67 | def add_localizer(event): |
|
68 | 68 | request = event.request |
|
69 | 69 | localizer = get_localizer(request) |
|
70 | 70 | |
|
71 | 71 | def auto_translate(*args, **kwargs): |
|
72 | 72 | return localizer.translate(tsf(*args, **kwargs)) |
|
73 | 73 | |
|
74 | 74 | request.localizer = localizer |
|
75 | 75 | request.translate = auto_translate |
|
76 | 76 | request.plularize = localizer.pluralize |
|
77 | 77 | |
|
78 | 78 | |
|
79 | 79 | def set_user_lang(event): |
|
80 | 80 | request = event.request |
|
81 | 81 | cur_user = getattr(request, 'user', None) |
|
82 | 82 | |
|
83 | 83 | if cur_user: |
|
84 | 84 | user_lang = cur_user.get_instance().user_data.get('language') |
|
85 | 85 | if user_lang: |
|
86 | 86 | log.debug('lang: setting current user:%s language to: %s', cur_user, user_lang) |
|
87 | 87 | event.request._LOCALE_ = user_lang |
|
88 | 88 | |
|
89 | 89 | |
|
90 | 90 | def add_pylons_context(event): |
|
91 | 91 | request = event.request |
|
92 | 92 | |
|
93 | 93 | config = rhodecode.CONFIG |
|
94 | 94 | environ = request.environ |
|
95 | 95 | session = request.session |
|
96 | 96 | |
|
97 | 97 | if hasattr(request, 'vcs_call'): |
|
98 | 98 | # skip vcs calls |
|
99 | 99 | return |
|
100 | 100 | |
|
101 | 101 | # Setup pylons globals. |
|
102 | 102 | pylons.config._push_object(config) |
|
103 | 103 | pylons.request._push_object(request) |
|
104 | 104 | pylons.session._push_object(session) |
|
105 | 105 | pylons.translator._push_object(_get_translator(config.get('lang'))) |
|
106 | 106 | |
|
107 | 107 | pylons.url._push_object(URLGenerator(config['routes.map'], environ)) |
|
108 | 108 | session_key = ( |
|
109 | 109 | config['pylons.environ_config'].get('session', 'beaker.session')) |
|
110 | 110 | environ[session_key] = session |
|
111 | 111 | |
|
112 | 112 | if hasattr(request, 'rpc_method'): |
|
113 | 113 | # skip api calls |
|
114 | 114 | return |
|
115 | 115 | |
|
116 | 116 | # Get the rhodecode auth user object and make it available. |
|
117 | 117 | auth_user = get_auth_user(environ) |
|
118 | 118 | request.user = auth_user |
|
119 | 119 | environ['rc_auth_user'] = auth_user |
|
120 | 120 | |
|
121 | 121 | # Setup the pylons context object ('c') |
|
122 | 122 | context = ContextObj() |
|
123 | 123 | context.rhodecode_user = auth_user |
|
124 | 124 | attach_context_attributes(context, request, request.user.user_id) |
|
125 | 125 | pylons.tmpl_context._push_object(context) |
|
126 | 126 | |
|
127 | 127 | |
|
128 | 128 | def scan_repositories_if_enabled(event): |
|
129 | 129 | """ |
|
130 | 130 | This is subscribed to the `pyramid.events.ApplicationCreated` event. It |
|
131 | 131 | does a repository scan if enabled in the settings. |
|
132 | 132 | """ |
|
133 | 133 | settings = event.app.registry.settings |
|
134 | 134 | vcs_server_enabled = settings['vcs.server.enable'] |
|
135 | 135 | import_on_startup = settings['startup.import_repos'] |
|
136 | 136 | if vcs_server_enabled and import_on_startup: |
|
137 | 137 | from rhodecode.model.scm import ScmModel |
|
138 | 138 | from rhodecode.lib.utils import repo2db_mapper, get_rhodecode_base_path |
|
139 | 139 | repositories = ScmModel().repo_scan(get_rhodecode_base_path()) |
|
140 | 140 | repo2db_mapper(repositories, remove_obsolete=False) |
|
141 | 141 | |
|
142 | 142 | |
|
143 | 143 | def write_metadata_if_needed(event): |
|
144 | 144 | """ |
|
145 | 145 | Writes upgrade metadata |
|
146 | 146 | """ |
|
147 | 147 | import rhodecode |
|
148 | 148 | from rhodecode.lib import system_info |
|
149 | 149 | from rhodecode.lib import ext_json |
|
150 | 150 | |
|
151 | 151 | def write(): |
|
152 | 152 | fname = '.rcmetadata.json' |
|
153 | 153 | ini_loc = os.path.dirname(rhodecode.CONFIG.get('__file__')) |
|
154 | 154 | metadata_destination = os.path.join(ini_loc, fname) |
|
155 | 155 | |
|
156 | 156 | configuration = system_info.SysInfo( |
|
157 | 157 | system_info.rhodecode_config)()['value'] |
|
158 | 158 | license_token = configuration['config']['license_token'] |
|
159 | 159 | dbinfo = system_info.SysInfo(system_info.database_info)()['value'] |
|
160 | 160 | del dbinfo['url'] |
|
161 | 161 | metadata = dict( |
|
162 | 162 | desc='upgrade metadata info', |
|
163 | 163 | license_token=license_token, |
|
164 | 164 | created_on=datetime.datetime.utcnow().isoformat(), |
|
165 | 165 | usage=system_info.SysInfo(system_info.usage_info)()['value'], |
|
166 | 166 | platform=system_info.SysInfo(system_info.platform_type)()['value'], |
|
167 | 167 | database=dbinfo, |
|
168 | 168 | cpu=system_info.SysInfo(system_info.cpu)()['value'], |
|
169 | 169 | memory=system_info.SysInfo(system_info.memory)()['value'], |
|
170 | 170 | ) |
|
171 | 171 | |
|
172 | 172 | with open(metadata_destination, 'wb') as f: |
|
173 | 173 | f.write(ext_json.json.dumps(metadata)) |
|
174 | 174 | |
|
175 | 175 | settings = event.app.registry.settings |
|
176 | 176 | if settings.get('metadata.skip'): |
|
177 | 177 | return |
|
178 | 178 | |
|
179 | 179 | try: |
|
180 | 180 | write() |
|
181 | 181 | except Exception: |
|
182 | 182 | pass |
|
183 | 183 | |
|
184 | 184 | |
|
185 | 185 | def write_js_routes_if_enabled(event): |
|
186 | 186 | registry = event.app.registry |
|
187 | 187 | |
|
188 | 188 | mapper = registry.queryUtility(IRoutesMapper) |
|
189 | 189 | _argument_prog = re.compile('\{(.*?)\}|:\((.*)\)') |
|
190 | 190 | |
|
191 | 191 | def _extract_route_information(route): |
|
192 | 192 | """ |
|
193 | 193 | Convert a route into tuple(name, path, args), eg: |
|
194 | 194 | ('show_user', '/profile/%(username)s', ['username']) |
|
195 | 195 | """ |
|
196 | 196 | |
|
197 | 197 | routepath = route.pattern |
|
198 | 198 | pattern = route.pattern |
|
199 | 199 | |
|
200 | 200 | def replace(matchobj): |
|
201 | 201 | if matchobj.group(1): |
|
202 | 202 | return "%%(%s)s" % matchobj.group(1).split(':')[0] |
|
203 | 203 | else: |
|
204 | 204 | return "%%(%s)s" % matchobj.group(2) |
|
205 | 205 | |
|
206 | 206 | routepath = _argument_prog.sub(replace, routepath) |
|
207 | 207 | |
|
208 | if not routepath.startswith('/'): | |
|
209 | routepath = '/'+routepath | |
|
210 | ||
|
208 | 211 | return ( |
|
209 | 212 | route.name, |
|
210 | 213 | routepath, |
|
211 | 214 | [(arg[0].split(':')[0] if arg[0] != '' else arg[1]) |
|
212 | 215 | for arg in _argument_prog.findall(pattern)] |
|
213 | 216 | ) |
|
214 | 217 | |
|
215 | 218 | def get_routes(): |
|
216 | 219 | # pylons routes |
|
217 | 220 | for route in rhodecode.CONFIG['routes.map'].jsroutes(): |
|
218 | 221 | yield route |
|
219 | 222 | |
|
220 | 223 | # pyramid routes |
|
221 | 224 | for route in mapper.get_routes(): |
|
222 | 225 | if not route.name.startswith('__'): |
|
223 | 226 | yield _extract_route_information(route) |
|
224 | 227 | |
|
225 | 228 | if asbool(registry.settings.get('generate_js_files', 'false')): |
|
226 | 229 | static_path = AssetResolver().resolve('rhodecode:public').abspath() |
|
227 | 230 | jsroutes = get_routes() |
|
228 | 231 | jsroutes_file_content = generate_jsroutes_content(jsroutes) |
|
229 | 232 | jsroutes_file_path = os.path.join( |
|
230 | 233 | static_path, 'js', 'rhodecode', 'routes.js') |
|
231 | 234 | |
|
232 | 235 | with io.open(jsroutes_file_path, 'w', encoding='utf-8') as f: |
|
233 | 236 | f.write(jsroutes_file_content) |
|
234 | 237 | |
|
235 | 238 | |
|
236 | 239 | class Subscriber(object): |
|
237 | 240 | """ |
|
238 | 241 | Base class for subscribers to the pyramid event system. |
|
239 | 242 | """ |
|
240 | 243 | def __call__(self, event): |
|
241 | 244 | self.run(event) |
|
242 | 245 | |
|
243 | 246 | def run(self, event): |
|
244 | 247 | raise NotImplementedError('Subclass has to implement this.') |
|
245 | 248 | |
|
246 | 249 | |
|
247 | 250 | class AsyncSubscriber(Subscriber): |
|
248 | 251 | """ |
|
249 | 252 | Subscriber that handles the execution of events in a separate task to not |
|
250 | 253 | block the execution of the code which triggers the event. It puts the |
|
251 | 254 | received events into a queue from which the worker process takes them in |
|
252 | 255 | order. |
|
253 | 256 | """ |
|
254 | 257 | def __init__(self): |
|
255 | 258 | self._stop = False |
|
256 | 259 | self._eventq = Queue.Queue() |
|
257 | 260 | self._worker = self.create_worker() |
|
258 | 261 | self._worker.start() |
|
259 | 262 | |
|
260 | 263 | def __call__(self, event): |
|
261 | 264 | self._eventq.put(event) |
|
262 | 265 | |
|
263 | 266 | def create_worker(self): |
|
264 | 267 | worker = Thread(target=self.do_work) |
|
265 | 268 | worker.daemon = True |
|
266 | 269 | return worker |
|
267 | 270 | |
|
268 | 271 | def stop_worker(self): |
|
269 | 272 | self._stop = False |
|
270 | 273 | self._eventq.put(None) |
|
271 | 274 | self._worker.join() |
|
272 | 275 | |
|
273 | 276 | def do_work(self): |
|
274 | 277 | while not self._stop: |
|
275 | 278 | event = self._eventq.get() |
|
276 | 279 | if event is not None: |
|
277 | 280 | self.run(event) |
|
278 | 281 | |
|
279 | 282 | |
|
280 | 283 | class AsyncSubprocessSubscriber(AsyncSubscriber): |
|
281 | 284 | """ |
|
282 | 285 | Subscriber that uses the subprocess32 module to execute a command if an |
|
283 | 286 | event is received. Events are handled asynchronously. |
|
284 | 287 | """ |
|
285 | 288 | |
|
286 | 289 | def __init__(self, cmd, timeout=None): |
|
287 | 290 | super(AsyncSubprocessSubscriber, self).__init__() |
|
288 | 291 | self._cmd = cmd |
|
289 | 292 | self._timeout = timeout |
|
290 | 293 | |
|
291 | 294 | def run(self, event): |
|
292 | 295 | cmd = self._cmd |
|
293 | 296 | timeout = self._timeout |
|
294 | 297 | log.debug('Executing command %s.', cmd) |
|
295 | 298 | |
|
296 | 299 | try: |
|
297 | 300 | output = subprocess32.check_output( |
|
298 | 301 | cmd, timeout=timeout, stderr=subprocess32.STDOUT) |
|
299 | 302 | log.debug('Command finished %s', cmd) |
|
300 | 303 | if output: |
|
301 | 304 | log.debug('Command output: %s', output) |
|
302 | 305 | except subprocess32.TimeoutExpired as e: |
|
303 | 306 | log.exception('Timeout while executing command.') |
|
304 | 307 | if e.output: |
|
305 | 308 | log.error('Command output: %s', e.output) |
|
306 | 309 | except subprocess32.CalledProcessError as e: |
|
307 | 310 | log.exception('Error while executing command.') |
|
308 | 311 | if e.output: |
|
309 | 312 | log.error('Command output: %s', e.output) |
|
310 | 313 | except: |
|
311 | 314 | log.exception( |
|
312 | 315 | 'Exception while executing command %s.', cmd) |
General Comments 0
You need to be logged in to leave comments.
Login now