~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/templatefunctions.py

  • Committer: Toshio Kuratomi
  • Date: 2010-04-18 14:41:23 UTC
  • mto: (464.1.1 mod-wsgi)
  • mto: This revision was merged to the branch mainline in revision 465.
  • Revision ID: toshio@fedoraproject.org-20100418144123-c93a6zbtmxzid12g
Files to anable mod_wsgi

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
# along with this program; if not, write to the Free Software
14
14
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
15
#
 
16
 
 
17
import cgi
16
18
import os
 
19
 
 
20
import pkg_resources
 
21
 
 
22
import bzrlib
 
23
 
 
24
import loggerhead
17
25
from loggerhead.zptsupport import zpt
18
26
 
19
27
 
37
45
 
38
46
 
39
47
@templatefunc
40
 
def file_change_summary(url, entry, modified_file_link):
 
48
def file_change_summary(url, entry, file_changes, style='normal', currently_showing=None):
 
49
    if style == 'fragment':
 
50
        def file_link(filename):
 
51
            if currently_showing and filename == currently_showing:
 
52
                return '<b><a href="#%s">%s</a></b>' % (
 
53
                    cgi.escape(filename), cgi.escape(filename))
 
54
            else:
 
55
                return revision_link(
 
56
                    url, entry.revno, filename, '#' + filename)
 
57
    else:
 
58
        def file_link(filename):
 
59
            return '<a href="%s%s" title="View changes to %s in revision %s">%s</a>' % (
 
60
                url(['/revision', entry.revno]), '#' + filename, cgi.escape(filename),
 
61
                cgi.escape(entry.revno), cgi.escape(filename))
41
62
    return _pt('revisionfilechanges').expand(
42
 
        url=url, entry=entry, modified_file_link=modified_file_link,
43
 
        **templatefunctions)
 
63
        entry=entry, file_changes=file_changes, file_link=file_link, **templatefunctions)
44
64
 
45
65
 
46
66
@templatefunc
47
 
def revisioninfo(url, branch, entry, modified_file_link=None):
 
67
def revisioninfo(url, branch, entry, file_changes=None, currently_showing=None, merged_in=None):
48
68
    from loggerhead import util
49
69
    return _pt('revisioninfo').expand(
50
70
        url=url, change=entry, branch=branch, util=util,
51
 
        modified_file_link=modified_file_link,
52
 
        **templatefunctions)
 
71
        file_changes=file_changes, currently_showing=currently_showing,
 
72
        merged_in=merged_in, **templatefunctions)
 
73
 
 
74
 
 
75
@templatefunc
 
76
def branchinfo(branch):
 
77
    if branch.served_url is not None:
 
78
        return _pt('branchinfo').expand(branch=branch, **templatefunctions)
 
79
    else:
 
80
        return ''
53
81
 
54
82
 
55
83
@templatefunc
72
100
        extra = ' ' + entry.branch_nick
73
101
    else:
74
102
        extra = ''
75
 
    return '(%s%s)'%(entry.revno, extra)
76
 
 
77
 
 
78
 
@templatefunc
79
 
def modified_file_link_rev(url, entry, item):
80
 
    return _pt('modified-file-link-rev').expand(
81
 
        url=url, entry=entry, item=item,
82
 
        **templatefunctions)
83
 
 
84
 
 
85
 
@templatefunc
86
 
def modified_file_link_log(url, entry, item):
87
 
    return _pt('modified-file-link-log').expand(
88
 
        url=url, entry=entry, item=item,
89
 
        **templatefunctions)
 
103
    return '(%s%s)' % (entry.revno, extra)
90
104
 
91
105
 
92
106
@templatefunc
104
118
def menu(branch, url, fileview_active=False):
105
119
    return _pt('menu').expand(branch=branch, url=url,
106
120
        fileview_active=fileview_active, **templatefunctions)
 
121
 
 
122
 
 
123
@templatefunc
 
124
def annotate_link(url, revno, path):
 
125
    return '<a href="%s" title="Annotate %s">%s</a>' % (
 
126
        url(['/annotate', revno, path]), cgi.escape(path), cgi.escape(path))
 
127
 
 
128
@templatefunc
 
129
def revision_link(url, revno, path, frag=''):
 
130
    return '<a href="%s%s" title="View changes to %s in revision %s">%s</a>' % (
 
131
        url(['/revision', revno, path]), frag, cgi.escape(path),
 
132
        cgi.escape(revno), cgi.escape(path))
 
133
 
 
134
 
 
135
@templatefunc
 
136
def loggerhead_version():
 
137
    return loggerhead.__version__
 
138
 
 
139
_cached_generator_string = None
 
140
 
 
141
@templatefunc
 
142
def generator_string():
 
143
    global _cached_generator_string
 
144
    if _cached_generator_string is None:
 
145
        versions = []
 
146
 
 
147
        # TODO: Errors -- e.g. from a missing/invalid __version__ attribute, or
 
148
        # ValueError accessing Distribution.version -- should be non-fatal.
 
149
 
 
150
        versions.append(('Loggerhead', loggerhead.__version__))
 
151
 
 
152
        import sys
 
153
        python_version = bzrlib._format_version_tuple(sys.version_info)
 
154
        versions.append(('Python', python_version))
 
155
 
 
156
        versions.append(('Bazaar', bzrlib.__version__))
 
157
 
 
158
        Paste = pkg_resources.get_distribution('Paste')
 
159
        versions.append(('Paste', Paste.version))
 
160
 
 
161
        try:
 
162
            PasteDeploy = pkg_resources.get_distribution('PasteDeploy')
 
163
        except pkg_resources.DistributionNotFound:
 
164
            pass
 
165
        else:
 
166
            versions.append(('PasteDeploy', PasteDeploy.version))
 
167
 
 
168
        import simpletal
 
169
        versions.append(('SimpleTAL', simpletal.__version__))
 
170
 
 
171
        try:
 
172
            import pygments
 
173
        except ImportError:
 
174
            pass
 
175
        else:
 
176
            versions.append(('Pygments', pygments.__version__))
 
177
 
 
178
        try:
 
179
            from bzrlib.plugins import search
 
180
        except ImportError:
 
181
            pass
 
182
        else:
 
183
            bzr_search_version = bzrlib._format_version_tuple(
 
184
                search.version_info)
 
185
            versions.append(('bzr-search', bzr_search_version))
 
186
 
 
187
        # TODO: On old Python versions, elementtree may be used.
 
188
 
 
189
        try:
 
190
            import simplejson
 
191
        except ImportError:
 
192
            pass
 
193
        else:
 
194
            versions.append(('simplejson', simplejson.__version__))
 
195
 
 
196
        try:
 
197
            Dozer = pkg_resources.get_distribution('Dozer')
 
198
        except pkg_resources.DistributionNotFound:
 
199
            pass
 
200
        else:
 
201
            versions.append(('Dozer', Dozer.version))
 
202
 
 
203
        version_strings = ("%s/%s" % t for t in versions)
 
204
        _cached_generator_string = ' '.join(version_strings)
 
205
    return _cached_generator_string