~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/directory_ui.py

  • Committer: Tom Haddon
  • Date: 2008-11-24 20:26:26 UTC
  • mto: This revision was merged to the branch mainline in revision 246.
  • Revision ID: tom.haddon@canonical.com-20081124202626-x0sva3e7zxlqtckw
Allow the script to run as root or another user, but start the loggerhead process as the correct user

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
import datetime
20
20
import logging
21
 
import stat
 
21
import os
22
22
 
23
23
from bzrlib import branch
24
24
 
48
48
 
49
49
    template_path = 'loggerhead.templates.directory'
50
50
 
51
 
    def __init__(self, static_url_base, transport, name):
 
51
    def __init__(self, static_url_base, path, 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_callable = lambda:None
 
60
        self._history = None
 
61
        self._path = path
61
62
        self._name = name
62
63
        self._static_url_base = static_url_base
63
 
        self.transport = transport
64
64
        self.log = logging.getLogger('')
65
65
 
66
 
    def get_values(self, path, kwargs, response):
67
 
        listing = [d for d in self.transport.list_dir('.')
68
 
                   if not d.startswith('.')]
 
66
    def get_values(self, h, revid, path, 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))]
69
70
        listing.sort(key=lambda x: x.lower())
70
71
        dirs = []
71
72
        parity = 0
72
73
        for d in listing:
 
74
            p = os.path.join(self._path, d)
73
75
            try:
74
 
                b = branch.Branch.open_from_transport(self.transport.clone(d))
 
76
                b = branch.Branch.open(p)
75
77
            except:
76
 
                if not stat.S_ISDIR(self.transport.stat(d).st_mode):
77
 
                    continue
78
78
                b = None
79
79
            dirs.append(DirEntry(d, parity, b))
80
80
            parity = 1 - parity