2
# Copyright (C) 2006 Robey Pointer <robey@lag.net>
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
collection of configuration and objects related to a bazaar branch.
27
from cherrypy import HTTPRedirect
29
from loggerhead import util
30
from loggerhead.changecache import ChangeCache
31
from loggerhead.history import History
32
from loggerhead.textindex import TextIndex
33
from loggerhead.controllers.changelog_ui import ChangeLogUI
34
from loggerhead.controllers.atom_ui import AtomUI
35
from loggerhead.controllers.revision_ui import RevisionUI
36
from loggerhead.controllers.inventory_ui import InventoryUI
37
from loggerhead.controllers.annotate_ui import AnnotateUI
38
from loggerhead.controllers.download_ui import DownloadUI
39
from loggerhead.controllers.bundle_ui import BundleUI
42
with_history_lock = util.with_lock('_history_lock', 'History')
45
class BranchView (object):
46
def __init__(self, group_name, name, config):
47
self._group_name = group_name
50
self.log = logging.getLogger('loggerhead.%s' % (name,))
53
self._history_lock = threading.RLock()
56
self.changes = ChangeLogUI(self)
57
self.revision = RevisionUI(self)
58
self.files = InventoryUI(self)
59
self.annotate = AnnotateUI(self)
60
self.download = DownloadUI(self)
61
self.atom = AtomUI(self)
62
self.bundle = BundleUI(self)
64
# force history object to be loaded:
67
config = property(lambda self: self._config)
69
name = property(lambda self: self._name)
71
group_name = property(lambda self: self._group_name)
73
friendly_name = property(lambda self: self._config.get('branch_name', self._name))
75
description = property(lambda self: self._config.get('description', ''))
77
branch_url = property(lambda self: self._config.get('url', ''))
81
raise HTTPRedirect(self.url('/changes'))
84
def get_history(self):
86
get an up-to-date History object, safely. each page-view calls this
87
method, and normally it will get the same History object as on previous
88
calls. but if the bazaar branch on-disk has been updated since this
89
History was created, a new object will be created and returned.
91
if (self._history is None) or self._history.out_of_date():
92
self.log.debug('Reload branch history...')
93
if self._history is not None:
94
self._history.detach()
95
self._history = History.from_folder(self._config.get('folder'), self._name)
96
cache_path = self._config.get('cachepath', None)
97
if cache_path is not None:
98
self._history.use_cache(ChangeCache(self._history, cache_path))
99
self._history.use_search_index(TextIndex(self._history, cache_path))
102
def check_rebuild(self):
103
h = self.get_history()
106
def url(self, elements, **kw):
107
if not isinstance(elements, list):
108
elements = [elements]
109
if elements[0].startswith('/'):
110
elements[0] = elements[0][1:]
111
return turbogears.url([ '/' + self.group_name, self.name ] + elements, **kw)
113
def last_updated(self):
114
h = self.get_history()
115
change = h.get_changes([ h.last_revid ])[0]