~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/directory_ui.py

  • Committer: Matt Nordhoff
  • Date: 2010-02-26 04:37:13 UTC
  • mfrom: (400 trunk)
  • mto: This revision was merged to the branch mainline in revision 401.
  • Revision ID: mnordhoff@mattnordhoff.com-20100226043713-7mw3r6dr9qowutmi
Merge trunk for NEWS

Show diffs side-by-side

added added

removed removed

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