Show More
@@ -1,147 +1,146 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | """ |
|
3 | 3 | rhodecode.controllers.summary |
|
4 | 4 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
5 | 5 | |
|
6 | 6 | Summary controller for Rhodecode |
|
7 | 7 | |
|
8 | 8 | :created_on: Apr 18, 2010 |
|
9 | 9 | :author: marcink |
|
10 | 10 | :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com> |
|
11 | 11 | :license: GPLv3, see COPYING for more details. |
|
12 | 12 | """ |
|
13 | 13 | # This program is free software; you can redistribute it and/or |
|
14 | 14 | # modify it under the terms of the GNU General Public License |
|
15 | 15 | # as published by the Free Software Foundation; version 2 |
|
16 | 16 | # of the License or (at your opinion) any later version of the license. |
|
17 | 17 | # |
|
18 | 18 | # This program is distributed in the hope that it will be useful, |
|
19 | 19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
20 | 20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
21 | 21 | # GNU General Public License for more details. |
|
22 | 22 | # |
|
23 | 23 | # You should have received a copy of the GNU General Public License |
|
24 | 24 | # along with this program; if not, write to the Free Software |
|
25 | 25 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
26 | 26 | # MA 02110-1301, USA. |
|
27 | 27 | |
|
28 | 28 | import calendar |
|
29 | 29 | import logging |
|
30 | 30 | from time import mktime |
|
31 | from datetime import datetime, timedelta | |
|
31 | from datetime import datetime, timedelta, date | |
|
32 | 32 | |
|
33 | 33 | from vcs.exceptions import ChangesetError |
|
34 | 34 | |
|
35 | 35 | from pylons import tmpl_context as c, request, url |
|
36 | 36 | from pylons.i18n.translation import _ |
|
37 | 37 | |
|
38 | 38 | from rhodecode.model.scm import ScmModel |
|
39 | 39 | from rhodecode.model.db import Statistics |
|
40 | 40 | |
|
41 | 41 | from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator |
|
42 | 42 | from rhodecode.lib.base import BaseController, render |
|
43 | 43 | from rhodecode.lib.utils import OrderedDict, EmptyChangeset |
|
44 | 44 | |
|
45 | 45 | from rhodecode.lib.celerylib import run_task |
|
46 | 46 | from rhodecode.lib.celerylib.tasks import get_commits_stats |
|
47 | 47 | |
|
48 | 48 | from webhelpers.paginate import Page |
|
49 | 49 | |
|
50 | 50 | try: |
|
51 | 51 | import json |
|
52 | 52 | except ImportError: |
|
53 | 53 | #python 2.5 compatibility |
|
54 | 54 | import simplejson as json |
|
55 | 55 | log = logging.getLogger(__name__) |
|
56 | 56 | |
|
57 | 57 | class SummaryController(BaseController): |
|
58 | 58 | |
|
59 | 59 | @LoginRequired() |
|
60 | 60 | @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', |
|
61 | 61 | 'repository.admin') |
|
62 | 62 | def __before__(self): |
|
63 | 63 | super(SummaryController, self).__before__() |
|
64 | 64 | |
|
65 | 65 | def index(self): |
|
66 | 66 | scm_model = ScmModel() |
|
67 | 67 | c.repo_info = scm_model.get_repo(c.repo_name) |
|
68 | 68 | c.following = scm_model.is_following_repo(c.repo_name, |
|
69 | 69 | c.rhodecode_user.user_id) |
|
70 | 70 | def url_generator(**kw): |
|
71 | 71 | return url('shortlog_home', repo_name=c.repo_name, **kw) |
|
72 | 72 | |
|
73 | 73 | c.repo_changesets = Page(c.repo_info, page=1, items_per_page=10, |
|
74 | 74 | url=url_generator) |
|
75 | 75 | |
|
76 | 76 | e = request.environ |
|
77 | 77 | |
|
78 | 78 | if self.rhodecode_user.username == 'default': |
|
79 | 79 | #for default(anonymous) user we don't need to pass credentials |
|
80 | 80 | username = '' |
|
81 | 81 | password = '' |
|
82 | 82 | else: |
|
83 | 83 | username = str(c.rhodecode_user.username) |
|
84 | 84 | password = '@' |
|
85 | 85 | |
|
86 | 86 | uri = u'%(protocol)s://%(user)s%(password)s%(host)s%(prefix)s/%(repo_name)s' % { |
|
87 | 87 | 'protocol': e.get('wsgi.url_scheme'), |
|
88 | 88 | 'user':username, |
|
89 | 89 | 'password':password, |
|
90 | 90 | 'host':e.get('HTTP_HOST'), |
|
91 | 91 | 'prefix':e.get('SCRIPT_NAME'), |
|
92 | 92 | 'repo_name':c.repo_name, } |
|
93 | 93 | c.clone_repo_url = uri |
|
94 | 94 | c.repo_tags = OrderedDict() |
|
95 | 95 | for name, hash in c.repo_info.tags.items()[:10]: |
|
96 | 96 | try: |
|
97 | 97 | c.repo_tags[name] = c.repo_info.get_changeset(hash) |
|
98 | 98 | except ChangesetError: |
|
99 | 99 | c.repo_tags[name] = EmptyChangeset(hash) |
|
100 | 100 | |
|
101 | 101 | c.repo_branches = OrderedDict() |
|
102 | 102 | for name, hash in c.repo_info.branches.items()[:10]: |
|
103 | 103 | try: |
|
104 | 104 | c.repo_branches[name] = c.repo_info.get_changeset(hash) |
|
105 | 105 | except ChangesetError: |
|
106 | 106 | c.repo_branches[name] = EmptyChangeset(hash) |
|
107 | 107 | |
|
108 |
td = date |
|
|
109 | y, m, d = td.year, td.month, td.day | |
|
108 | td = date.today() + timedelta(days=1) | |
|
109 | td_1m = td - timedelta(days=calendar.mdays[td.month]) | |
|
110 | td_1y = td - timedelta(days=365) | |
|
110 | 111 | |
|
111 | ts_min_y = mktime((y - 1, (td - timedelta(days=calendar.mdays[m])).month, | |
|
112 | d, 0, 0, 0, 0, 0, 0,)) | |
|
113 | ts_min_m = mktime((y, (td - timedelta(days=calendar.mdays[m])).month, | |
|
114 | d, 0, 0, 0, 0, 0, 0,)) | |
|
112 | ts_min_m = mktime(td_1m.timetuple()) | |
|
113 | ts_min_y = mktime(td_1y.timetuple()) | |
|
114 | ts_max_y = mktime(td.timetuple()) | |
|
115 | 115 | |
|
116 | ts_max_y = mktime((y, m, d, 0, 0, 0, 0, 0, 0,)) | |
|
117 | 116 | if c.repo_info.dbrepo.enable_statistics: |
|
118 | 117 | c.no_data_msg = _('No data loaded yet') |
|
119 | 118 | run_task(get_commits_stats, c.repo_info.name, ts_min_y, ts_max_y) |
|
120 | 119 | else: |
|
121 | 120 | c.no_data_msg = _('Statistics update are disabled for this repository') |
|
122 | 121 | c.ts_min = ts_min_m |
|
123 | 122 | c.ts_max = ts_max_y |
|
124 | 123 | |
|
125 | 124 | stats = self.sa.query(Statistics)\ |
|
126 | 125 | .filter(Statistics.repository == c.repo_info.dbrepo)\ |
|
127 | 126 | .scalar() |
|
128 | 127 | |
|
129 | 128 | |
|
130 | 129 | if stats and stats.languages: |
|
131 | 130 | c.no_data = False is c.repo_info.dbrepo.enable_statistics |
|
132 | 131 | lang_stats = json.loads(stats.languages) |
|
133 | 132 | c.commit_data = stats.commit_activity |
|
134 | 133 | c.overview_data = stats.commit_activity_combined |
|
135 | 134 | c.trending_languages = json.dumps(OrderedDict( |
|
136 | 135 | sorted(lang_stats.items(), reverse=True, |
|
137 | 136 | key=lambda k: k[1])[:10] |
|
138 | 137 | ) |
|
139 | 138 | ) |
|
140 | 139 | else: |
|
141 | 140 | c.commit_data = json.dumps({}) |
|
142 | 141 | c.overview_data = json.dumps([[ts_min_y, 0], [ts_max_y, 10] ]) |
|
143 | 142 | c.trending_languages = json.dumps({}) |
|
144 | 143 | c.no_data = True |
|
145 | 144 | |
|
146 | 145 | return render('summary/summary.html') |
|
147 | 146 |
General Comments 0
You need to be logged in to leave comments.
Login now