15
14
# You should have received a copy of the GNU General Public License
16
15
# along with this program; if not, write to the Free Software
17
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
from paste.request import path_info_pop, parse_querystring
24
from loggerhead import util
25
from loggerhead.templatefunctions import templatefunctions
26
from loggerhead.zptsupport import load_template
28
class BufferingWriter(object):
30
def __init__(self, writefunc, buf_limit):
34
self.writefunc = writefunc
36
self.buf_limit = buf_limit
39
chunk = ''.join(self.buf)
40
chunk = re.sub(r'\s*\n\s*', '\n', chunk)
41
chunk = re.sub(r'[ \t]+', ' ', chunk)
42
self.bytes_saved += self.buflen - len(chunk)
47
def write(self, data):
49
self.buflen += len(data)
50
self.bytes += len(data)
51
if self.buflen > self.buf_limit:
54
class TemplatedBranchView(object):
58
def __init__(self, branch, history):
60
self._history = history
63
def __call__(self, environ, start_response):
66
kw = dict(parse_querystring(environ))
70
arg = path_info_pop(environ)
76
'branch': self._branch,
79
'url': self._branch.context_url,
81
vals.update(templatefunctions)
83
vals.update(self.get_values(h, args, kw, headers))
85
self.log.info('Getting information for %s: %r secs' % (
86
self.__class__.__name__, time.time() - z,))
87
if 'Content-Type' not in headers:
88
headers['Content-Type'] = 'text/html'
89
writer = start_response("200 OK", headers.items())
90
template = load_template(self.template_path)
92
w = BufferingWriter(writer, 8192)
93
template.expand_into(w, **vals)
95
self.log.info('Rendering %s: %r secs, %s bytes, %s (%2.1f%%) bytes saved' % (
96
self.__class__.__name__, time.time() - z, w.bytes, w.bytes_saved, 100.0*w.bytes_saved/w.bytes))
22
from turbogears import controllers
23
from cherrypy import HTTPRedirect, NotFound
25
from loggerhead.controllers.changelog_ui import ChangeLogUI
26
from loggerhead.controllers.atom_ui import AtomUI
27
from loggerhead.controllers.revision_ui import RevisionUI
28
from loggerhead.controllers.inventory_ui import InventoryUI
31
log = logging.getLogger("loggerhead.controllers")
33
class Root (controllers.RootController):
34
changes = ChangeLogUI()
36
revision = RevisionUI()
37
inventory = InventoryUI()
41
raise HTTPRedirect(turbogears.url('/changes'))