1
"""The WSGI application for serving a Bazaar branch."""
7
import bzrlib.lru_cache
9
4
from paste import request
10
5
from paste import httpexceptions
6
from paste.wsgiwrappers import WSGIRequest, WSGIResponse
12
8
from loggerhead.apps import static_app
9
from loggerhead.changecache import FileChangeCache
13
10
from loggerhead.controllers.changelog_ui import ChangeLogUI
14
11
from loggerhead.controllers.inventory_ui import InventoryUI
15
12
from loggerhead.controllers.annotate_ui import AnnotateUI
16
13
from loggerhead.controllers.revision_ui import RevisionUI
17
14
from loggerhead.controllers.atom_ui import AtomUI
18
15
from loggerhead.controllers.download_ui import DownloadUI
16
from loggerhead.controllers.bundle_ui import BundleUI
19
17
from loggerhead.history import History
20
18
from loggerhead import util
21
logging.getLogger().setLevel(logging.DEBUG)
23
23
class BranchWSGIApp(object):
25
def __init__(self, branch, friendly_name=None, config={}, graph_cache=None):
25
def __init__(self, branch_url, friendly_name=None, config={}):
26
self.branch_url = branch_url
27
28
self._config = config
28
29
self.friendly_name = friendly_name
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
self.log = logging.getLogger(friendly_name)
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))
34
if (self._history is None) or self._history.out_of_date():
35
self.log.debug('Reload branch history...')
36
_history = self._history = History.from_folder(self.branch_url)
37
cache_path = self._config.get('cachepath', None)
38
if cache_path is not None:
39
_history.use_file_cache(FileChangeCache(_history, cache_path))
50
42
def url(self, *args, **kw):
51
43
if isinstance(args[0], list):
74
66
'revision': RevisionUI,
75
67
'download': DownloadUI,
79
72
def last_updated(self):
80
h = self.get_history()
81
74
change = h.get_changes([ h.last_revid ])[0]
84
77
def branch_url(self):
85
return self.branch.get_config().get_user_option('public_branch')
78
return self.history.get_config().get_user_option('public_branch')
87
80
def app(self, environ, start_response):
81
req = WSGIRequest(environ)
82
response = WSGIResponse()
83
response.headers['Content-Type'] = 'text/plain'
88
84
self._url_base = environ['SCRIPT_NAME']
89
85
self._static_url_base = environ.get('loggerhead.static.url')
90
86
if self._static_url_base is None: