~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/inventory_ui.py

  • Committer: Robey Pointer
  • Date: 2006-12-12 20:34:10 UTC
  • Revision ID: robey@lag.net-20061212203410-traayjfhp0ftc26u
starting work on the inventory page, and some starting work on getting a changelog per-path

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# Copyright (C) 2006  Robey Pointer <robey@lag.net>
 
3
#
 
4
# This program is free software; you can redistribute it and/or modify
 
5
# it under the terms of the GNU General Public License as published by
 
6
# the Free Software Foundation; either version 2 of the License, or
 
7
# (at your option) any later version.
 
8
#
 
9
# This program is distributed in the hope that it will be useful,
 
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
# GNU General Public License for more details.
 
13
#
 
14
# You should have received a copy of the GNU General Public License
 
15
# along with this program; if not, write to the Free Software
 
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
17
#
 
18
 
 
19
import datetime
 
20
import os
 
21
import posixpath
 
22
import textwrap
 
23
 
 
24
import turbogears
 
25
from cherrypy import HTTPRedirect, session
 
26
 
 
27
from loggerhead.history import History
 
28
from loggerhead import util
 
29
 
 
30
 
 
31
def dirname(path):
 
32
    while path.endswith('/'):
 
33
        path = path[:-1]
 
34
    path = posixpath.dirname(path)
 
35
    return path
 
36
 
 
37
        
 
38
class InventoryUI (object):
 
39
 
 
40
    @turbogears.expose(html='loggerhead.templates.inventory')
 
41
    def default(self, *args, **kw):
 
42
        h = History.from_folder(turbogears.config.get('loggerhead.folder'))
 
43
        if len(args) > 0:
 
44
            revid = args[0]
 
45
        else:
 
46
            revid = h.last_revid
 
47
 
 
48
        try:
 
49
            rev = h.get_revision(revid)
 
50
            inv = h.get_inventory(revid)
 
51
        except:
 
52
            raise HTTPRedirect(turbogears.url('/changes'))
 
53
        
 
54
        path = kw.get('path', None)
 
55
        if path is None:
 
56
            path = '/'
 
57
            file_id = None
 
58
        else:
 
59
            file_id = inv.path2id(path)
 
60
            
 
61
        buttons = [
 
62
            ('top', turbogears.url('/changes')),
 
63
            ('revision', turbogears.url([ '/revision', revid ])),
 
64
            ('history', turbogears.url([ '/changes', revid ])),
 
65
        ]
 
66
 
 
67
        vals = {
 
68
            'branch_name': turbogears.config.get('loggerhead.branch_name'),
 
69
            'util': util,
 
70
            'buttons': buttons,
 
71
            'revid': revid,
 
72
            'change': h.get_change(revid),
 
73
            'path': path,
 
74
            'updir': dirname(path),
 
75
            'filelist': h.get_filelist(inv, path),
 
76
            'history': h,
 
77
            'scan_url': '/revision',
 
78
            'pagesize': 1,
 
79
            'posixpath': posixpath,
 
80
        }
 
81
        return vals