1
"""The WSGI application for serving a Bazaar branch."""
7
import bzrlib.lru_cache
4
9
from paste import request
5
10
from paste import httpexceptions
7
12
from loggerhead.apps import static_app
9
13
from loggerhead.controllers.changelog_ui import ChangeLogUI
10
14
from loggerhead.controllers.inventory_ui import InventoryUI
11
15
from loggerhead.controllers.annotate_ui import AnnotateUI
19
23
class BranchWSGIApp(object):
21
def __init__(self, branch_url, friendly_name=None, config={}):
22
self.branch_url = branch_url
25
def __init__(self, branch, friendly_name=None, config={}, graph_cache=None):
24
27
self._config = config
25
28
self.friendly_name = friendly_name
26
29
self.log = logging.getLogger('loggerhead.%s' % (friendly_name,))
30
if graph_cache is None:
31
graph_cache = bzrlib.lru_cache.LRUCache()
32
self.graph_cache = graph_cache
30
if (self._history is None) or self._history.out_of_date():
31
self.log.debug('Reload branch history...')
32
_history = self._history = History.from_folder(self.branch_url)
33
cache_path = self._config.get('cachepath', None)
34
if cache_path is not None:
35
# Only import the cache if we're going to use it.
36
# This makes sqlite optional
38
from loggerhead.changecache import FileChangeCache
40
self.log.debug("Couldn't load python-sqlite,"
41
" continuing without using a cache")
43
_history.use_file_cache(FileChangeCache(_history,
34
def get_history(self):
35
_history = History(self.branch, self.graph_cache)
36
cache_path = self._config.get('cachepath', None)
37
if cache_path is not None:
38
# Only import the cache if we're going to use it.
39
# This makes sqlite optional
41
from loggerhead.changecache import FileChangeCache
43
self.log.debug("Couldn't load python-sqlite,"
44
" continuing without using a cache")
46
_history.use_file_cache(
47
FileChangeCache(_history, cache_path))
47
50
def url(self, *args, **kw):
48
51
if isinstance(args[0], list):
76
79
def last_updated(self):
80
h = self.get_history()
78
81
change = h.get_changes([ h.last_revid ])[0]
81
84
def branch_url(self):
82
return self.history.get_config().get_user_option('public_branch')
85
return self.branch.get_config().get_user_option('public_branch')
84
87
def app(self, environ, start_response):
85
88
self._url_base = environ['SCRIPT_NAME']
96
99
cls = self.controllers_dict.get(path)
98
101
raise httpexceptions.HTTPNotFound()
100
return c(environ, start_response)
102
self.branch.lock_read()
104
c = cls(self, self.get_history())
105
return c(environ, start_response)