~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-20 23:37:59 UTC
  • Revision ID: argentina@gmail.com-20080820233759-y57h48eon7kig1fh
Tweak footer to look better.

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
 
20
from loggerhead.controllers.diff_ui import DiffUI
24
21
from loggerhead.history import History
25
22
from loggerhead import util
26
23
 
27
24
 
28
 
_DEFAULT = object()
29
 
 
30
25
class BranchWSGIApp(object):
31
26
 
32
27
    def __init__(self, branch, friendly_name=None, config={},
33
 
                 graph_cache=None, branch_link=None, is_root=False,
34
 
                 served_url=_DEFAULT):
 
28
                 graph_cache=None, branch_link=None):
35
29
        self.branch = branch
36
30
        self._config = config
37
31
        self.friendly_name = friendly_name
38
32
        self.branch_link = branch_link  # Currently only used in Launchpad
39
 
        self.log = logging.getLogger('loggerhead.%s' % friendly_name)
 
33
        self.log = logging.getLogger('loggerhead.%s' % (friendly_name,))
40
34
        if graph_cache is None:
41
35
            graph_cache = bzrlib.lru_cache.LRUCache()
42
36
        self.graph_cache = graph_cache
43
 
        self.is_root = is_root
44
 
        self.served_url = served_url
45
37
 
46
38
    def get_history(self):
47
39
        _history = History(self.branch, self.graph_cache)
69
61
        qs = '&'.join(qs)
70
62
        return request.construct_url(
71
63
            self._environ, script_name=self._url_base,
72
 
            path_info=unicode('/'.join(args)).encode('utf-8'),
 
64
            path_info='/'.join(args),
73
65
            querystring=qs)
74
66
 
75
67
    def context_url(self, *args, **kw):
80
72
        return self._static_url_base + path
81
73
 
82
74
    controllers_dict = {
83
 
        '+filediff': FileDiffUI,
84
 
        '+revlog': RevLogUI,
85
75
        'annotate': AnnotateUI,
86
 
        'atom': AtomUI,
87
76
        'changes': ChangeLogUI,
88
 
        'diff': DiffUI,
89
 
        'download': DownloadUI,
90
77
        'files': InventoryUI,
91
78
        'revision': RevisionUI,
 
79
        'download': DownloadUI,
 
80
        'atom': AtomUI,
92
81
        'search': SearchUI,
 
82
        'diff': DiffUI,
93
83
        }
94
84
 
95
85
    def last_updated(self):
96
86
        h = self.get_history()
97
 
        change = h.get_changes([h.last_revid])[0]
 
87
        change = h.get_changes([ h.last_revid ])[0]
98
88
        return change.date
99
89
 
100
90
    def branch_url(self):
106
96
        if self._static_url_base is None:
107
97
            self._static_url_base = self._url_base
108
98
        self._environ = environ
109
 
        if self.served_url is _DEFAULT:
110
 
            self.served_url = self.url([])
111
99
        path = request.path_info_pop(environ)
112
100
        if not path:
113
101
            raise httpexceptions.HTTPMovedPermanently(
119
107
            raise httpexceptions.HTTPNotFound()
120
108
        self.branch.lock_read()
121
109
        try:
122
 
            try:
123
 
                c = cls(self, self.get_history)
124
 
                return c(environ, start_response)
125
 
            except:
126
 
                environ['exc_info'] = sys.exc_info()
127
 
                environ['branch'] = self
128
 
                raise
 
110
            c = cls(self, self.get_history())
 
111
            return c(environ, start_response)
129
112
        finally:
130
113
            self.branch.unlock()