~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/apps/filesystem.py

  • Committer: Martin Albisetti
  • Date: 2008-08-15 16:24:50 UTC
  • Revision ID: argentina@gmail.com-20080815162450-m3sqctbtjlnc7btu
Tags: loggerhead-1.6
Update NEWS. 1.6 Released.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
"""Serve branches at urls that mimic the file system layout."""
2
2
 
3
3
import os
 
4
import tempfile
4
5
 
5
6
from bzrlib import branch, errors, lru_cache
6
7
 
7
8
from paste.request import path_info_pop
8
9
from paste import httpexceptions
9
 
from paste import urlparser
10
10
 
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
14
 
 
15
sql_dir = tempfile.mkdtemp(prefix='loggerhead-cache-')
 
16
 
16
17
 
17
18
class BranchesFromFileSystemServer(object):
18
 
 
19
19
    def __init__(self, path, root, name=None):
20
20
        self.path = path
21
21
        self.root = root
22
22
        self.name = name
23
 
        self._config = root._config
24
23
 
25
24
    def app_for_branch(self, branch):
26
25
        if not self.name:
27
 
            name = branch.get_config().get_nickname()
28
 
            is_root = True
 
26
            name = branch.nick
29
27
        else:
30
28
            name = self.name
31
 
            is_root = False
32
29
        branch_app = BranchWSGIApp(
33
 
            branch, name,
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
38
32
 
39
33
    def app_for_non_branch(self, environ):
46
40
                name = self.name
47
41
            else:
48
42
                name = '/'
49
 
            return DirectoryUI(environ['loggerhead.static.url'],
50
 
                               self.path,
51
 
                               name)
 
43
            return DirectoryUI(environ['loggerhead.static.url'], self.path, name)
52
44
        else:
53
45
            new_path = os.path.join(self.path, segment)
54
46
            if self.name:
70
62
 
71
63
class BranchesFromFileSystemRoot(object):
72
64
 
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
76
 
        self._config = config
77
68
 
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)
89
77
        else:
90
78
            return BranchesFromFileSystemServer(
91
79
                self.folder, self)(environ, start_response)
93
81
 
94
82
class UserBranchesFromFileSystemRoot(object):
95
83
 
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
99
 
        self._config = config
100
 
        self.trunk_dir = config.get_option('trunk_dir')
 
87
        self.trunk_dir = trunk_dir
101
88
 
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'