~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/branchview.py

Merge replacins deprecated methods

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
from cherrypy import HTTPRedirect
30
30
 
31
31
from loggerhead import util
32
 
from loggerhead.changecache import ChangeCache
 
32
from loggerhead.changecache import ChangeCache, FileChangeCache
33
33
from loggerhead.history import History
34
34
from loggerhead.textindex import TextIndex
35
35
from loggerhead.controllers.changelog_ui import ChangeLogUI
45
45
 
46
46
 
47
47
class BranchView (object):
48
 
    def __init__(self, group_name, name, subfolder, absfolder, config, project_config):
 
48
    def __init__(self, group_name, name, subfolder, absfolder, config,
 
49
                 project_config, root_config):
49
50
        self._group_name = group_name
50
51
        self._name = name
51
52
        self._folder = subfolder
52
53
        self._absfolder = absfolder
53
54
        self._config = config
54
55
        self._project_config = project_config
 
56
        self._root_config = root_config
55
57
        self.log = logging.getLogger('loggerhead.%s' % (name,))
56
 
        
 
58
 
57
59
        # branch history
58
60
        self._history_lock = threading.RLock()
59
61
        self._history = None
60
62
        self._closed = False
61
 
        
 
63
 
62
64
        self.changes = ChangeLogUI(self)
63
65
        self.revision = RevisionUI(self)
64
66
        self.files = InventoryUI(self)
66
68
        self.download = DownloadUI(self)
67
69
        self.atom = AtomUI(self)
68
70
        self.bundle = BundleUI(self)
69
 
        
 
71
 
70
72
        # force history object to be loaded:
71
73
        self.get_history()
72
 
        
 
74
 
73
75
        turbogears.startup.call_on_shutdown.append(self.close)
74
 
    
 
76
 
75
77
    @with_history_lock
76
78
    def close(self):
77
79
        # it's important that we cleanly detach the history, so the cache
80
82
        self._history.detach()
81
83
        self._history = None
82
84
        self._closed = True
83
 
            
 
85
 
84
86
    config = property(lambda self: self._config)
85
 
    
 
87
 
86
88
    name = property(lambda self: self._name)
87
89
 
88
90
    group_name = property(lambda self: self._group_name)
89
 
    
 
91
 
90
92
    def _get_friendly_name(self):
91
93
        name = self._config.get('branch_name', None)
92
94
        if name is not None:
106
108
        # try branch-specific config?
107
109
        description = self.get_history().get_config().get_user_option('description')
108
110
        return description
109
 
        
 
111
 
110
112
    description = property(_get_description)
111
 
    
 
113
 
112
114
    def _get_branch_url(self):
113
115
        url = self._config.get('url', None)
114
116
        if url is not None:
120
122
        # try branch-specific config?
121
123
        url = self.get_history().get_config().get_user_option('public_branch')
122
124
        return url
123
 
        
 
125
 
124
126
    branch_url = property(_get_branch_url)
125
 
    
 
127
 
126
128
    @turbogears.expose()
127
129
    def index(self):
128
130
        raise HTTPRedirect(self.url('/changes'))
129
131
 
 
132
    def get_config_item(self, item, default=None):
 
133
        for conf in self._config, self._project_config, self._root_config:
 
134
            if item in conf:
 
135
                return conf[item]
 
136
        return default
 
137
 
130
138
    @with_history_lock
131
139
    def get_history(self):
132
140
        """
141
149
            self.log.debug('Reload branch history...')
142
150
            if self._history is not None:
143
151
                self._history.detach()
144
 
            self._history = History.from_folder(self._absfolder, self._name)
 
152
            _history = self._history = History.from_folder(
 
153
                self._absfolder, self._name)
145
154
            cache_path = self._config.get('cachepath', None)
146
155
            if cache_path is None:
147
156
                # try the project config
148
157
                cache_path = self._project_config.get('cachepath', None)
149
158
            if cache_path is not None:
150
 
                self._history.use_cache(ChangeCache(self._history, cache_path))
151
 
                self._history.use_search_index(TextIndex(self._history, cache_path))
 
159
                _history.use_cache(ChangeCache(_history, cache_path))
 
160
                _history.use_file_cache(FileChangeCache(_history, cache_path))
 
161
                _history.use_search_index(TextIndex(_history, cache_path))
152
162
        return self._history
153
 
    
 
163
 
154
164
    def check_rebuild(self):
155
165
        h = self.get_history()
156
166
        if h is not None:
157
167
            h.check_rebuild()
158
 
    
 
168
 
159
169
    def url(self, elements, **kw):
 
170
        "build an url relative to this branch"
160
171
        if not isinstance(elements, list):
161
172
            elements = [elements]
162
173
        if elements[0].startswith('/'):
164
175
        elements = [urllib.quote(x) for x in elements]
165
176
        return turbogears.url([ '/' + self.group_name, self.name ] + elements, **kw)
166
177
 
 
178
    def context_url(self, elements, **kw):
 
179
        "build an url relative to this branch, bringing along browsing context"
 
180
        return self.url(elements, **util.get_context(**kw))
 
181
 
167
182
    def last_updated(self):
168
183
        h = self.get_history()
169
184
        change = h.get_changes([ h.last_revid ])[0]