~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/apps/config.py

  • Committer: Matt Nordhoff
  • Date: 2009-05-17 11:10:38 UTC
  • mto: (346.2.1 serve-directory)
  • mto: This revision was merged to the branch mainline in revision 350.
  • Revision ID: mnordhoff@mattnordhoff.com-20090517111038-26vo32le1dyp42lh
Fix 'bzr serve --http' (bug #377551).

I also added an optional 'argv' argument to LoggerheadConfig, defaulting to sys.argv[1:] like it used to do.

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
 
11
11
import bzrlib.lru_cache
12
12
 
13
 
from configobj import ConfigObj
 
13
from bzrlib.util.configobj.configobj import ConfigObj
14
14
 
15
15
from paste.request import path_info_pop
16
16
from paste import httpexceptions
17
17
from paste.wsgiwrappers import WSGIResponse
18
18
 
19
19
from loggerhead.apps.branch import BranchWSGIApp
20
 
from loggerhead.apps import favicon_app, static_app
 
20
from loggerhead.apps import favicon_app, static_app, robots_app
21
21
from loggerhead.templatefunctions import templatefunctions
22
22
from loggerhead.zptsupport import load_template
23
23
from loggerhead import util
26
26
 
27
27
from loggerhead.history import is_branch
28
28
 
 
29
 
29
30
class Project(object):
30
31
    """A project contains the branches.
31
32
 
73
74
        log.debug('Rescanning auto-folder for project %s ...', self.name)
74
75
        for folder in auto_list:
75
76
            view_name = os.path.basename(folder)
76
 
            log.debug('Auto-configuring (project %s) branch %s...', self.name, view_name)
 
77
            log.debug('Auto-configuring (project %s) branch %s...',
 
78
                      self.name,
 
79
                      view_name)
77
80
            self._add_view(view_name, ConfigObj(), folder)
78
81
        self._auto_list = auto_list
79
82
 
90
93
        description = view_config.get('description', None)
91
94
        if description is not None:
92
95
            return description
93
 
        description = history._branch.get_config().get_user_option('description')
 
96
        description = history._branch.get_config().get_user_option(
 
97
                          'description')
94
98
        return description
95
99
 
96
100
    def _add_view(self, view_name, view_config, folder):
104
108
                friendly_name = history.get_config().get_nickname()
105
109
                if friendly_name is None:
106
110
                    friendly_name = view_name
 
111
            branch_url = self._get_branch_url(view, view_config, view_name)
 
112
            description = self._get_description(view, view_config, history)
107
113
            self.view_data_by_name[view_name] = {
108
114
                'branch_path': folder,
109
 
                'args': (view_name, view_config, self.graph_cache),
110
 
                'description': self._get_description(view, view_config, history),
111
 
                '_src_folder': folder,
112
 
                '_view_config': view_config,
 
115
                'config': view_config,
 
116
                'description': description,
113
117
                'friendly_name': friendly_name,
 
118
                'graph_cache': self.graph_cache,
114
119
                'name': view_name,
 
120
                'served_url': branch_url,
115
121
                }
116
 
            branch_url = self._get_branch_url(view, view_config, view_name)
117
 
            if branch_url is not None:
118
 
                self.view_data_by_name[view_name]['branch_url'] = branch_url
119
122
            self.view_names.append(view_name)
120
123
        finally:
121
124
            b.unlock()
126
129
            return None
127
130
        view_data = view_data.copy()
128
131
        branch_path = view_data.pop('branch_path')
129
 
        args = view_data.pop('args')
 
132
        description = view_data.pop('description')
 
133
        name = view_data.pop('name')
130
134
        b = bzrlib.branch.Branch.open(branch_path)
131
135
        b.lock_read()
132
 
        view = BranchWSGIApp(b, *args)
133
 
        for k in view_data:
134
 
            setattr(view, k, view_data[k])
 
136
        view = BranchWSGIApp(b, **view_data)
 
137
        view.description = description
 
138
        view.name = name
135
139
        return view
136
140
 
137
141
    def call(self, environ, start_response):
158
162
        self.projects_by_name = {}
159
163
        graph_cache = bzrlib.lru_cache.LRUCache()
160
164
        for project_name in self.config.sections:
161
 
            project = Project(
162
 
                project_name, self.config[project_name], self.config, graph_cache)
 
165
            project = Project(project_name, self.config[project_name],
 
166
                              self.config, graph_cache)
163
167
            self.projects.append(project)
164
168
            self.projects_by_name[project_name] = project
165
169
 
169
173
        # branches again.
170
174
        for p in self.projects:
171
175
            p._recheck_auto_folders()
 
176
 
172
177
        class branch(object):
 
178
 
173
179
            @staticmethod
174
180
            def static_url(path):
175
181
                return self._static_url_base + path
208
214
            response = WSGIResponse()
209
215
            self.browse(response)
210
216
            return response(environ, start_response)
 
217
        elif segment == 'robots.txt':
 
218
            return robots_app(environ, start_response)
211
219
        elif segment == 'static':
212
220
            return static_app(environ, start_response)
213
221
        elif segment == 'favicon.ico':