~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/apps/branch.py

[rs=igc] update to lp:loggerhead trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008-2011 Canonical Ltd.
 
1
# Copyright (C) 2008, 2009, 2010 Canonical Ltd.
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
29
29
 
30
30
from loggerhead.apps import static_app
31
31
from loggerhead.controllers.annotate_ui import AnnotateUI
32
 
from loggerhead.controllers.view_ui import ViewUI
33
32
from loggerhead.controllers.atom_ui import AtomUI
34
33
from loggerhead.controllers.changelog_ui import ChangeLogUI
35
34
from loggerhead.controllers.diff_ui import DiffUI
63
62
        self.use_cdn = use_cdn
64
63
 
65
64
    def get_history(self):
 
65
        file_cache = None
66
66
        revinfo_disk_cache = None
67
67
        cache_path = self._config.get('cachepath', None)
68
68
        if cache_path is not None:
69
69
            # Only import the cache if we're going to use it.
70
70
            # This makes sqlite optional
71
71
            try:
72
 
                from loggerhead.changecache import RevInfoDiskCache
 
72
                from loggerhead.changecache import (
 
73
                    FileChangeCache, RevInfoDiskCache)
73
74
            except ImportError:
74
75
                self.log.debug("Couldn't load python-sqlite,"
75
76
                               " continuing without using a cache")
76
77
            else:
 
78
                file_cache = FileChangeCache(cache_path)
77
79
                revinfo_disk_cache = RevInfoDiskCache(cache_path)
78
80
        return History(
79
 
            self.branch, self.graph_cache,
 
81
            self.branch, self.graph_cache, file_cache=file_cache,
80
82
            revinfo_disk_cache=revinfo_disk_cache, cache_key=self.friendly_name)
81
83
 
82
84
    def url(self, *args, **kw):
87
89
            if v is not None:
88
90
                qs.append('%s=%s' % (k, urllib.quote(v)))
89
91
        qs = '&'.join(qs)
90
 
        path_info = urllib.quote(
91
 
            unicode('/'.join(args)).encode('utf-8'), safe='/~:')
92
 
        if qs:
93
 
            path_info += '?' + qs
94
 
        return self._url_base + path_info
95
 
 
96
 
    def absolute_url(self, *args, **kw):
97
 
        rel_url = self.url(*args, **kw)
98
 
        return request.resolve_relative_url(rel_url, self._environ)
 
92
        return request.construct_url(
 
93
            self._environ, script_name=self._url_base,
 
94
            path_info=unicode('/'.join(args)).encode('utf-8'),
 
95
            querystring=qs)
99
96
 
100
97
    def context_url(self, *args, **kw):
101
98
        kw = util.get_context(**kw)
122
119
        'files': InventoryUI,
123
120
        'revision': RevisionUI,
124
121
        'search': SearchUI,
125
 
        'view': ViewUI,
126
122
        }
127
123
 
128
124
    def last_updated(self):
133
129
    def public_branch_url(self):
134
130
        return self.branch.get_config().get_user_option('public_branch')
135
131
 
136
 
    def lookup_app(self, environ):
 
132
    def app(self, environ, start_response):
137
133
        # Check again if the branch is blocked from being served, this is
138
134
        # mostly for tests. It's already checked in apps/transport.py
139
135
        if self.branch.get_config().get_user_option('http_serve') == 'False':
158
154
        path = request.path_info_pop(environ)
159
155
        if not path:
160
156
            raise httpexceptions.HTTPMovedPermanently(
161
 
                self.absolute_url('/changes'))
 
157
                self._url_base + '/changes')
162
158
        if path == 'static':
163
 
            return static_app
164
 
        elif path == '+json':
165
 
            environ['loggerhead.as_json'] = True
166
 
            path = request.path_info_pop(environ)
 
159
            return static_app(environ, start_response)
167
160
        cls = self.controllers_dict.get(path)
168
161
        if cls is None:
169
162
            raise httpexceptions.HTTPNotFound()
170
 
        return cls(self, self.get_history)
171
 
 
172
 
    def app(self, environ, start_response):
173
163
        self.branch.lock_read()
174
164
        try:
175
165
            try:
176
 
                c = self.lookup_app(environ)
 
166
                c = cls(self, self.get_history)
177
167
                return c(environ, start_response)
178
168
            except:
179
169
                environ['exc_info'] = sys.exc_info()