~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/directory_ui.py

  • Committer: Martin Albisetti
  • Date: 2008-08-05 05:17:47 UTC
  • mfrom: (190.1.3 branch_locations)
  • Revision ID: argentina@gmail.com-20080805051747-j2s6xl31yqzrjgti
Providing branch_link which will provide a hyperlink on the friendly name (Tim Penhey)

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
import datetime
20
20
import logging
21
 
import stat
 
21
import os
22
22
 
23
23
from bzrlib import branch
24
24
 
25
 
from loggerhead import util
26
25
from loggerhead.controllers import TemplatedBranchView
27
26
 
28
 
 
29
27
class DirEntry(object):
30
 
 
31
28
    def __init__(self, dirname, parity, branch):
32
29
        self.dirname = dirname
33
30
        self.parity = parity
34
31
        self.branch = branch
35
32
        if branch is not None:
36
 
            # If a branch is empty, bzr raises an exception when trying this
37
 
            try:
38
 
                self.last_change = datetime.datetime.fromtimestamp(
39
 
                    branch.repository.get_revision(
40
 
                        branch.last_revision()).timestamp)
41
 
            except:
42
 
                self.last_change = None
43
 
 
 
33
            self.last_change =  datetime.datetime.fromtimestamp(
 
34
                branch.repository.get_revision(branch.last_revision()).timestamp)
44
35
 
45
36
class DirectoryUI(TemplatedBranchView):
46
37
    """
48
39
 
49
40
    template_path = 'loggerhead.templates.directory'
50
41
 
51
 
    def __init__(self, static_url_base, transport, name):
52
 
 
 
42
    def __init__(self, static_url_base, path, name):
53
43
        class _branch(object):
54
44
            context_url = 1
55
 
 
56
 
            @staticmethod
57
 
            def static_url(path):
58
 
                return self._static_url_base + path
59
45
        self._branch = _branch
60
 
        self._history_callable = lambda:None
 
46
        self._history = None
 
47
        self._path = path
61
48
        self._name = name
62
49
        self._static_url_base = static_url_base
63
 
        self.transport = transport
64
50
        self.log = logging.getLogger('')
65
51
 
66
 
    def get_values(self, path, kwargs, response):
67
 
        listing = [d for d in self.transport.list_dir('.')
 
52
    def get_values(self, h, args, kwargs, response):
 
53
        listing = [d for d in os.listdir(self._path)
68
54
                   if not d.startswith('.')
69
 
                   and stat.S_ISDIR(self.transport.stat(d).st_mode)]
 
55
                   and os.path.isdir(os.path.join(self._path, d))]
70
56
        listing.sort(key=lambda x: x.lower())
71
57
        dirs = []
72
58
        parity = 0
 
59
        def static_url(path):
 
60
            return self._static_url_base + path
73
61
        for d in listing:
 
62
            p = os.path.join(self._path, d)
74
63
            try:
75
 
                b = branch.Branch.open_from_transport(self.transport.clone(d))
 
64
                b = branch.Branch.open(p)
76
65
            except:
77
66
                b = None
78
67
            dirs.append(DirEntry(d, parity, b))
79
68
            parity = 1 - parity
80
 
        # Create breadcrumb trail
81
 
        directory_breadcrumbs = util.directory_breadcrumbs(
82
 
                self._name,
83
 
                False,
84
 
                'directory')
85
69
        return {
86
70
            'dirs': dirs,
87
71
            'name': self._name,
88
 
            'directory_breadcrumbs': directory_breadcrumbs,
 
72
            'static_url': static_url,
89
73
            }