2
from bzrlib import branch, errors
1
3
from loggerhead.history import History
2
from loggerhead.wsgiapp import BranchWSGIApp
4
h = History.from_folder('.')
4
from loggerhead.wsgiapp import BranchWSGIApp, static_app
5
from paste.request import path_info_pop
6
from paste import httpexceptions
9
7
from paste import httpserver
10
from paste.evalexception import EvalException
11
8
from paste.httpexceptions import make_middleware
12
9
from paste.translogger import make_filter
15
for w in EvalException, make_middleware:
10
from loggerhead.changecache import FileChangeCache
14
class BranchesFromFileSystemServer(object):
15
def __init__(self, folder, root):
19
def __call__(self, environ, start_response):
20
segment = path_info_pop(environ)
22
raise httpexceptions.HTTPNotFound()
23
relpath = os.path.join(self.folder, segment)
24
f = os.path.join(self.root.folder, relpath)
25
if not os.path.isdir(f):
26
raise httpexceptions.HTTPNotFound()
27
if f in self.root.cache:
28
return self.root.cache[f](environ, start_response)
30
b = branch.Branch.open(f)
31
except errors.NotBranchError:
32
return BranchesFromFileSystemServer(relpath, self.root)(environ, start_response)
36
_history = History.from_branch(b)
37
_history.use_file_cache(FileChangeCache(_history, 'sql'))
38
h = BranchWSGIApp(_history, relpath).app
39
self.root.cache[f] = h
40
return h(environ, start_response)
44
class BranchesFromFileSystemRoot(object):
45
def __init__(self, folder):
48
def __call__(self, environ, start_response):
49
environ['loggerhead.static.url'] = environ['SCRIPT_NAME']
50
segment = path_info_pop(environ)
51
if segment == 'static':
52
return static_app(environ, start_response)
54
return BranchesFromFileSystemServer(
55
segment, self)(environ, start_response)
57
app = BranchesFromFileSystemRoot('../..')
60
app = make_middleware(app)
18
61
app = make_filter(app, None)
20
httpserver.serve(app, host='127.0.0.1', port='9876')
63
from paste.evalexception.middleware import EvalException
65
httpserver.serve(EvalException(app), host='127.0.0.1', port='9876')