annotate rhodecode/lib/annotate.py @ 4147:1c8f818787b3 rhodecode-2.2.5-gpl

old style: show the full link box on summary page - no overlap or truncation
author Mads Kiilerich <madski@unity3d.com>
date Wed, 02 Jul 2014 19:03:23 -0400
parents ffd45b185016
children 7e5f8c12a3fc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3375
diff changeset
2 # This program is free software: you can redistribute it and/or modify
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3375
diff changeset
3 # it under the terms of the GNU General Public License as published by
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3375
diff changeset
4 # the Free Software Foundation, either version 3 of the License, or
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3375
diff changeset
5 # (at your option) any later version.
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3375
diff changeset
6 #
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3375
diff changeset
7 # This program is distributed in the hope that it will be useful,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3375
diff changeset
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3375
diff changeset
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3375
diff changeset
10 # GNU General Public License for more details.
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3375
diff changeset
11 #
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3375
diff changeset
12 # You should have received a copy of the GNU General Public License
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3375
diff changeset
13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
14 """
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3375
diff changeset
15 rhodecode.lib.annotate
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3375
diff changeset
16 ~~~~~~~~~~~~~~~~~~~~~~
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
17
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3375
diff changeset
18 Anontation library for usage in rhodecode, previously part of vcs
1818
cf51bbfb120e auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents: 1753
diff changeset
19
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3375
diff changeset
20 :created_on: Dec 4, 2011
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3375
diff changeset
21 :author: marcink
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3375
diff changeset
22 :copyright: (c) 2013 RhodeCode GmbH.
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3375
diff changeset
23 :license: GPLv3, see LICENSE for more details.
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
24 """
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3375
diff changeset
25
3375
7000fc4aa569 Add option to define custom lexers for custom extensions for code highlight in rcextension module
Marcin Kuzminski <marcin@python-works.com>
parents: 3044
diff changeset
26 import StringIO
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
27
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
28 from rhodecode.lib.vcs.exceptions import VCSError
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
29 from rhodecode.lib.vcs.nodes import FileNode
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
30 from pygments.formatters import HtmlFormatter
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
31 from pygments import highlight
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
32
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
33
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
34 def annotate_highlight(filenode, annotate_from_changeset_func=None,
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
35 order=None, headers=None, **options):
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
36 """
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
37 Returns html portion containing annotated table with 3 columns: line
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
38 numbers, changeset information and pygmentized line of code.
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
39
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
40 :param filenode: FileNode object
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
41 :param annotate_from_changeset_func: function taking changeset and
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
42 returning single annotate cell; needs break line at the end
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
43 :param order: ordered sequence of ``ls`` (line numbers column),
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
44 ``annotate`` (annotate column), ``code`` (code column); Default is
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
45 ``['ls', 'annotate', 'code']``
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
46 :param headers: dictionary with headers (keys are whats in ``order``
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
47 parameter)
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
48 """
3375
7000fc4aa569 Add option to define custom lexers for custom extensions for code highlight in rcextension module
Marcin Kuzminski <marcin@python-works.com>
parents: 3044
diff changeset
49 from rhodecode.lib.utils import get_custom_lexer
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
50 options['linenos'] = True
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
51 formatter = AnnotateHtmlFormatter(filenode=filenode, order=order,
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
52 headers=headers,
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
53 annotate_from_changeset_func=annotate_from_changeset_func, **options)
3375
7000fc4aa569 Add option to define custom lexers for custom extensions for code highlight in rcextension module
Marcin Kuzminski <marcin@python-works.com>
parents: 3044
diff changeset
54 lexer = get_custom_lexer(filenode.extension) or filenode.lexer
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
55 highlighted = highlight(filenode.content, lexer, formatter)
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
56 return highlighted
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
57
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
58
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
59 class AnnotateHtmlFormatter(HtmlFormatter):
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
60
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
61 def __init__(self, filenode, annotate_from_changeset_func=None,
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
62 order=None, **options):
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
63 """
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
64 If ``annotate_from_changeset_func`` is passed it should be a function
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
65 which returns string from the given changeset. For example, we may pass
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
66 following function as ``annotate_from_changeset_func``::
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
67
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
68 def changeset_to_anchor(changeset):
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
69 return '<a href="/changesets/%s/">%s</a>\n' %\
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
70 (changeset.id, changeset.id)
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
71
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
72 :param annotate_from_changeset_func: see above
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
73 :param order: (default: ``['ls', 'annotate', 'code']``); order of
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
74 columns;
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
75 :param options: standard pygment's HtmlFormatter options, there is
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
76 extra option tough, ``headers``. For instance we can pass::
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
77
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
78 formatter = AnnotateHtmlFormatter(filenode, headers={
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
79 'ls': '#',
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
80 'annotate': 'Annotate',
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
81 'code': 'Code',
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
82 })
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
83
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
84 """
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
85 super(AnnotateHtmlFormatter, self).__init__(**options)
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
86 self.annotate_from_changeset_func = annotate_from_changeset_func
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
87 self.order = order or ('ls', 'annotate', 'code')
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
88 headers = options.pop('headers', None)
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
89 if headers and not ('ls' in headers and 'annotate' in headers and
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
90 'code' in headers):
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
91 raise ValueError("If headers option dict is specified it must "
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
92 "all 'ls', 'annotate' and 'code' keys")
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
93 self.headers = headers
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
94 if isinstance(filenode, FileNode):
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
95 self.filenode = filenode
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
96 else:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
97 raise VCSError("This formatter expect FileNode parameter, not %r"
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
98 % type(filenode))
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
99
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
100 def annotate_from_changeset(self, changeset):
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
101 """
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
102 Returns full html line for single changeset per annotated line.
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
103 """
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
104 if self.annotate_from_changeset_func:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
105 return self.annotate_from_changeset_func(changeset)
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
106 else:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
107 return ''.join((changeset.id, '\n'))
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
108
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
109 def _wrap_tablelinenos(self, inner):
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
110 dummyoutfile = StringIO.StringIO()
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
111 lncount = 0
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
112 for t, line in inner:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
113 if t:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
114 lncount += 1
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
115 dummyoutfile.write(line)
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
116
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
117 fl = self.linenostart
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
118 mw = len(str(lncount + fl - 1))
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
119 sp = self.linenospecial
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
120 st = self.linenostep
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
121 la = self.lineanchors
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
122 aln = self.anchorlinenos
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
123 if sp:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
124 lines = []
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
125
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
126 for i in range(fl, fl + lncount):
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
127 if i % st == 0:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
128 if i % sp == 0:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
129 if aln:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
130 lines.append('<a href="#%s-%d" class="special">'
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
131 '%*d</a>' %
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
132 (la, i, mw, i))
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
133 else:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
134 lines.append('<span class="special">'
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
135 '%*d</span>' % (mw, i))
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
136 else:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
137 if aln:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
138 lines.append('<a href="#%s-%d">'
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
139 '%*d</a>' % (la, i, mw, i))
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
140 else:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
141 lines.append('%*d' % (mw, i))
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
142 else:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
143 lines.append('')
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
144 ls = '\n'.join(lines)
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
145 else:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
146 lines = []
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
147 for i in range(fl, fl + lncount):
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
148 if i % st == 0:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
149 if aln:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
150 lines.append('<a href="#%s-%d">%*d</a>' \
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
151 % (la, i, mw, i))
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
152 else:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
153 lines.append('%*d' % (mw, i))
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
154 else:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
155 lines.append('')
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
156 ls = '\n'.join(lines)
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
157
3044
c57a37430dc9 fixes #652 switch to generator approach when doing file annotation to prevent huge memory consumption when executed on large files. Thanks to ALexey Larikov for patch.
Marcin Kuzminski <marcin@python-works.com>
parents: 2007
diff changeset
158 # annotate_changesets = [tup[1] for tup in self.filenode.annotate]
c57a37430dc9 fixes #652 switch to generator approach when doing file annotation to prevent huge memory consumption when executed on large files. Thanks to ALexey Larikov for patch.
Marcin Kuzminski <marcin@python-works.com>
parents: 2007
diff changeset
159 ## TODO: not sure what that fixes
c57a37430dc9 fixes #652 switch to generator approach when doing file annotation to prevent huge memory consumption when executed on large files. Thanks to ALexey Larikov for patch.
Marcin Kuzminski <marcin@python-works.com>
parents: 2007
diff changeset
160 # # If pygments cropped last lines break we need do that too
c57a37430dc9 fixes #652 switch to generator approach when doing file annotation to prevent huge memory consumption when executed on large files. Thanks to ALexey Larikov for patch.
Marcin Kuzminski <marcin@python-works.com>
parents: 2007
diff changeset
161 # ln_cs = len(annotate_changesets)
c57a37430dc9 fixes #652 switch to generator approach when doing file annotation to prevent huge memory consumption when executed on large files. Thanks to ALexey Larikov for patch.
Marcin Kuzminski <marcin@python-works.com>
parents: 2007
diff changeset
162 # ln_ = len(ls.splitlines())
c57a37430dc9 fixes #652 switch to generator approach when doing file annotation to prevent huge memory consumption when executed on large files. Thanks to ALexey Larikov for patch.
Marcin Kuzminski <marcin@python-works.com>
parents: 2007
diff changeset
163 # if ln_cs > ln_:
c57a37430dc9 fixes #652 switch to generator approach when doing file annotation to prevent huge memory consumption when executed on large files. Thanks to ALexey Larikov for patch.
Marcin Kuzminski <marcin@python-works.com>
parents: 2007
diff changeset
164 # annotate_changesets = annotate_changesets[:ln_ - ln_cs]
c57a37430dc9 fixes #652 switch to generator approach when doing file annotation to prevent huge memory consumption when executed on large files. Thanks to ALexey Larikov for patch.
Marcin Kuzminski <marcin@python-works.com>
parents: 2007
diff changeset
165 annotate = ''.join((self.annotate_from_changeset(el[2]())
c57a37430dc9 fixes #652 switch to generator approach when doing file annotation to prevent huge memory consumption when executed on large files. Thanks to ALexey Larikov for patch.
Marcin Kuzminski <marcin@python-works.com>
parents: 2007
diff changeset
166 for el in self.filenode.annotate))
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
167 # in case you wonder about the seemingly redundant <div> here:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
168 # since the content in the other cell also is wrapped in a div,
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
169 # some browsers in some configurations seem to mess up the formatting.
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
170 '''
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
171 yield 0, ('<table class="%stable">' % self.cssclass +
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
172 '<tr><td class="linenos"><div class="linenodiv"><pre>' +
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
173 ls + '</pre></div></td>' +
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
174 '<td class="code">')
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
175 yield 0, dummyoutfile.getvalue()
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
176 yield 0, '</td></tr></table>'
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
177
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
178 '''
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
179 headers_row = []
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
180 if self.headers:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
181 headers_row = ['<tr class="annotate-header">']
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
182 for key in self.order:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
183 td = ''.join(('<td>', self.headers[key], '</td>'))
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
184 headers_row.append(td)
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
185 headers_row.append('</tr>')
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
186
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
187 body_row_start = ['<tr>']
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
188 for key in self.order:
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
189 if key == 'ls':
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
190 body_row_start.append(
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
191 '<td class="linenos"><div class="linenodiv"><pre>' +
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
192 ls + '</pre></div></td>')
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
193 elif key == 'annotate':
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
194 body_row_start.append(
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
195 '<td class="annotate"><div class="annotatediv"><pre>' +
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
196 annotate + '</pre></div></td>')
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
197 elif key == 'code':
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
198 body_row_start.append('<td class="code">')
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
199 yield 0, ('<table class="%stable">' % self.cssclass +
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
200 ''.join(headers_row) +
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
201 ''.join(body_row_start)
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
202 )
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
203 yield 0, dummyoutfile.getvalue()
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
204 yield 0, '</td></tr></table>'