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:
13
class BranchesFromFileSystemServer(object):
14
def __init__(self, folder, root):
18
def __call__(self, environ, start_response):
19
segment = path_info_pop(environ)
21
raise httpexceptions.HTTPNotFound()
22
f = os.path.join(self.folder, segment)
24
if not os.path.isdir(f):
25
raise httpexceptions.HTTPNotFound()
26
if f in self.root.cache:
27
return self.root.cache[f](environ, start_response)
29
b = branch.Branch.open(f)
30
except errors.NotBranchError:
31
return BranchesFromFileSystemServer(f, self.root)(environ, start_response)
35
h = BranchWSGIApp(History.from_branch(b), 'hello').app
36
self.root.cache[f] = h
37
return h(environ, start_response)
41
class BranchesFromFileSystemRoot(object):
42
def __init__(self, folder):
45
def __call__(self, environ, start_response):
46
environ['loggerhead.static.url'] = environ['SCRIPT_NAME']
47
segment = path_info_pop(environ)
48
if segment == 'static':
49
return static_app(environ, start_response)
51
return BranchesFromFileSystemServer(
52
os.path.join(self.folder, segment), self)(environ, start_response)
54
app = BranchesFromFileSystemRoot('../..')
57
app = make_middleware(app)
18
58
app = make_filter(app, None)
20
httpserver.serve(app, host='127.0.0.1', port='9876')
60
from paste.evalexception.middleware import EvalException
62
httpserver.serve(EvalException(app), host='127.0.0.1', port='9876')