##// END OF EJS Templates
exception-tracker: add show-more link.
ergo -
r2985:0dd49fc6 default
parent child Browse files
Show More
@@ -1,153 +1,154 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2018-2018 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 os
21 21 import logging
22 22
23 23 from pyramid.httpexceptions import HTTPFound
24 24 from pyramid.view import view_config
25 25
26 26 from rhodecode.apps._base import BaseAppView
27 27 from rhodecode.apps.admin.navigation import navigation_list
28 28 from rhodecode.lib import helpers as h
29 29 from rhodecode.lib.auth import (
30 30 LoginRequired, HasPermissionAllDecorator, CSRFRequired)
31 from rhodecode.lib.utils2 import time_to_utcdatetime
31 from rhodecode.lib.utils2 import time_to_utcdatetime, safe_int
32 32 from rhodecode.lib import exc_tracking
33 33
34 34 log = logging.getLogger(__name__)
35 35
36 36
37 37 class ExceptionsTrackerView(BaseAppView):
38 38 def load_default_context(self):
39 39 c = self._get_local_tmpl_context()
40 40 c.navlist = navigation_list(self.request)
41 41 return c
42 42
43 43 def count_all_exceptions(self):
44 44 exc_store_path = exc_tracking.get_exc_store()
45 45 count = 0
46 46 for fname in os.listdir(exc_store_path):
47 47 parts = fname.split('_', 2)
48 48 if not len(parts) == 3:
49 49 continue
50 50 count +=1
51 51 return count
52 52
53 53 def get_all_exceptions(self, read_metadata=False, limit=None):
54 54 exc_store_path = exc_tracking.get_exc_store()
55 55 exception_list = []
56 56
57 57 def key_sorter(val):
58 58 try:
59 59 return val.split('_')[-1]
60 60 except Exception:
61 61 return 0
62 62 count = 0
63 63 for fname in reversed(sorted(os.listdir(exc_store_path), key=key_sorter)):
64 64
65 65 parts = fname.split('_', 2)
66 66 if not len(parts) == 3:
67 67 continue
68 68
69 69 exc_id, app_type, exc_timestamp = parts
70 70
71 71 exc = {'exc_id': exc_id, 'app_type': app_type, 'exc_type': 'unknown',
72 72 'exc_utc_date': '', 'exc_timestamp': exc_timestamp}
73 73
74 74 if read_metadata:
75 75 full_path = os.path.join(exc_store_path, fname)
76 76 # we can read our metadata
77 77 with open(full_path, 'rb') as f:
78 78 exc_metadata = exc_tracking.exc_unserialize(f.read())
79 79 exc.update(exc_metadata)
80 80
81 81 # convert our timestamp to a date obj, for nicer representation
82 82 exc['exc_utc_date'] = time_to_utcdatetime(exc['exc_timestamp'])
83 83 exception_list.append(exc)
84 84
85 85 count += 1
86 86 if limit and count >= limit:
87 87 break
88 88 return exception_list
89 89
90 90 @LoginRequired()
91 91 @HasPermissionAllDecorator('hg.admin')
92 92 @view_config(
93 93 route_name='admin_settings_exception_tracker', request_method='GET',
94 94 renderer='rhodecode:templates/admin/settings/settings.mako')
95 95 def browse_exceptions(self):
96 96 _ = self.request.translate
97 97 c = self.load_default_context()
98 98 c.active = 'exceptions_browse'
99 c.limit = self.request.GET.get('limit', 50)
99 c.limit = safe_int(self.request.GET.get('limit')) or 50
100 c.next_limit = c.limit + 50
100 101 c.exception_list = self.get_all_exceptions(read_metadata=True, limit=c.limit)
101 102 c.exception_list_count = self.count_all_exceptions()
102 103 c.exception_store_dir = exc_tracking.get_exc_store()
103 104 return self._get_template_context(c)
104 105
105 106 @LoginRequired()
106 107 @HasPermissionAllDecorator('hg.admin')
107 108 @view_config(
108 109 route_name='admin_settings_exception_tracker_show', request_method='GET',
109 110 renderer='rhodecode:templates/admin/settings/settings.mako')
110 111 def exception_show(self):
111 112 _ = self.request.translate
112 113 c = self.load_default_context()
113 114
114 115 c.active = 'exceptions'
115 116 c.exception_id = self.request.matchdict['exception_id']
116 117 c.traceback = exc_tracking.read_exception(c.exception_id, prefix=None)
117 118 return self._get_template_context(c)
118 119
119 120 @LoginRequired()
120 121 @HasPermissionAllDecorator('hg.admin')
121 122 @CSRFRequired()
122 123 @view_config(
123 124 route_name='admin_settings_exception_tracker_delete_all', request_method='POST',
124 125 renderer='rhodecode:templates/admin/settings/settings.mako')
125 126 def exception_delete_all(self):
126 127 _ = self.request.translate
127 128 c = self.load_default_context()
128 129
129 130 c.active = 'exceptions'
130 131 all_exc = self.get_all_exceptions()
131 132 exc_count = len(all_exc)
132 133 for exc in all_exc:
133 134 exc_tracking.delete_exception(exc['exc_id'], prefix=None)
134 135
135 136 h.flash(_('Removed {} Exceptions').format(exc_count), category='success')
136 137 raise HTTPFound(h.route_path('admin_settings_exception_tracker'))
137 138
138 139 @LoginRequired()
139 140 @HasPermissionAllDecorator('hg.admin')
140 141 @CSRFRequired()
141 142 @view_config(
142 143 route_name='admin_settings_exception_tracker_delete', request_method='POST',
143 144 renderer='rhodecode:templates/admin/settings/settings.mako')
144 145 def exception_delete(self):
145 146 _ = self.request.translate
146 147 c = self.load_default_context()
147 148
148 149 c.active = 'exceptions'
149 150 c.exception_id = self.request.matchdict['exception_id']
150 151 exc_tracking.delete_exception(c.exception_id, prefix=None)
151 152
152 153 h.flash(_('Removed Exception {}').format(c.exception_id), category='success')
153 154 raise HTTPFound(h.route_path('admin_settings_exception_tracker'))
@@ -1,56 +1,57 b''
1 1 <div class="panel panel-default">
2 2 <div class="panel-heading">
3 3 <h3 class="panel-title">${_('Exceptions Tracker ')}</h3>
4 4 </div>
5 5 <div class="panel-body">
6 6 % if c.exception_list_count == 1:
7 7 ${_('There is {} stored exception.').format(c.exception_list_count)}
8 8 % else:
9 9 ${_('There are {} stored exceptions.').format(c.exception_list_count)}
10 10 % endif
11 11 ${_('Store directory')}: ${c.exception_store_dir}
12 12
13 13 ${h.secure_form(h.route_path('admin_settings_exception_tracker_delete_all'), request=request)}
14 14 <div style="margin: 0 0 20px 0" class="fake-space"></div>
15 15
16 16 <div class="field">
17 17 <button class="btn btn-small btn-danger" type="submit"
18 18 onclick="return confirm('${_('Confirm to delete all exceptions')}');">
19 19 <i class="icon-remove-sign"></i>
20 20 ${_('Delete All')}
21 21 </button>
22 22 </div>
23 23
24 24 ${h.end_form()}
25 25
26 26 </div>
27 27 </div>
28 28
29 29
30 30 <div class="panel panel-default">
31 31 <div class="panel-heading">
32 <h3 class="panel-title">${_('Exceptions Tracker - Showing the last {} Exceptions').format(c.limit)}</h3>
32 <h3 class="panel-title">${_('Exceptions Tracker - Showing the last {} Exceptions').format(c.limit)}.</h3>
33 <a class="panel-edit" href="${h.current_route_path(request, limit=c.next_limit)}">${_('Show more')}</a>
33 34 </div>
34 35 <div class="panel-body">
35 36 <table class="rctable">
36 37 <tr>
37 38 <th>#</th>
38 39 <th>Exception ID</th>
39 40 <th>Date</th>
40 41 <th>App Type</th>
41 42 <th>Exc Type</th>
42 43 </tr>
43 44 <% cnt = len(c.exception_list)%>
44 45 % for tb in c.exception_list:
45 46 <tr>
46 47 <td>${cnt}</td>
47 48 <td><a href="${h.route_path('admin_settings_exception_tracker_show', exception_id=tb['exc_id'])}"><code>${tb['exc_id']}</code></a></td>
48 49 <td>${h.format_date(tb['exc_utc_date'])}</td>
49 50 <td>${tb['app_type']}</td>
50 51 <td>${tb['exc_type']}</td>
51 52 </tr>
52 53 <% cnt -=1 %>
53 54 % endfor
54 55 </table>
55 56 </div>
56 57 </div>
General Comments 0
You need to be logged in to leave comments. Login now