23
from configobj import ConfigObj
25
26
from turbogears import controllers
26
from configobj import ConfigObj
27
from cherrypy import HTTPRedirect, NotFound
28
29
from loggerhead import util
29
from loggerhead.branchview import BranchView
30
from loggerhead.history import is_branch
31
from loggerhead.templatefunctions import templatefunctions
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
33
41
log = logging.getLogger("loggerhead.controllers")
36
def cherrypy_friendly(s):
38
convert a config section name into a name that pleases cherrypy.
40
return re.sub(r'[^\w\d_]', '_', s)
43
class Project (object):
44
def __init__(self, name, config, root_config):
46
self.friendly_name = config.get('name', name)
47
self.description = config.get('description', '')
48
self.long_description = config.get('long_description', '')
50
self._root_config = root_config
53
for view_name in config.sections:
54
log.debug('Configuring (project %s) branch %s...', name, view_name)
55
self._add_view(view_name, config[view_name], config[view_name].get('folder'))
57
self._auto_folder = config.get('auto_publish_folder', None)
59
if self._auto_folder is not None:
60
self._recheck_auto_folders()
62
def _recheck_auto_folders(self):
63
if self._auto_folder is None:
66
# scan a folder for bazaar branches, and add them automatically
67
for path, folders, filenames in os.walk(self._auto_folder):
68
for folder in folders:
69
folder = os.path.join(path, folder)
71
auto_list.append(folder)
73
if auto_list == self._auto_list:
74
# nothing has changed; do nothing.
78
log.debug('Rescanning auto-folder for project %s ...', self.name)
80
for folder in auto_list:
81
view_name = os.path.basename(folder)
82
log.debug('Auto-configuring (project %s) branch %s...', self.name, view_name)
83
self._add_view(view_name, ConfigObj(), folder)
84
self._auto_list = auto_list
86
def _add_view(self, view_name, view_config, folder):
87
c_view_name = cherrypy_friendly(view_name)
89
self.name, c_view_name, view_name, folder, view_config,
90
self._config, self._root_config)
91
self._views.append(view)
92
setattr(self, c_view_name, view)
94
views = property(lambda self: self._views)
97
43
class Root (controllers.RootController):
98
def __init__(self, config):
100
self._config = config
101
for project_name in self._config.sections:
102
c_project_name = cherrypy_friendly(project_name)
104
c_project_name, self._config[project_name], self._config)
105
self._projects.append(project)
106
setattr(self, c_project_name, project)
108
@turbogears.expose(template='zpt:loggerhead.templates.browse')
44
changes = ChangeLogUI()
46
revision = RevisionUI()
48
annotate = AnnotateUI()
110
for p in self._projects:
111
p._recheck_auto_folders()
113
'projects': self._projects,
115
'title': self._config.get('title', None),
117
vals.update(templatefunctions)
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)
84
# for use in profiling the very-slow get_change() method:
85
#h = util.get_history()
86
#h._get_change_profiled(h.last_revid)