15
15
# You should have received a copy of the GNU General Public License
16
16
# along with this program; if not, write to the Free Software
17
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
from paste.request import path_info_pop
25
from turbogears import controllers
26
from configobj import ConfigObj
23
28
from loggerhead import util
24
from loggerhead.templatefunctions import templatefunctions
25
from loggerhead.zptsupport import load_template
27
class TemplatedBranchView(object):
31
def __init__(self, branch):
35
def default(self, request, response):
37
h = self._branch.history
45
arg = path_info_pop(request.environ)
51
'branch': self._branch,
54
'url': self._branch.context_url,
56
vals.update(templatefunctions)
57
del response.headers['Content-Type']
58
vals.update(self.get_values(h, args, kw, response))
60
self.log.info('/%s: %r secs' % (
61
self.__class__.__name__, time.time() - z,))
62
if 'Content-Type' not in response.headers:
63
response.headers['Content-Type'] = 'text/html'
64
template = load_template(self.template_path)
65
template.expand_into(response, **vals)
29
from loggerhead.branchview import BranchView
30
from loggerhead.history import is_branch
32
log = logging.getLogger("loggerhead.controllers")
35
def cherrypy_friendly(s):
37
convert a config section name into a name that pleases cherrypy.
39
return re.sub(r'[^\w\d_]', '_', s)
42
class Project (object):
43
def __init__(self, name, config):
45
self.friendly_name = config.get('name', name)
46
self.description = config.get('description', '')
47
self.long_description = config.get('long_description', '')
51
for view_name in config.sections:
52
log.debug('Configuring (project %s) branch %s...', name, view_name)
53
self._add_view(view_name, config[view_name], config[view_name].get('folder'))
55
self._auto_folder = config.get('auto_publish_folder', None)
57
if self._auto_folder is not None:
58
self._recheck_auto_folders()
60
def _recheck_auto_folders(self):
61
if self._auto_folder is None:
64
# scan a folder for bazaar branches, and add them automatically
65
for path, folders, filenames in os.walk(self._auto_folder):
66
for folder in folders:
67
folder = os.path.join(path, folder)
69
auto_list.append(folder)
71
if auto_list == self._auto_list:
72
# nothing has changed; do nothing.
76
log.debug('Rescanning auto-folder for project %s ...', self.name)
78
for folder in auto_list:
79
view_name = os.path.basename(folder)
80
log.debug('Auto-configuring (project %s) branch %s...', self.name, view_name)
81
self._add_view(view_name, ConfigObj(), folder)
82
self._auto_list = auto_list
84
def _add_view(self, view_name, view_config, folder):
85
c_view_name = cherrypy_friendly(view_name)
86
view = BranchView(self.name, c_view_name, view_name, folder, view_config, self._config)
87
self._views.append(view)
88
setattr(self, c_view_name, view)
90
views = property(lambda self: self._views)
93
class Root (controllers.RootController):
94
def __init__(self, config):
97
for project_name in self._config.sections:
98
c_project_name = cherrypy_friendly(project_name)
99
project = Project(c_project_name, self._config[project_name])
100
self._projects.append(project)
101
setattr(self, c_project_name, project)
103
@turbogears.expose(template='loggerhead.templates.browse')
105
for p in self._projects:
106
p._recheck_auto_folders()
108
'projects': self._projects,
110
'title': self._config.get('title', ''),
113
def _check_rebuild(self):
114
for p in self._projects:
120
# for use in profiling the very-slow get_change() method:
121
#h = Root.bazaar.bzr_dev.get_history()
122
#w = list(h.get_revision_history())
123
#h._get_changes_profiled(w[:100])