~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/apps/config.py

  • Committer: Martin Albisetti
  • Author(s): Jelmer Vernooij
  • Date: 2008-08-05 17:31:23 UTC
  • mfrom: (197.1.1 trunk)
  • Revision ID: argentina@gmail.com-20080805173123-srwhfyqbinpz2ol3
Add manual page for serve-branches

Show diffs side-by-side

added added

removed removed

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