~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/directory_ui.py

  • Committer: John Arbash Meinel
  • Date: 2011-02-10 23:05:31 UTC
  • mto: This revision was merged to the branch mainline in revision 426.
  • Revision ID: john@arbash-meinel.com-20110210230531-spb87czp526tljp7
Add a NEWS update, and HACKING commentary about the new code.

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
48
48
 
49
49
    template_path = 'loggerhead.templates.directory'
50
50
 
51
 
    def __init__(self, static_url_base, path, name):
 
51
    def __init__(self, static_url_base, transport, name):
52
52
 
53
53
        class _branch(object):
54
54
            context_url = 1
57
57
            def static_url(path):
58
58
                return self._static_url_base + path
59
59
        self._branch = _branch
60
 
        self._history = None
61
 
        self._path = path
 
60
        self._history_callable = lambda: None
62
61
        self._name = name
63
62
        self._static_url_base = static_url_base
 
63
        self.transport = transport
64
64
        self.log = logging.getLogger('')
65
65
 
66
 
    def get_values(self, h, args, kwargs, response):
67
 
        listing = [d for d in os.listdir(self._path)
68
 
                   if not d.startswith('.')
69
 
                   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('.')]
70
69
        listing.sort(key=lambda x: x.lower())
71
70
        dirs = []
72
71
        parity = 0
73
72
        for d in listing:
74
 
            p = os.path.join(self._path, d)
75
73
            try:
76
 
                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
77
77
            except:
 
78
                try:
 
79
                    if not stat.S_ISDIR(self.transport.stat(d).st_mode):
 
80
                        continue
 
81
                except errors.NoSuchFile:
 
82
                    continue
78
83
                b = None
79
84
            dirs.append(DirEntry(d, parity, b))
80
85
            parity = 1 - parity