Show More
@@ -1,90 +1,94 b'' | |||||
1 | #!/usr/bin/env python |
|
1 | #!/usr/bin/env python | |
2 | # encoding: utf-8 |
|
2 | # encoding: utf-8 | |
3 | # changelog controller for pylons |
|
3 | # changelog controller for pylons | |
4 | # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> |
|
4 | # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> | |
5 | # |
|
5 | # | |
6 | # This program is free software; you can redistribute it and/or |
|
6 | # This program is free software; you can redistribute it and/or | |
7 | # modify it under the terms of the GNU General Public License |
|
7 | # modify it under the terms of the GNU General Public License | |
8 | # as published by the Free Software Foundation; version 2 |
|
8 | # as published by the Free Software Foundation; version 2 | |
9 | # of the License or (at your opinion) any later version of the license. |
|
9 | # of the License or (at your opinion) any later version of the license. | |
10 | # |
|
10 | # | |
11 | # This program is distributed in the hope that it will be useful, |
|
11 | # This program is distributed in the hope that it will be useful, | |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | # GNU General Public License for more details. |
|
14 | # GNU General Public License for more details. | |
15 | # |
|
15 | # | |
16 | # You should have received a copy of the GNU General Public License |
|
16 | # You should have received a copy of the GNU General Public License | |
17 | # along with this program; if not, write to the Free Software |
|
17 | # along with this program; if not, write to the Free Software | |
18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | |
19 | # MA 02110-1301, USA. |
|
19 | # MA 02110-1301, USA. | |
20 | """ |
|
20 | """ | |
21 | Created on April 21, 2010 |
|
21 | Created on April 21, 2010 | |
22 | changelog controller for pylons |
|
22 | changelog controller for pylons | |
23 | @author: marcink |
|
23 | @author: marcink | |
24 | """ |
|
24 | """ | |
25 | from json import dumps |
|
25 | try: | |
|
26 | import json | |||
|
27 | except ImportError: | |||
|
28 | #python 2.5 compatibility | |||
|
29 | import simplejson as json | |||
26 | from mercurial.graphmod import colored, CHANGESET, revisions as graph_rev |
|
30 | from mercurial.graphmod import colored, CHANGESET, revisions as graph_rev | |
27 | from pylons import request, session, tmpl_context as c |
|
31 | from pylons import request, session, tmpl_context as c | |
28 | from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator |
|
32 | from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator | |
29 | from rhodecode.lib.base import BaseController, render |
|
33 | from rhodecode.lib.base import BaseController, render | |
30 | from rhodecode.model.hg_model import HgModel |
|
34 | from rhodecode.model.hg_model import HgModel | |
31 | from webhelpers.paginate import Page |
|
35 | from webhelpers.paginate import Page | |
32 | import logging |
|
36 | import logging | |
33 | log = logging.getLogger(__name__) |
|
37 | log = logging.getLogger(__name__) | |
34 |
|
38 | |||
35 | class ChangelogController(BaseController): |
|
39 | class ChangelogController(BaseController): | |
36 |
|
40 | |||
37 | @LoginRequired() |
|
41 | @LoginRequired() | |
38 | @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', |
|
42 | @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', | |
39 | 'repository.admin') |
|
43 | 'repository.admin') | |
40 | def __before__(self): |
|
44 | def __before__(self): | |
41 | super(ChangelogController, self).__before__() |
|
45 | super(ChangelogController, self).__before__() | |
42 |
|
46 | |||
43 | def index(self): |
|
47 | def index(self): | |
44 | limit = 100 |
|
48 | limit = 100 | |
45 | default = 20 |
|
49 | default = 20 | |
46 | if request.params.get('size'): |
|
50 | if request.params.get('size'): | |
47 | try: |
|
51 | try: | |
48 | int_size = int(request.params.get('size')) |
|
52 | int_size = int(request.params.get('size')) | |
49 | except ValueError: |
|
53 | except ValueError: | |
50 | int_size = default |
|
54 | int_size = default | |
51 | int_size = int_size if int_size <= limit else limit |
|
55 | int_size = int_size if int_size <= limit else limit | |
52 | c.size = int_size |
|
56 | c.size = int_size | |
53 | session['changelog_size'] = c.size |
|
57 | session['changelog_size'] = c.size | |
54 | session.save() |
|
58 | session.save() | |
55 | else: |
|
59 | else: | |
56 | c.size = int(session.get('changelog_size', default)) |
|
60 | c.size = int(session.get('changelog_size', default)) | |
57 |
|
61 | |||
58 | changesets = HgModel().get_repo(c.repo_name) |
|
62 | changesets = HgModel().get_repo(c.repo_name) | |
59 |
|
63 | |||
60 | p = int(request.params.get('page', 1)) |
|
64 | p = int(request.params.get('page', 1)) | |
61 | c.total_cs = len(changesets) |
|
65 | c.total_cs = len(changesets) | |
62 | c.pagination = Page(changesets, page=p, item_count=c.total_cs, |
|
66 | c.pagination = Page(changesets, page=p, item_count=c.total_cs, | |
63 | items_per_page=c.size) |
|
67 | items_per_page=c.size) | |
64 |
|
68 | |||
65 | self._graph(changesets, c.size, p) |
|
69 | self._graph(changesets, c.size, p) | |
66 |
|
70 | |||
67 | return render('changelog/changelog.html') |
|
71 | return render('changelog/changelog.html') | |
68 |
|
72 | |||
69 |
|
73 | |||
70 | def _graph(self, repo, size, p): |
|
74 | def _graph(self, repo, size, p): | |
71 | revcount = size |
|
75 | revcount = size | |
72 | if not repo.revisions:return dumps([]), 0 |
|
76 | if not repo.revisions:return json.dumps([]), 0 | |
73 |
|
77 | |||
74 | max_rev = repo.revisions[-1] |
|
78 | max_rev = repo.revisions[-1] | |
75 | offset = 1 if p == 1 else ((p - 1) * revcount + 1) |
|
79 | offset = 1 if p == 1 else ((p - 1) * revcount + 1) | |
76 | rev_start = repo.revisions[(-1 * offset)] |
|
80 | rev_start = repo.revisions[(-1 * offset)] | |
77 |
|
81 | |||
78 | revcount = min(max_rev, revcount) |
|
82 | revcount = min(max_rev, revcount) | |
79 | rev_end = max(0, rev_start - revcount) |
|
83 | rev_end = max(0, rev_start - revcount) | |
80 | dag = graph_rev(repo.repo, rev_start, rev_end) |
|
84 | dag = graph_rev(repo.repo, rev_start, rev_end) | |
81 |
|
85 | |||
82 | c.dag = tree = list(colored(dag)) |
|
86 | c.dag = tree = list(colored(dag)) | |
83 | data = [] |
|
87 | data = [] | |
84 | for (id, type, ctx, vtx, edges) in tree: |
|
88 | for (id, type, ctx, vtx, edges) in tree: | |
85 | if type != CHANGESET: |
|
89 | if type != CHANGESET: | |
86 | continue |
|
90 | continue | |
87 | data.append(('', vtx, edges)) |
|
91 | data.append(('', vtx, edges)) | |
88 |
|
92 | |||
89 | c.jsdata = dumps(data) |
|
93 | c.jsdata = json.dumps(data) | |
90 |
|
94 |
@@ -1,104 +1,108 b'' | |||||
1 | #!/usr/bin/env python |
|
1 | #!/usr/bin/env python | |
2 | # encoding: utf-8 |
|
2 | # encoding: utf-8 | |
3 | # summary controller for pylons |
|
3 | # summary controller for pylons | |
4 | # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> |
|
4 | # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> | |
5 | # |
|
5 | # | |
6 | # This program is free software; you can redistribute it and/or |
|
6 | # This program is free software; you can redistribute it and/or | |
7 | # modify it under the terms of the GNU General Public License |
|
7 | # modify it under the terms of the GNU General Public License | |
8 | # as published by the Free Software Foundation; version 2 |
|
8 | # as published by the Free Software Foundation; version 2 | |
9 | # of the License or (at your opinion) any later version of the license. |
|
9 | # of the License or (at your opinion) any later version of the license. | |
10 | # |
|
10 | # | |
11 | # This program is distributed in the hope that it will be useful, |
|
11 | # This program is distributed in the hope that it will be useful, | |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | # GNU General Public License for more details. |
|
14 | # GNU General Public License for more details. | |
15 | # |
|
15 | # | |
16 | # You should have received a copy of the GNU General Public License |
|
16 | # You should have received a copy of the GNU General Public License | |
17 | # along with this program; if not, write to the Free Software |
|
17 | # along with this program; if not, write to the Free Software | |
18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | |
19 | # MA 02110-1301, USA. |
|
19 | # MA 02110-1301, USA. | |
20 | """ |
|
20 | """ | |
21 | Created on April 18, 2010 |
|
21 | Created on April 18, 2010 | |
22 | summary controller for pylons |
|
22 | summary controller for pylons | |
23 | @author: marcink |
|
23 | @author: marcink | |
24 | """ |
|
24 | """ | |
25 | from pylons import tmpl_context as c, request, url |
|
25 | from pylons import tmpl_context as c, request, url | |
26 | from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator |
|
26 | from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator | |
27 | from rhodecode.lib.base import BaseController, render |
|
27 | from rhodecode.lib.base import BaseController, render | |
28 | from rhodecode.lib.utils import OrderedDict |
|
28 | from rhodecode.lib.utils import OrderedDict | |
29 | from rhodecode.model.hg_model import HgModel |
|
29 | from rhodecode.model.hg_model import HgModel | |
30 | from rhodecode.model.db import Statistics |
|
30 | from rhodecode.model.db import Statistics | |
31 | from webhelpers.paginate import Page |
|
31 | from webhelpers.paginate import Page | |
32 | from rhodecode.lib.celerylib import run_task |
|
32 | from rhodecode.lib.celerylib import run_task | |
33 | from rhodecode.lib.celerylib.tasks import get_commits_stats |
|
33 | from rhodecode.lib.celerylib.tasks import get_commits_stats | |
34 | from datetime import datetime, timedelta |
|
34 | from datetime import datetime, timedelta | |
35 | from time import mktime |
|
35 | from time import mktime | |
36 | import calendar |
|
36 | import calendar | |
37 | import logging |
|
37 | import logging | |
38 | import json |
|
38 | try: | |
|
39 | import json | |||
|
40 | except ImportError: | |||
|
41 | #python 2.5 compatibility | |||
|
42 | import simplejson as json | |||
39 | log = logging.getLogger(__name__) |
|
43 | log = logging.getLogger(__name__) | |
40 |
|
44 | |||
41 | class SummaryController(BaseController): |
|
45 | class SummaryController(BaseController): | |
42 |
|
46 | |||
43 | @LoginRequired() |
|
47 | @LoginRequired() | |
44 | @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', |
|
48 | @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', | |
45 | 'repository.admin') |
|
49 | 'repository.admin') | |
46 | def __before__(self): |
|
50 | def __before__(self): | |
47 | super(SummaryController, self).__before__() |
|
51 | super(SummaryController, self).__before__() | |
48 |
|
52 | |||
49 | def index(self): |
|
53 | def index(self): | |
50 | hg_model = HgModel() |
|
54 | hg_model = HgModel() | |
51 | c.repo_info = hg_model.get_repo(c.repo_name) |
|
55 | c.repo_info = hg_model.get_repo(c.repo_name) | |
52 | c.repo_changesets = Page(list(c.repo_info[:10]), page=1, items_per_page=20) |
|
56 | c.repo_changesets = Page(list(c.repo_info[:10]), page=1, items_per_page=20) | |
53 | e = request.environ |
|
57 | e = request.environ | |
54 |
|
58 | |||
55 | uri = u'%(protocol)s://%(user)s@%(host)s%(prefix)s/%(repo_name)s' % { |
|
59 | uri = u'%(protocol)s://%(user)s@%(host)s%(prefix)s/%(repo_name)s' % { | |
56 | 'protocol': e.get('wsgi.url_scheme'), |
|
60 | 'protocol': e.get('wsgi.url_scheme'), | |
57 | 'user':str(c.rhodecode_user.username), |
|
61 | 'user':str(c.rhodecode_user.username), | |
58 | 'host':e.get('HTTP_HOST'), |
|
62 | 'host':e.get('HTTP_HOST'), | |
59 | 'prefix':e.get('SCRIPT_NAME'), |
|
63 | 'prefix':e.get('SCRIPT_NAME'), | |
60 | 'repo_name':c.repo_name, } |
|
64 | 'repo_name':c.repo_name, } | |
61 | c.clone_repo_url = uri |
|
65 | c.clone_repo_url = uri | |
62 | c.repo_tags = OrderedDict() |
|
66 | c.repo_tags = OrderedDict() | |
63 | for name, hash in c.repo_info.tags.items()[:10]: |
|
67 | for name, hash in c.repo_info.tags.items()[:10]: | |
64 | c.repo_tags[name] = c.repo_info.get_changeset(hash) |
|
68 | c.repo_tags[name] = c.repo_info.get_changeset(hash) | |
65 |
|
69 | |||
66 | c.repo_branches = OrderedDict() |
|
70 | c.repo_branches = OrderedDict() | |
67 | for name, hash in c.repo_info.branches.items()[:10]: |
|
71 | for name, hash in c.repo_info.branches.items()[:10]: | |
68 | c.repo_branches[name] = c.repo_info.get_changeset(hash) |
|
72 | c.repo_branches[name] = c.repo_info.get_changeset(hash) | |
69 |
|
73 | |||
70 | td = datetime.today() + timedelta(days=1) |
|
74 | td = datetime.today() + timedelta(days=1) | |
71 | y, m, d = td.year, td.month, td.day |
|
75 | y, m, d = td.year, td.month, td.day | |
72 |
|
76 | |||
73 | ts_min_y = mktime((y - 1, (td - timedelta(days=calendar.mdays[m])).month, |
|
77 | ts_min_y = mktime((y - 1, (td - timedelta(days=calendar.mdays[m])).month, | |
74 | d, 0, 0, 0, 0, 0, 0,)) |
|
78 | d, 0, 0, 0, 0, 0, 0,)) | |
75 | ts_min_m = mktime((y, (td - timedelta(days=calendar.mdays[m])).month, |
|
79 | ts_min_m = mktime((y, (td - timedelta(days=calendar.mdays[m])).month, | |
76 | d, 0, 0, 0, 0, 0, 0,)) |
|
80 | d, 0, 0, 0, 0, 0, 0,)) | |
77 |
|
81 | |||
78 | ts_max_y = mktime((y, m, d, 0, 0, 0, 0, 0, 0,)) |
|
82 | ts_max_y = mktime((y, m, d, 0, 0, 0, 0, 0, 0,)) | |
79 |
|
83 | |||
80 | run_task(get_commits_stats, c.repo_info.name, ts_min_y, ts_max_y) |
|
84 | run_task(get_commits_stats, c.repo_info.name, ts_min_y, ts_max_y) | |
81 | c.ts_min = ts_min_m |
|
85 | c.ts_min = ts_min_m | |
82 | c.ts_max = ts_max_y |
|
86 | c.ts_max = ts_max_y | |
83 |
|
87 | |||
84 | stats = self.sa.query(Statistics)\ |
|
88 | stats = self.sa.query(Statistics)\ | |
85 | .filter(Statistics.repository == c.repo_info.dbrepo)\ |
|
89 | .filter(Statistics.repository == c.repo_info.dbrepo)\ | |
86 | .scalar() |
|
90 | .scalar() | |
87 |
|
91 | |||
88 |
|
92 | |||
89 | if stats and stats.languages: |
|
93 | if stats and stats.languages: | |
90 | lang_stats = json.loads(stats.languages) |
|
94 | lang_stats = json.loads(stats.languages) | |
91 | c.commit_data = stats.commit_activity |
|
95 | c.commit_data = stats.commit_activity | |
92 | c.overview_data = stats.commit_activity_combined |
|
96 | c.overview_data = stats.commit_activity_combined | |
93 | c.trending_languages = json.dumps(OrderedDict( |
|
97 | c.trending_languages = json.dumps(OrderedDict( | |
94 | sorted(lang_stats.items(), reverse=True, |
|
98 | sorted(lang_stats.items(), reverse=True, | |
95 | key=lambda k: k[1])[:2] |
|
99 | key=lambda k: k[1])[:2] | |
96 | ) |
|
100 | ) | |
97 | ) |
|
101 | ) | |
98 | else: |
|
102 | else: | |
99 | c.commit_data = json.dumps({}) |
|
103 | c.commit_data = json.dumps({}) | |
100 | c.overview_data = json.dumps([[ts_min_y, 0], [ts_max_y, 0] ]) |
|
104 | c.overview_data = json.dumps([[ts_min_y, 0], [ts_max_y, 0] ]) | |
101 | c.trending_languages = json.dumps({}) |
|
105 | c.trending_languages = json.dumps({}) | |
102 |
|
106 | |||
103 | return render('summary/summary.html') |
|
107 | return render('summary/summary.html') | |
104 |
|
108 |
General Comments 0
You need to be logged in to leave comments.
Login now