~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/branchview.py

  • Committer: Robey Pointer
  • Date: 2006-12-21 00:30:31 UTC
  • Revision ID: robey@lag.net-20061221003031-lf4lcav50h39h2zo
oops, missed this url -> branch_url conversion

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
"""
22
22
 
23
23
import logging
24
 
import posixpath
25
24
import threading
26
 
import urllib
27
25
 
28
26
import turbogears
29
27
from cherrypy import HTTPRedirect
30
28
 
31
29
from loggerhead import util
32
 
from loggerhead.changecache import ChangeCache, FileChangeCache
 
30
from loggerhead.changecache import ChangeCache
33
31
from loggerhead.history import History
34
32
from loggerhead.textindex import TextIndex
35
33
from loggerhead.controllers.changelog_ui import ChangeLogUI
45
43
 
46
44
 
47
45
class BranchView (object):
48
 
    def __init__(self, group_name, name, subfolder, absfolder, config, project_config):
 
46
    def __init__(self, group_name, name, config):
49
47
        self._group_name = group_name
50
48
        self._name = name
51
 
        self._folder = subfolder
52
 
        self._absfolder = absfolder
53
49
        self._config = config
54
 
        self._project_config = project_config
55
50
        self.log = logging.getLogger('loggerhead.%s' % (name,))
56
51
        
57
52
        # branch history
58
53
        self._history_lock = threading.RLock()
59
54
        self._history = None
60
 
        self._closed = False
61
55
        
62
56
        self.changes = ChangeLogUI(self)
63
57
        self.revision = RevisionUI(self)
69
63
        
70
64
        # force history object to be loaded:
71
65
        self.get_history()
72
 
        
73
 
        turbogears.startup.call_on_shutdown.append(self.close)
74
66
    
75
 
    @with_history_lock
76
 
    def close(self):
77
 
        # it's important that we cleanly detach the history, so the cache
78
 
        # files can be closed correctly and hopefully remain uncorrupted.
79
 
        # this should also stop any ongoing indexing.
80
 
        self._history.detach()
81
 
        self._history = None
82
 
        self._closed = True
83
 
            
84
67
    config = property(lambda self: self._config)
85
68
    
86
69
    name = property(lambda self: self._name)
87
70
 
88
71
    group_name = property(lambda self: self._group_name)
89
72
    
90
 
    def _get_friendly_name(self):
91
 
        name = self._config.get('branch_name', None)
92
 
        if name is not None:
93
 
            return name
94
 
        # try branch-specific config?
95
 
        name = self.get_history().get_config().get_nickname()
96
 
        if name is not None:
97
 
            return name
98
 
        return self._name
99
 
 
100
 
    friendly_name = property(_get_friendly_name)
101
 
 
102
 
    def _get_description(self):
103
 
        description = self._config.get('description', None)
104
 
        if description is not None:
105
 
            return description
106
 
        # try branch-specific config?
107
 
        description = self.get_history().get_config().get_user_option('description')
108
 
        return description
109
 
        
110
 
    description = property(_get_description)
111
 
    
112
 
    def _get_branch_url(self):
113
 
        url = self._config.get('url', None)
114
 
        if url is not None:
115
 
            return url
116
 
        # try to assemble one from the project, if an url_prefix was defined.
117
 
        url = self._project_config.get('url_prefix', None)
118
 
        if url is not None:
119
 
            return posixpath.join(url, self._folder) + '/'
120
 
        # try branch-specific config?
121
 
        url = self.get_history().get_config().get_user_option('public_branch')
122
 
        return url
123
 
        
124
 
    branch_url = property(_get_branch_url)
125
 
    
 
73
    friendly_name = property(lambda self: self._config.get('branch_name', self._name))
 
74
 
 
75
    description = property(lambda self: self._config.get('description', ''))
 
76
    
 
77
    branch_url = property(lambda self: self._config.get('url', ''))
 
78
 
126
79
    @turbogears.expose()
127
80
    def index(self):
128
81
        raise HTTPRedirect(self.url('/changes'))
135
88
        calls.  but if the bazaar branch on-disk has been updated since this
136
89
        History was created, a new object will be created and returned.
137
90
        """
138
 
        if self._closed:
139
 
            return None
140
91
        if (self._history is None) or self._history.out_of_date():
141
92
            self.log.debug('Reload branch history...')
142
93
            if self._history is not None:
143
94
                self._history.detach()
144
 
            _history = self._history = History.from_folder(
145
 
                self._absfolder, self._name)
 
95
            self._history = History.from_folder(self._config.get('folder'), self._name)
146
96
            cache_path = self._config.get('cachepath', None)
147
 
            if cache_path is None:
148
 
                # try the project config
149
 
                cache_path = self._project_config.get('cachepath', None)
150
97
            if cache_path is not None:
151
 
                _history.use_cache(ChangeCache(_history, cache_path))
152
 
                _history.use_file_cache(FileChangeCache(_history, cache_path))
153
 
                _history.use_search_index(TextIndex(_history, cache_path))
 
98
                self._history.use_cache(ChangeCache(self._history, cache_path))
 
99
                self._history.use_search_index(TextIndex(self._history, cache_path))
154
100
        return self._history
155
101
    
156
102
    def check_rebuild(self):
157
103
        h = self.get_history()
158
 
        if h is not None:
159
 
            h.check_rebuild()
 
104
        h.check_rebuild()
160
105
    
161
106
    def url(self, elements, **kw):
162
 
        "build an url relative to this branch"
163
107
        if not isinstance(elements, list):
164
108
            elements = [elements]
165
109
        if elements[0].startswith('/'):
166
110
            elements[0] = elements[0][1:]
167
 
        elements = [urllib.quote(x) for x in elements]
168
111
        return turbogears.url([ '/' + self.group_name, self.name ] + elements, **kw)
169
112
 
170
 
    def context_url(self, elements, **kw):
171
 
        "build an url relative to this branch, bringing along browsing context"
172
 
        return self.url(elements, **util.get_context(**kw))
173
 
    
174
113
    def last_updated(self):
175
114
        h = self.get_history()
176
115
        change = h.get_changes([ h.last_revid ])[0]