~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/apps/branch.py

  • Committer: Martin Albisetti
  • Date: 2008-08-05 05:17:47 UTC
  • mfrom: (190.1.3 branch_locations)
  • Revision ID: argentina@gmail.com-20080805051747-j2s6xl31yqzrjgti
Providing branch_link which will provide a hyperlink on the friendly name (Tim Penhey)

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
import logging
4
4
import urllib
5
 
import sys
6
5
 
7
6
import bzrlib.branch
8
7
import bzrlib.lru_cache
11
10
from paste import httpexceptions
12
11
 
13
12
from loggerhead.apps import static_app
 
13
from loggerhead.controllers.changelog_ui import ChangeLogUI
 
14
from loggerhead.controllers.inventory_ui import InventoryUI
14
15
from loggerhead.controllers.annotate_ui import AnnotateUI
 
16
from loggerhead.controllers.revision_ui import RevisionUI
15
17
from loggerhead.controllers.atom_ui import AtomUI
16
 
from loggerhead.controllers.changelog_ui import ChangeLogUI
17
 
from loggerhead.controllers.diff_ui import DiffUI
18
18
from loggerhead.controllers.download_ui import DownloadUI
19
 
from loggerhead.controllers.filediff_ui import FileDiffUI
20
 
from loggerhead.controllers.inventory_ui import InventoryUI
21
 
from loggerhead.controllers.revision_ui import RevisionUI
22
 
from loggerhead.controllers.revlog_ui import RevLogUI
23
19
from loggerhead.controllers.search_ui import SearchUI
24
20
from loggerhead.history import History
25
21
from loggerhead import util
26
22
 
27
23
 
28
 
_DEFAULT = object()
29
 
 
30
24
class BranchWSGIApp(object):
31
25
 
32
26
    def __init__(self, branch, friendly_name=None, config={},
33
 
                 graph_cache=None, branch_link=None, is_root=False,
34
 
                 served_url=_DEFAULT, use_cdn=False):
 
27
                 graph_cache=None, branch_link=None):
35
28
        self.branch = branch
36
29
        self._config = config
37
30
        self.friendly_name = friendly_name
38
31
        self.branch_link = branch_link  # Currently only used in Launchpad
39
 
        self.log = logging.getLogger('loggerhead.%s' % friendly_name)
 
32
        self.log = logging.getLogger('loggerhead.%s' % (friendly_name,))
40
33
        if graph_cache is None:
41
 
            graph_cache = bzrlib.lru_cache.LRUCache(10)
 
34
            graph_cache = bzrlib.lru_cache.LRUCache()
42
35
        self.graph_cache = graph_cache
43
 
        self.is_root = is_root
44
 
        self.served_url = served_url
45
 
        self.use_cdn = use_cdn
46
36
 
47
37
    def get_history(self):
48
 
        file_cache = None
49
 
        revinfo_disk_cache = None
 
38
        _history = History(self.branch, self.graph_cache)
50
39
        cache_path = self._config.get('cachepath', None)
51
40
        if cache_path is not None:
52
41
            # Only import the cache if we're going to use it.
53
42
            # This makes sqlite optional
54
43
            try:
55
 
                from loggerhead.changecache import (
56
 
                    FileChangeCache, RevInfoDiskCache)
 
44
                from loggerhead.changecache import FileChangeCache
57
45
            except ImportError:
58
46
                self.log.debug("Couldn't load python-sqlite,"
59
47
                               " continuing without using a cache")
60
48
            else:
61
 
                file_cache = FileChangeCache(cache_path)
62
 
                revinfo_disk_cache = RevInfoDiskCache(cache_path)
63
 
        return History(
64
 
            self.branch, self.graph_cache, file_cache=file_cache,
65
 
            revinfo_disk_cache=revinfo_disk_cache, cache_key=self.friendly_name)
 
49
                _history.use_file_cache(
 
50
                    FileChangeCache(_history, cache_path))
 
51
        return _history
66
52
 
67
53
    def url(self, *args, **kw):
68
54
        if isinstance(args[0], list):
74
60
        qs = '&'.join(qs)
75
61
        return request.construct_url(
76
62
            self._environ, script_name=self._url_base,
77
 
            path_info=unicode('/'.join(args)).encode('utf-8'),
 
63
            path_info='/'.join(args),
78
64
            querystring=qs)
79
65
 
80
66
    def context_url(self, *args, **kw):
84
70
    def static_url(self, path):
85
71
        return self._static_url_base + path
86
72
 
87
 
    def yui_url(self, path):
88
 
        if self.use_cdn:
89
 
            base = 'http://yui.yahooapis.com/3.0.0pr2/build/'
90
 
        else:
91
 
            base = self.static_url('/static/javascript/yui/build/')
92
 
        return base + path
93
 
 
94
73
    controllers_dict = {
95
 
        '+filediff': FileDiffUI,
96
 
        '+revlog': RevLogUI,
97
74
        'annotate': AnnotateUI,
98
 
        'atom': AtomUI,
99
75
        'changes': ChangeLogUI,
100
 
        'diff': DiffUI,
101
 
        'download': DownloadUI,
102
76
        'files': InventoryUI,
103
77
        'revision': RevisionUI,
 
78
        'download': DownloadUI,
 
79
        'atom': AtomUI,
104
80
        'search': SearchUI,
105
81
        }
106
82
 
107
83
    def last_updated(self):
108
84
        h = self.get_history()
109
 
        change = h.get_changes([h.last_revid])[0]
 
85
        change = h.get_changes([ h.last_revid ])[0]
110
86
        return change.date
111
87
 
112
88
    def branch_url(self):
118
94
        if self._static_url_base is None:
119
95
            self._static_url_base = self._url_base
120
96
        self._environ = environ
121
 
        if self.served_url is _DEFAULT:
122
 
            public_branch = self.branch_url()
123
 
            if public_branch is not None:
124
 
                self.served_url = public_branch
125
 
            else:
126
 
                self.served_url = self.url([])
127
97
        path = request.path_info_pop(environ)
128
98
        if not path:
129
99
            raise httpexceptions.HTTPMovedPermanently(
135
105
            raise httpexceptions.HTTPNotFound()
136
106
        self.branch.lock_read()
137
107
        try:
138
 
            try:
139
 
                c = cls(self, self.get_history)
140
 
                return c(environ, start_response)
141
 
            except:
142
 
                environ['exc_info'] = sys.exc_info()
143
 
                environ['branch'] = self
144
 
                raise
 
108
            c = cls(self, self.get_history())
 
109
            return c(environ, start_response)
145
110
        finally:
146
111
            self.branch.unlock()