~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/apps/config.py

  • Committer: Jelmer Vernooij
  • Date: 2008-08-06 18:39:15 UTC
  • mto: (197.1.9 pathargs)
  • mto: This revision was merged to the branch mainline in revision 202.
  • Revision ID: jelmer@samba.org-20080806183915-81q0zlnxq57s0egb
Add --pidfile option to stop-loggerhead.

Show diffs side-by-side

added added

removed removed

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