1
"""The WSGI application for serving a Bazaar branch."""
8
import bzrlib.lru_cache
10
4
from paste import request
11
5
from paste import httpexceptions
6
from paste.wsgiwrappers import WSGIRequest, WSGIResponse
13
8
from loggerhead.apps import static_app
9
from loggerhead.changecache import FileChangeCache
14
10
from loggerhead.controllers.changelog_ui import ChangeLogUI
15
11
from loggerhead.controllers.inventory_ui import InventoryUI
16
12
from loggerhead.controllers.annotate_ui import AnnotateUI
17
13
from loggerhead.controllers.revision_ui import RevisionUI
18
14
from loggerhead.controllers.atom_ui import AtomUI
19
15
from loggerhead.controllers.download_ui import DownloadUI
20
from loggerhead.controllers.search_ui import SearchUI
21
from loggerhead.controllers.diff_ui import DiffUI
22
16
from loggerhead.history import History
23
17
from loggerhead import util
26
20
class BranchWSGIApp(object):
28
def __init__(self, branch, friendly_name=None, config={},
29
graph_cache=None, branch_link=None, is_root=False):
22
def __init__(self, branch_url, friendly_name=None, config={}):
23
self.branch_url = branch_url
31
25
self._config = config
32
26
self.friendly_name = friendly_name
33
self.branch_link = branch_link # Currently only used in Launchpad
34
self.log = logging.getLogger('loggerhead.%s' % friendly_name)
35
if graph_cache is None:
36
graph_cache = bzrlib.lru_cache.LRUCache()
37
self.graph_cache = graph_cache
38
self.is_root = is_root
27
self.log = logging.getLogger('loggerhead.%s' % (friendly_name,))
40
def get_history(self):
41
_history = History(self.branch, self.graph_cache)
42
cache_path = self._config.get('cachepath', None)
43
if cache_path is not None:
44
# Only import the cache if we're going to use it.
45
# This makes sqlite optional
47
from loggerhead.changecache import FileChangeCache
49
self.log.debug("Couldn't load python-sqlite,"
50
" continuing without using a cache")
52
_history.use_file_cache(
53
FileChangeCache(_history, cache_path))
31
if (self._history is None) or self._history.out_of_date():
32
self.log.debug('Reload branch history...')
33
_history = self._history = History.from_folder(self.branch_url)
34
cache_path = self._config.get('cachepath', None)
35
if cache_path is not None:
36
_history.use_file_cache(FileChangeCache(_history, cache_path))
56
39
def url(self, *args, **kw):
57
40
if isinstance(args[0], list):
80
63
'revision': RevisionUI,
81
64
'download': DownloadUI,
87
68
def last_updated(self):
88
h = self.get_history()
89
change = h.get_changes([h.last_revid])[0]
70
change = h.get_changes([ h.last_revid ])[0]
92
73
def branch_url(self):
93
return self.branch.get_config().get_user_option('public_branch')
74
return self.history.get_config().get_user_option('public_branch')
95
76
def app(self, environ, start_response):
77
req = WSGIRequest(environ)
78
response = WSGIResponse()
79
response.headers['Content-Type'] = 'text/plain'
96
80
self._url_base = environ['SCRIPT_NAME']
97
81
self._static_url_base = environ.get('loggerhead.static.url')
98
82
if self._static_url_base is None: