~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/directory_ui.py

  • Committer: Matt Nordhoff
  • Date: 2009-04-30 10:39:05 UTC
  • mto: This revision was merged to the branch mainline in revision 406.
  • Revision ID: mnordhoff@mattnordhoff.com-20090430103905-10si14h2i325htrj
Strip trailing whitespace

Show diffs side-by-side

added added

removed removed

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