14
16
# You should have received a copy of the GNU General Public License
15
17
# along with this program; if not, write to the Free Software
16
18
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
from turbogears import controllers
23
from cherrypy import HTTPRedirect, NotFound
26
from okulo.controllers.page_ui import PageUI
27
from okulo.controllers.login_ui import LoginUI, LogoutUI
28
from okulo.controllers.history_ui import HistoryUI
29
from okulo.controllers.edit_ui import EditUI
30
from okulo.controllers.contents_ui import ContentsUI
31
from okulo.controllers.source_ui import SourceUI
32
from okulo.controllers.search_ui import SearchUI
33
from okulo.controllers.add_ui import AddUI
34
from okulo.controllers.signup_ui import SignupUI
35
from okulo.controllers.atom_ui import AtomUI
36
from okulo.controllers.userhome_ui import UserHomeUI
37
from okulo.controllers.delete_ui import DeleteUI
39
from loggerhead.controllers.changelog_ui import ChangeLogUI
40
from loggerhead.controllers.atom_ui import AtomUI
43
log = logging.getLogger("loggerhead.controllers")
45
class Root (controllers.RootController):
46
changes = ChangeLogUI()
49
@turbogears.expose(template="loggerhead.templates.welcome")
52
log.debug("Happy TurboGears Controller Responding For Duty")
53
return dict(now=time.ctime())
56
if args['cmd'][0] == 'changelog':
58
otherrevid = get("otherrevid")
59
pathrevid = get("pathrevid")
62
self.write(self.changelog(revno, None, path, pathrevid, otherrevid))
64
def changelog(self, revid, search=None, path=None,
65
pathrevid=None, otherrevid=None ):
67
return cmd_changelog.changelog(self, revid, search, path,
68
pathrevid, otherrevid )
72
revid, history, pathrevid, otherrevid =
73
hgweb.compute_history(revid, path, pathrevid, otherrevid )
76
class Root (controllers.Root):
82
contents = ContentsUI()
91
def index(self, *args):
92
raise HTTPRedirect(turbogears.url('/page/start'))
95
def default(self, *args):
96
if args[0].startswith('~'):
97
home = UserHomeUI(args[0][1:])
100
return home.default(*args[1:])
23
from paste.request import path_info_pop, parse_querystring
25
from loggerhead import util
26
from loggerhead.templatefunctions import templatefunctions
27
from loggerhead.zptsupport import load_template
30
class BufferingWriter(object):
32
def __init__(self, writefunc, buf_limit):
36
self.writefunc = writefunc
38
self.buf_limit = buf_limit
41
chunk = ''.join(self.buf)
42
chunk = re.sub(r'\s*\n\s*', '\n', chunk)
43
chunk = re.sub(r'[ \t]+', ' ', chunk)
44
self.bytes_saved += self.buflen - len(chunk)
49
def write(self, data):
51
self.buflen += len(data)
52
self.bytes += len(data)
53
if self.buflen > self.buf_limit:
57
class TemplatedBranchView(object):
61
def __init__(self, branch, history_callable):
63
self._history_callable = history_callable
69
if self.__history is not None:
71
self.__history = self._history_callable()
74
def __call__(self, environ, start_response):
76
kwargs = dict(parse_querystring(environ))
77
util.set_context(kwargs)
80
arg = path_info_pop(environ)
87
path = '/'.join(args[1:])
91
'static_url': self._branch.static_url,
92
'branch': self._branch,
94
'url': self._branch.context_url,
96
vals.update(templatefunctions)
99
vals.update(self.get_values(path, kwargs, headers))
101
self.log.info('Getting information for %s: %r secs' % (
102
self.__class__.__name__, time.time() - z))
103
if 'Content-Type' not in headers:
104
headers['Content-Type'] = 'text/html'
105
writer = start_response("200 OK", headers.items())
106
template = load_template(self.template_path)
108
w = BufferingWriter(writer, 8192)
109
template.expand_into(w, **vals)
112
'Rendering %s: %r secs, %s bytes, %s (%2.1f%%) bytes saved' % (
113
self.__class__.__name__,
117
100.0*w.bytes_saved/w.bytes))
124
if len(self.args) > 0:
125
return h.fix_revid(self.args[0])