/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: Ubuntu One Auto Copilot
  • Author(s): Colin Watson
  • Date: 2022-09-21 12:08:21 UTC
  • mfrom: (539.1.2 fix-tox)
  • Revision ID: otto-copilot@canonical.com-20220921120821-fan53lzjaborq3h1
Fix running tests in tox.

Merged from https://code.launchpad.net/~cjwatson/loggerhead/fix-tox/+merge/430053

Show diffs side-by-side

added added

removed removed

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