23
from configobj import ConfigObj
27
26
from turbogears import controllers
28
27
from cherrypy import HTTPRedirect, NotFound
29
from configobj import ConfigObj
31
29
from loggerhead import util
32
from loggerhead.branchview import BranchView
33
from loggerhead.history import History, is_branch
31
my_config = ConfigObj('loggerhead.conf', encoding='utf-8')
32
util.set_config(my_config)
34
from loggerhead.controllers.changelog_ui import ChangeLogUI
35
from loggerhead.controllers.atom_ui import AtomUI
36
from loggerhead.controllers.revision_ui import RevisionUI
37
from loggerhead.controllers.inventory_ui import InventoryUI
38
from loggerhead.controllers.annotate_ui import AnnotateUI
39
from loggerhead.history import History
35
41
log = logging.getLogger("loggerhead.controllers")
38
def cherrypy_friendly(s):
40
convert a config section name into a name that pleases cherrypy.
42
return re.sub(r'[^\w\d_]', '_', s)
45
class Project (object):
46
def __init__(self, name, config):
48
self.friendly_name = config.get('name', name)
49
self.description = config.get('description', '')
50
self.long_description = config.get('long_description', '')
54
for view_name in config.sections:
55
log.debug('Configuring (project %r) branch %r...', name, view_name)
56
self._add_view(view_name, config[view_name], config[view_name].get('folder'))
58
auto_folder = config.get('auto_publish_folder', None)
59
if auto_folder is not None:
61
# scan a folder for bazaar branches, and add them automatically
62
for path, folders, filenames in os.walk(auto_folder):
63
for folder in folders:
64
folder = os.path.join(path, folder)
66
auto_list.append(folder)
68
for folder in auto_list:
69
view_name = os.path.basename(folder)
70
log.debug('Auto-configuring (project %r) branch %r...', name, view_name)
71
self._add_view(view_name, ConfigObj(), folder)
73
def _add_view(self, view_name, view_config, folder):
74
c_view_name = cherrypy_friendly(view_name)
75
view = BranchView(self.name, c_view_name, view_name, folder, view_config, self._config)
76
self._views.append(view)
77
setattr(self, c_view_name, view)
79
views = property(lambda self: self._views)
82
43
class Root (controllers.RootController):
85
for project_name in sys._loggerhead_config.sections:
86
c_project_name = cherrypy_friendly(project_name)
87
project = Project(c_project_name, sys._loggerhead_config[project_name])
88
self._projects.append(project)
89
setattr(self, c_project_name, project)
91
@turbogears.expose(template='loggerhead.templates.browse')
44
changes = ChangeLogUI()
46
revision = RevisionUI()
48
annotate = AnnotateUI()
94
'projects': self._projects,
96
'title': sys._loggerhead_config.get('title', ''),
99
def _check_rebuild(self):
100
for p in self._projects:
52
raise HTTPRedirect(turbogears.url('/changes'))
55
# force history to be read:
61
log.info('Rebuilding revision cache...')
62
last_update = time.time()
63
h = util.get_history()
66
work = h.get_revision_history()
72
if time.time() - last_update > 60:
73
log.info('Revision cache rebuilding continues: %d/%d' % (count, len(work)))
74
last_update = time.time()
76
log.info('Revision cache rebuild completed.')
79
# re-index every hour (for now -- maybe should be even longer?)
82
turbogears.scheduler.add_interval_task(initialdelay=1, interval=index_freq, action=rebuild_cache)
109
84
# for use in profiling the very-slow get_change() method:
110
#h = Root.bazaar.bzr_dev.get_history()
111
#w = list(h.get_revision_history())
112
#h._get_changes_profiled(w[:100])
85
#h = util.get_history()
86
#h._get_change_profiled(h.last_revid)