~ubuntu-branches/debian/sid/loggerhead/sid

« back to all changes in this revision

Viewing changes to loggerhead/controllers/annotate_ui.py

  • Committer: Bazaar Package Importer
  • Author(s): Jelmer Vernooij
  • Date: 2008-07-25 22:43:49 UTC
  • Revision ID: james.westby@ubuntu.com-20080725224349-f3tlyfotni60a94n
Tags: upstream-1.6
ImportĀ upstreamĀ versionĀ 1.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# Copyright (C) 2006  Robey Pointer <robey@lag.net>
 
3
# Copyright (C) 2006  Goffredo Baroncelli <kreijack@inwind.it>
 
4
#
 
5
# This program is free software; you can redistribute it and/or modify
 
6
# it under the terms of the GNU General Public License as published by
 
7
# the Free Software Foundation; either version 2 of the License, or
 
8
# (at your option) any later version.
 
9
#
 
10
# This program is distributed in the hope that it will be useful,
 
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
# GNU General Public License for more details.
 
14
#
 
15
# You should have received a copy of the GNU General Public License
 
16
# along with this program; if not, write to the Free Software
 
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
#
 
19
 
 
20
import os
 
21
import posixpath
 
22
 
 
23
from paste.httpexceptions import HTTPBadRequest
 
24
 
 
25
from loggerhead.controllers import TemplatedBranchView
 
26
from loggerhead import util
 
27
 
 
28
 
 
29
def dirname(path):
 
30
    while path.endswith('/'):
 
31
        path = path[:-1]
 
32
    path = posixpath.dirname(path)
 
33
    return path
 
34
 
 
35
class AnnotateUI (TemplatedBranchView):
 
36
 
 
37
    template_path = 'loggerhead.templates.annotate'
 
38
 
 
39
    def get_values(self, h, args, kw, headers):
 
40
        if len(args) > 0:
 
41
            revid = h.fix_revid(args[0])
 
42
        else:
 
43
            revid = h.last_revid
 
44
 
 
45
        path = None
 
46
        if len(args) > 1:
 
47
            path = '/'.join(args[1:])
 
48
            if not path.startswith('/'):
 
49
                path = '/' + path
 
50
 
 
51
        file_id = kw.get('file_id', None)
 
52
        if (file_id is None) and (path is None):
 
53
            raise HTTPBadRequest('No file_id or filename provided to annotate')
 
54
 
 
55
        if file_id is None:
 
56
            file_id = h.get_file_id(revid, path)
 
57
 
 
58
        # no navbar for revisions
 
59
        navigation = util.Container()
 
60
 
 
61
        if path is None:
 
62
            path = h.get_path(revid, file_id)
 
63
        filename = os.path.basename(path)
 
64
 
 
65
        return {
 
66
            'revid': revid,
 
67
            'file_id': file_id,
 
68
            'path': path,
 
69
            'filename': filename,
 
70
            'navigation': navigation,
 
71
            'change': h.get_changes([ revid ])[0],
 
72
            'contents': list(h.annotate_file(file_id, revid)),
 
73
            'fileview_active': True,
 
74
        }