1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
#
# Copyright (C) 2006 Robey Pointer <robey@lag.net>
# Copyright (C) 2006 Goffredo Baroncelli <kreijack@inwind.it>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
import logging
import re
import sys
import time
from configobj import ConfigObj
import turbogears
from turbogears import controllers
from cherrypy import HTTPRedirect, NotFound
my_config = ConfigObj('loggerhead.conf', encoding='utf-8')
extra_path = my_config.get('bzrpath', None)
if extra_path:
sys.path.insert(0, extra_path)
from loggerhead import util
from loggerhead.branchview import BranchView
from loggerhead.history import History
log = logging.getLogger("loggerhead.controllers")
def cherrypy_friendly(s):
"""
convert a config section name into a name that pleases cherrypy.
"""
return re.sub(r'[^\w\d_]', '_', s)
class Project (object):
def __init__(self, name, config):
self.name = name
self.friendly_name = config.get('name', name)
self.description = config.get('description', '')
self.long_description = config.get('long_description', '')
self._views = []
for view_name in config.sections:
log.debug('Configuring (project %r) branch %r...', name, view_name)
c_view_name = cherrypy_friendly(view_name)
view = BranchView(name, c_view_name, view_name, config[view_name], config)
self._views.append(view)
setattr(self, c_view_name, view)
views = property(lambda self: self._views)
class Root (controllers.RootController):
def __init__(self):
global my_config
self._projects = []
for project_name in my_config.sections:
c_project_name = cherrypy_friendly(project_name)
project = Project(c_project_name, my_config[project_name])
self._projects.append(project)
setattr(self, c_project_name, project)
@turbogears.expose(template='loggerhead.templates.browse')
def index(self):
return {
'projects': self._projects,
'util': util,
'title': my_config.get('title', ''),
}
def _check_rebuild(self):
for p in self._projects:
for v in p.views:
v.check_rebuild()
# singleton:
Root = Root()
# re-index every 6 hours
index_freq = 6 * 3600
turbogears.scheduler.add_interval_task(initialdelay=1, interval=index_freq, action=Root._check_rebuild)
# for use in profiling the very-slow get_change() method:
#h = util.get_history()
#w = list(h.get_revision_history())
#h._get_changes_profiled(w[:100])
|