/loggerhead/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/loggerhead/trunk

« back to all changes in this revision

Viewing changes to loggerhead/controllers/directory_ui.py

  • Committer: Colin Watson
  • Date: 2019-09-19 08:10:36 UTC
  • mfrom: (491.2.62 breezy)
  • Revision ID: cjwatson@canonical.com-20190919081036-q1symc2h2iedtlh3
[r=cjwatson] Switch loggerhead over to using the Breezy rather than Bazaar APIs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import logging
21
21
import stat
22
22
 
23
 
from bzrlib import branch, errors
 
23
from breezy import branch, errors, urlutils
24
24
 
25
 
from loggerhead import util
26
 
from loggerhead.controllers import TemplatedBranchView
 
25
from .. import util
 
26
from ..controllers import TemplatedBranchView
27
27
 
28
28
 
29
29
class DirEntry(object):
30
30
 
31
31
    def __init__(self, dirname, parity, branch):
32
 
        self.dirname = dirname
 
32
        self.dirname = urlutils.unquote(dirname)
33
33
        self.parity = parity
34
34
        self.branch = branch
35
35
        if branch is not None:
36
36
            # If a branch is empty, bzr raises an exception when trying this
37
37
            try:
38
 
                self.last_change = datetime.datetime.utcfromtimestamp(
39
 
                    branch.repository.get_revision(
40
 
                        branch.last_revision()).timestamp)
41
 
            except:
42
 
                self.last_change = None
 
38
                self.last_revision = branch.repository.get_revision(branch.last_revision())
 
39
                self.last_change_time = datetime.datetime.utcfromtimestamp(self.last_revision.timestamp)
 
40
            except errors.NoSuchRevision:
 
41
                self.last_revision = None
 
42
                self.last_change_time = None
43
43
 
44
44
 
45
45
class DirectoryUI(TemplatedBranchView):
46
46
    """
47
47
    """
48
48
 
49
 
    template_path = 'loggerhead.templates.directory'
 
49
    template_name = 'directory'
50
50
 
51
51
    def __init__(self, static_url_base, transport, name):
52
52
 
72
72
        for d in listing:
73
73
            try:
74
74
                b = branch.Branch.open_from_transport(self.transport.clone(d))
75
 
                if b.get_config().get_user_option('http_serve') == 'False':
76
 
                    continue
77
75
            except:
 
76
                # TODO(jelmer): don't catch all exceptions here
78
77
                try:
79
78
                    if not stat.S_ISDIR(self.transport.stat(d).st_mode):
80
79
                        continue
81
80
                except errors.NoSuchFile:
82
81
                    continue
83
82
                b = None
 
83
            else:
 
84
                if not b.get_config().get_user_option_as_bool('http_serve', default=True):
 
85
                    continue
84
86
            dirs.append(DirEntry(d, parity, b))
85
87
            parity = 1 - parity
86
88
        # Create breadcrumb trail