##// END OF EJS Templates
remove obsolete and not used branches/tags extraction on summary page
marcink -
r3762:f485eb78 beta
parent child Browse files
Show More
@@ -1,264 +1,251 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """
2 """
3 rhodecode.controllers.summary
3 rhodecode.controllers.summary
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5
5
6 Summary controller for Rhodecode
6 Summary controller for Rhodecode
7
7
8 :created_on: Apr 18, 2010
8 :created_on: Apr 18, 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 traceback
26 import traceback
27 import calendar
27 import calendar
28 import logging
28 import logging
29 import urllib
29 import urllib
30 from time import mktime
30 from time import mktime
31 from datetime import timedelta, date
31 from datetime import timedelta, date
32 from urlparse import urlparse
32 from urlparse import urlparse
33
33
34 from pylons import tmpl_context as c, request, url, config
34 from pylons import tmpl_context as c, request, url, config
35 from pylons.i18n.translation import _
35 from pylons.i18n.translation import _
36 from webob.exc import HTTPBadRequest
36 from webob.exc import HTTPBadRequest
37
37
38 from beaker.cache import cache_region, region_invalidate
38 from beaker.cache import cache_region, region_invalidate
39
39
40 from rhodecode.lib import helpers as h
40 from rhodecode.lib import helpers as h
41 from rhodecode.lib.compat import product
41 from rhodecode.lib.compat import product
42 from rhodecode.lib.vcs.exceptions import ChangesetError, EmptyRepositoryError, \
42 from rhodecode.lib.vcs.exceptions import ChangesetError, EmptyRepositoryError, \
43 NodeDoesNotExistError
43 NodeDoesNotExistError
44 from rhodecode.config.conf import ALL_READMES, ALL_EXTS, LANGUAGES_EXTENSIONS_MAP
44 from rhodecode.config.conf import ALL_READMES, ALL_EXTS, LANGUAGES_EXTENSIONS_MAP
45 from rhodecode.model.db import Statistics, CacheInvalidation
45 from rhodecode.model.db import Statistics, CacheInvalidation
46 from rhodecode.lib.utils import jsonify
46 from rhodecode.lib.utils import jsonify
47 from rhodecode.lib.utils2 import safe_unicode, safe_str
47 from rhodecode.lib.utils2 import safe_unicode, safe_str
48 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator,\
48 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator,\
49 NotAnonymous
49 NotAnonymous
50 from rhodecode.lib.base import BaseRepoController, render
50 from rhodecode.lib.base import BaseRepoController, render
51 from rhodecode.lib.vcs.backends.base import EmptyChangeset
51 from rhodecode.lib.vcs.backends.base import EmptyChangeset
52 from rhodecode.lib.markup_renderer import MarkupRenderer
52 from rhodecode.lib.markup_renderer import MarkupRenderer
53 from rhodecode.lib.celerylib import run_task
53 from rhodecode.lib.celerylib import run_task
54 from rhodecode.lib.celerylib.tasks import get_commits_stats
54 from rhodecode.lib.celerylib.tasks import get_commits_stats
55 from rhodecode.lib.helpers import RepoPage
55 from rhodecode.lib.helpers import RepoPage
56 from rhodecode.lib.compat import json, OrderedDict
56 from rhodecode.lib.compat import json, OrderedDict
57 from rhodecode.lib.vcs.nodes import FileNode
57 from rhodecode.lib.vcs.nodes import FileNode
58
58
59 log = logging.getLogger(__name__)
59 log = logging.getLogger(__name__)
60
60
61 README_FILES = [''.join([x[0][0], x[1][0]]) for x in
61 README_FILES = [''.join([x[0][0], x[1][0]]) for x in
62 sorted(list(product(ALL_READMES, ALL_EXTS)),
62 sorted(list(product(ALL_READMES, ALL_EXTS)),
63 key=lambda y:y[0][1] + y[1][1])]
63 key=lambda y:y[0][1] + y[1][1])]
64
64
65
65
66 class SummaryController(BaseRepoController):
66 class SummaryController(BaseRepoController):
67
67
68 def __before__(self):
68 def __before__(self):
69 super(SummaryController, self).__before__()
69 super(SummaryController, self).__before__()
70
70
71 def _get_download_links(self, repo):
71 def _get_download_links(self, repo):
72
72
73 download_l = []
73 download_l = []
74
74
75 branches_group = ([], _("Branches"))
75 branches_group = ([], _("Branches"))
76 tags_group = ([], _("Tags"))
76 tags_group = ([], _("Tags"))
77
77
78 for name, chs in c.rhodecode_repo.branches.items():
78 for name, chs in c.rhodecode_repo.branches.items():
79 #chs = chs.split(':')[-1]
79 #chs = chs.split(':')[-1]
80 branches_group[0].append((chs, name),)
80 branches_group[0].append((chs, name),)
81 download_l.append(branches_group)
81 download_l.append(branches_group)
82
82
83 for name, chs in c.rhodecode_repo.tags.items():
83 for name, chs in c.rhodecode_repo.tags.items():
84 #chs = chs.split(':')[-1]
84 #chs = chs.split(':')[-1]
85 tags_group[0].append((chs, name),)
85 tags_group[0].append((chs, name),)
86 download_l.append(tags_group)
86 download_l.append(tags_group)
87
87
88 return download_l
88 return download_l
89
89
90
90
91 def __get_readme_data(self, db_repo):
91 def __get_readme_data(self, db_repo):
92 repo_name = db_repo.repo_name
92 repo_name = db_repo.repo_name
93
93
94 @cache_region('long_term')
94 @cache_region('long_term')
95 def _get_readme_from_cache(key):
95 def _get_readme_from_cache(key):
96 readme_data = None
96 readme_data = None
97 readme_file = None
97 readme_file = None
98 log.debug('Looking for README file')
98 log.debug('Looking for README file')
99 try:
99 try:
100 # get's the landing revision! or tip if fails
100 # get's the landing revision! or tip if fails
101 cs = db_repo.get_landing_changeset()
101 cs = db_repo.get_landing_changeset()
102 if isinstance(cs, EmptyChangeset):
102 if isinstance(cs, EmptyChangeset):
103 raise EmptyRepositoryError()
103 raise EmptyRepositoryError()
104 renderer = MarkupRenderer()
104 renderer = MarkupRenderer()
105 for f in README_FILES:
105 for f in README_FILES:
106 try:
106 try:
107 readme = cs.get_node(f)
107 readme = cs.get_node(f)
108 if not isinstance(readme, FileNode):
108 if not isinstance(readme, FileNode):
109 continue
109 continue
110 readme_file = f
110 readme_file = f
111 log.debug('Found README file `%s` rendering...' %
111 log.debug('Found README file `%s` rendering...' %
112 readme_file)
112 readme_file)
113 readme_data = renderer.render(readme.content, f)
113 readme_data = renderer.render(readme.content, f)
114 break
114 break
115 except NodeDoesNotExistError:
115 except NodeDoesNotExistError:
116 continue
116 continue
117 except ChangesetError:
117 except ChangesetError:
118 log.error(traceback.format_exc())
118 log.error(traceback.format_exc())
119 pass
119 pass
120 except EmptyRepositoryError:
120 except EmptyRepositoryError:
121 pass
121 pass
122 except Exception:
122 except Exception:
123 log.error(traceback.format_exc())
123 log.error(traceback.format_exc())
124
124
125 return readme_data, readme_file
125 return readme_data, readme_file
126
126
127 key = repo_name + '_README'
127 key = repo_name + '_README'
128 inv = CacheInvalidation.invalidate(key)
128 inv = CacheInvalidation.invalidate(key)
129 if inv is not None:
129 if inv is not None:
130 region_invalidate(_get_readme_from_cache, None, key)
130 region_invalidate(_get_readme_from_cache, None, key)
131 CacheInvalidation.set_valid(inv.cache_key)
131 CacheInvalidation.set_valid(inv.cache_key)
132 return _get_readme_from_cache(key)
132 return _get_readme_from_cache(key)
133
133
134 @LoginRequired()
134 @LoginRequired()
135 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
135 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
136 'repository.admin')
136 'repository.admin')
137 def index(self, repo_name):
137 def index(self, repo_name):
138 c.dbrepo = dbrepo = c.rhodecode_db_repo
138 c.dbrepo = dbrepo = c.rhodecode_db_repo
139
139
140 def url_generator(**kw):
140 def url_generator(**kw):
141 return url('shortlog_home', repo_name=repo_name, size=10, **kw)
141 return url('shortlog_home', repo_name=repo_name, size=10, **kw)
142
142
143 c.repo_changesets = RepoPage(c.rhodecode_repo, page=1,
143 c.repo_changesets = RepoPage(c.rhodecode_repo, page=1,
144 items_per_page=10, url=url_generator)
144 items_per_page=10, url=url_generator)
145 page_revisions = [x.raw_id for x in list(c.repo_changesets)]
145 page_revisions = [x.raw_id for x in list(c.repo_changesets)]
146 c.statuses = c.rhodecode_db_repo.statuses(page_revisions)
146 c.statuses = c.rhodecode_db_repo.statuses(page_revisions)
147
147
148 if self.rhodecode_user.username == 'default':
148 if self.rhodecode_user.username == 'default':
149 # for default(anonymous) user we don't need to pass credentials
149 # for default(anonymous) user we don't need to pass credentials
150 username = ''
150 username = ''
151 password = ''
151 password = ''
152 else:
152 else:
153 username = str(self.rhodecode_user.username)
153 username = str(self.rhodecode_user.username)
154 password = '@'
154 password = '@'
155
155
156 parsed_url = urlparse(url.current(qualified=True))
156 parsed_url = urlparse(url.current(qualified=True))
157
157
158 default_clone_uri = '{scheme}://{user}{pass}{netloc}{path}'
158 default_clone_uri = '{scheme}://{user}{pass}{netloc}{path}'
159
159
160 uri_tmpl = config.get('clone_uri', default_clone_uri)
160 uri_tmpl = config.get('clone_uri', default_clone_uri)
161 uri_tmpl = uri_tmpl.replace('{', '%(').replace('}', ')s')
161 uri_tmpl = uri_tmpl.replace('{', '%(').replace('}', ')s')
162 decoded_path = safe_unicode(urllib.unquote(parsed_url.path))
162 decoded_path = safe_unicode(urllib.unquote(parsed_url.path))
163 uri_dict = {
163 uri_dict = {
164 'user': urllib.quote(username),
164 'user': urllib.quote(username),
165 'pass': password,
165 'pass': password,
166 'scheme': parsed_url.scheme,
166 'scheme': parsed_url.scheme,
167 'netloc': parsed_url.netloc,
167 'netloc': parsed_url.netloc,
168 'path': urllib.quote(safe_str(decoded_path))
168 'path': urllib.quote(safe_str(decoded_path))
169 }
169 }
170
170
171 uri = (uri_tmpl % uri_dict)
171 uri = (uri_tmpl % uri_dict)
172 # generate another clone url by id
172 # generate another clone url by id
173 uri_dict.update(
173 uri_dict.update(
174 {'path': decoded_path.replace(repo_name, '_%s' % c.dbrepo.repo_id)}
174 {'path': decoded_path.replace(repo_name, '_%s' % c.dbrepo.repo_id)}
175 )
175 )
176 uri_id = uri_tmpl % uri_dict
176 uri_id = uri_tmpl % uri_dict
177
177
178 c.clone_repo_url = uri
178 c.clone_repo_url = uri
179 c.clone_repo_url_id = uri_id
179 c.clone_repo_url_id = uri_id
180 c.repo_tags = OrderedDict()
181 for name, hash_ in c.rhodecode_repo.tags.items()[:10]:
182 try:
183 c.repo_tags[name] = c.rhodecode_repo.get_changeset(hash_)
184 except ChangesetError:
185 c.repo_tags[name] = EmptyChangeset(hash_)
186
187 c.repo_branches = OrderedDict()
188 for name, hash_ in c.rhodecode_repo.branches.items()[:10]:
189 try:
190 c.repo_branches[name] = c.rhodecode_repo.get_changeset(hash_)
191 except ChangesetError:
192 c.repo_branches[name] = EmptyChangeset(hash_)
193
180
194 td = date.today() + timedelta(days=1)
181 td = date.today() + timedelta(days=1)
195 td_1m = td - timedelta(days=calendar.mdays[td.month])
182 td_1m = td - timedelta(days=calendar.mdays[td.month])
196 td_1y = td - timedelta(days=365)
183 td_1y = td - timedelta(days=365)
197
184
198 ts_min_m = mktime(td_1m.timetuple())
185 ts_min_m = mktime(td_1m.timetuple())
199 ts_min_y = mktime(td_1y.timetuple())
186 ts_min_y = mktime(td_1y.timetuple())
200 ts_max_y = mktime(td.timetuple())
187 ts_max_y = mktime(td.timetuple())
201
188
202 if dbrepo.enable_statistics:
189 if dbrepo.enable_statistics:
203 c.show_stats = True
190 c.show_stats = True
204 c.no_data_msg = _('No data loaded yet')
191 c.no_data_msg = _('No data loaded yet')
205 recurse_limit = 500 # don't recurse more than 500 times when parsing
192 recurse_limit = 500 # don't recurse more than 500 times when parsing
206 run_task(get_commits_stats, c.dbrepo.repo_name, ts_min_y,
193 run_task(get_commits_stats, c.dbrepo.repo_name, ts_min_y,
207 ts_max_y, recurse_limit)
194 ts_max_y, recurse_limit)
208 else:
195 else:
209 c.show_stats = False
196 c.show_stats = False
210 c.no_data_msg = _('Statistics are disabled for this repository')
197 c.no_data_msg = _('Statistics are disabled for this repository')
211 c.ts_min = ts_min_m
198 c.ts_min = ts_min_m
212 c.ts_max = ts_max_y
199 c.ts_max = ts_max_y
213
200
214 stats = self.sa.query(Statistics)\
201 stats = self.sa.query(Statistics)\
215 .filter(Statistics.repository == dbrepo)\
202 .filter(Statistics.repository == dbrepo)\
216 .scalar()
203 .scalar()
217
204
218 c.stats_percentage = 0
205 c.stats_percentage = 0
219
206
220 if stats and stats.languages:
207 if stats and stats.languages:
221 c.no_data = False is dbrepo.enable_statistics
208 c.no_data = False is dbrepo.enable_statistics
222 lang_stats_d = json.loads(stats.languages)
209 lang_stats_d = json.loads(stats.languages)
223 c.commit_data = stats.commit_activity
210 c.commit_data = stats.commit_activity
224 c.overview_data = stats.commit_activity_combined
211 c.overview_data = stats.commit_activity_combined
225
212
226 lang_stats = ((x, {"count": y,
213 lang_stats = ((x, {"count": y,
227 "desc": LANGUAGES_EXTENSIONS_MAP.get(x)})
214 "desc": LANGUAGES_EXTENSIONS_MAP.get(x)})
228 for x, y in lang_stats_d.items())
215 for x, y in lang_stats_d.items())
229
216
230 c.trending_languages = json.dumps(
217 c.trending_languages = json.dumps(
231 sorted(lang_stats, reverse=True, key=lambda k: k[1])[:10]
218 sorted(lang_stats, reverse=True, key=lambda k: k[1])[:10]
232 )
219 )
233 last_rev = stats.stat_on_revision + 1
220 last_rev = stats.stat_on_revision + 1
234 c.repo_last_rev = c.rhodecode_repo.count()\
221 c.repo_last_rev = c.rhodecode_repo.count()\
235 if c.rhodecode_repo.revisions else 0
222 if c.rhodecode_repo.revisions else 0
236 if last_rev == 0 or c.repo_last_rev == 0:
223 if last_rev == 0 or c.repo_last_rev == 0:
237 pass
224 pass
238 else:
225 else:
239 c.stats_percentage = '%.2f' % ((float((last_rev)) /
226 c.stats_percentage = '%.2f' % ((float((last_rev)) /
240 c.repo_last_rev) * 100)
227 c.repo_last_rev) * 100)
241 else:
228 else:
242 c.commit_data = json.dumps({})
229 c.commit_data = json.dumps({})
243 c.overview_data = json.dumps([[ts_min_y, 0], [ts_max_y, 10]])
230 c.overview_data = json.dumps([[ts_min_y, 0], [ts_max_y, 10]])
244 c.trending_languages = json.dumps({})
231 c.trending_languages = json.dumps({})
245 c.no_data = True
232 c.no_data = True
246
233
247 c.enable_downloads = dbrepo.enable_downloads
234 c.enable_downloads = dbrepo.enable_downloads
248 if c.enable_downloads:
235 if c.enable_downloads:
249 c.download_options = self._get_download_links(c.rhodecode_repo)
236 c.download_options = self._get_download_links(c.rhodecode_repo)
250
237
251 c.readme_data, c.readme_file = \
238 c.readme_data, c.readme_file = \
252 self.__get_readme_data(c.rhodecode_db_repo)
239 self.__get_readme_data(c.rhodecode_db_repo)
253 return render('summary/summary.html')
240 return render('summary/summary.html')
254
241
255 @LoginRequired()
242 @LoginRequired()
256 @NotAnonymous()
243 @NotAnonymous()
257 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
244 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
258 'repository.admin')
245 'repository.admin')
259 @jsonify
246 @jsonify
260 def repo_size(self, repo_name):
247 def repo_size(self, repo_name):
261 if request.is_xhr:
248 if request.is_xhr:
262 return c.rhodecode_db_repo._repo_size()
249 return c.rhodecode_db_repo._repo_size()
263 else:
250 else:
264 raise HTTPBadRequest()
251 raise HTTPBadRequest()
General Comments 0
You need to be logged in to leave comments. Login now