annotate pylons_app/controllers/graph.py @ 172:83c7ee1b5f5c

improved timerproxy with sqllogging, and new way of sqlformat queries
author Marcin Kuzminski <marcin@python-works.com>
date Fri, 21 May 2010 03:01:31 +0200
parents cf32c4cc26e8
children b68b2246e5a6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
137
cf32c4cc26e8 fixed graph when repository is empty moved imports to top and removed some lfet over prints
Marcin Kuzminski <marcin@python-works.com>
parents: 106
diff changeset
1 import logging
106
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
2 from pylons import request, response, session, tmpl_context as c, url, config, \
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
3 app_globals as g
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
4 from pylons.controllers.util import abort, redirect
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
5 from pylons_app.lib.base import BaseController, render
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
6 from pylons_app.lib.utils import get_repo_slug
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
7 from pylons_app.model.hg_model import HgModel
93
aec4c0071cb3 added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
8
137
cf32c4cc26e8 fixed graph when repository is empty moved imports to top and removed some lfet over prints
Marcin Kuzminski <marcin@python-works.com>
parents: 106
diff changeset
9 from mercurial.graphmod import revisions as graph_rev, colored, CHANGESET
cf32c4cc26e8 fixed graph when repository is empty moved imports to top and removed some lfet over prints
Marcin Kuzminski <marcin@python-works.com>
parents: 106
diff changeset
10 from pylons_app.lib.filters import age as _age, person
cf32c4cc26e8 fixed graph when repository is empty moved imports to top and removed some lfet over prints
Marcin Kuzminski <marcin@python-works.com>
parents: 106
diff changeset
11 from simplejson import dumps
cf32c4cc26e8 fixed graph when repository is empty moved imports to top and removed some lfet over prints
Marcin Kuzminski <marcin@python-works.com>
parents: 106
diff changeset
12 from mercurial.node import short
cf32c4cc26e8 fixed graph when repository is empty moved imports to top and removed some lfet over prints
Marcin Kuzminski <marcin@python-works.com>
parents: 106
diff changeset
13 from webhelpers.paginate import Page
cf32c4cc26e8 fixed graph when repository is empty moved imports to top and removed some lfet over prints
Marcin Kuzminski <marcin@python-works.com>
parents: 106
diff changeset
14
cf32c4cc26e8 fixed graph when repository is empty moved imports to top and removed some lfet over prints
Marcin Kuzminski <marcin@python-works.com>
parents: 106
diff changeset
15
93
aec4c0071cb3 added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
16
aec4c0071cb3 added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
17 log = logging.getLogger(__name__)
aec4c0071cb3 added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
18
aec4c0071cb3 added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
19 class GraphController(BaseController):
106
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
20 def __before__(self):
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
21 c.repos_prefix = config['repos_name']
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
22 c.repo_name = get_repo_slug(request)
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
23
93
aec4c0071cb3 added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
24 def index(self):
aec4c0071cb3 added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
25 # Return a rendered template
106
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
26 hg_model = HgModel()
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
27 if request.POST.get('size'):
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
28 c.size = int(request.params.get('size', 20))
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
29 else:
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
30 c.size = int(request.params.get('size', 20))
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
31 c.jsdata, c.canvasheight = self.graph(hg_model.get_repo(c.repo_name), c.size)
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
32
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
33 return render('/graph.html')
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
34
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
35
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
36 def graph(self, repo, size):
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
37 revcount = size
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
38 p = int(request.params.get('page', 1))
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
39 c.pagination = Page(repo.revisions, page=p, item_count=len(repo.revisions), items_per_page=revcount)
137
cf32c4cc26e8 fixed graph when repository is empty moved imports to top and removed some lfet over prints
Marcin Kuzminski <marcin@python-works.com>
parents: 106
diff changeset
40 if not repo.revisions:return dumps([]), 0
cf32c4cc26e8 fixed graph when repository is empty moved imports to top and removed some lfet over prints
Marcin Kuzminski <marcin@python-works.com>
parents: 106
diff changeset
41
106
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
42 max_rev = repo.revisions[-1]
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
43 offset = 1 if p == 1 else ((p - 1) * revcount)
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
44 rev_start = repo.revisions[(-1 * offset)]
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
45 bg_height = 39
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
46
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
47 revcount = min(max_rev, revcount)
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
48 rev_end = max(0, rev_start - revcount)
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
49 dag = graph_rev(repo.repo, rev_start, rev_end)
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
50 tree = list(colored(dag))
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
51 canvasheight = (len(tree) + 1) * bg_height - 27
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
52 data = []
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
53 for (id, type, ctx, vtx, edges) in tree:
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
54 if type != CHANGESET:
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
55 continue
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
56 node = short(ctx.node())
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
57 age = _age(ctx.date())
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
58 desc = ctx.description()
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
59 user = person(ctx.user())
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
60 branch = ctx.branch()
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
61 branch = branch, repo.repo.branchtags().get(branch) == ctx.node()
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
62 data.append((node, vtx, edges, desc, user, age, branch, ctx.tags()))
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
63
a86c8de926b4 some fixes in graph tab. Little fixes in files
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
64 return dumps(data), canvasheight