1
1
"""Serve branches at urls that mimic the file system layout."""
5
6
from bzrlib import branch, errors, lru_cache
7
8
from paste.request import path_info_pop
8
9
from paste import httpexceptions
9
from paste import urlparser
11
11
from loggerhead.apps.branch import BranchWSGIApp
12
12
from loggerhead.apps import favicon_app, static_app
13
from loggerhead.config import LoggerheadConfig
14
13
from loggerhead.controllers.directory_ui import DirectoryUI
15
sql_dir = tempfile.mkdtemp(prefix='loggerhead-cache-')
17
18
class BranchesFromFileSystemServer(object):
19
19
def __init__(self, path, root, name=None):
23
self._config = root._config
25
24
def app_for_branch(self, branch):
27
name = branch.get_config().get_nickname()
32
29
branch_app = BranchWSGIApp(
34
{'cachepath': self._config.SQL_DIR},
35
self.root.graph_cache, is_root=is_root,
36
use_cdn=self._config.get_option('use_cdn'))
30
branch, name, {'cachepath': sql_dir}, self.root.graph_cache)
37
31
return branch_app.app
39
33
def app_for_non_branch(self, environ):
49
return DirectoryUI(environ['loggerhead.static.url'],
43
return DirectoryUI(environ['loggerhead.static.url'], self.path, name)
53
45
new_path = os.path.join(self.path, segment)
71
63
class BranchesFromFileSystemRoot(object):
73
def __init__(self, folder, config):
74
self.graph_cache = lru_cache.LRUCache(10)
65
def __init__(self, folder):
66
self.graph_cache = lru_cache.LRUCache()
75
67
self.folder = folder
78
69
def __call__(self, environ, start_response):
79
70
environ['loggerhead.static.url'] = environ['SCRIPT_NAME']
83
74
return static_app(environ, start_response)
84
75
elif environ['PATH_INFO'] == '/favicon.ico':
85
76
return favicon_app(environ, start_response)
86
elif '/.bzr/' in environ['PATH_INFO']:
87
app = urlparser.make_static(None, self.folder)
88
return app(environ, start_response)
90
78
return BranchesFromFileSystemServer(
91
79
self.folder, self)(environ, start_response)
94
82
class UserBranchesFromFileSystemRoot(object):
96
def __init__(self, folder, config):
97
self.graph_cache = lru_cache.LRUCache(10)
84
def __init__(self, folder, trunk_dir):
85
self.graph_cache = lru_cache.LRUCache()
98
86
self.folder = folder
100
self.trunk_dir = config.get_option('trunk_dir')
87
self.trunk_dir = trunk_dir
102
89
def __call__(self, environ, start_response):
103
90
environ['loggerhead.static.url'] = environ['SCRIPT_NAME']
104
path_info = environ['PATH_INFO']
91
path_info= environ['PATH_INFO']
105
92
if path_info.startswith('/static/'):
106
93
segment = path_info_pop(environ)
107
94
assert segment == 'static'