review/web_ui.py @ 73284798e9e9
webui
More infrastructure for the web UI.
author |
Steve Losh <steve@stevelosh.com> |
date |
Tue, 13 Oct 2009 20:06:47 -0400 |
parents |
22906da596df |
children |
590fb7bae0a8 |
"""The review extension's web UI."""
import sys, os
import api
from mercurial import cmdutil
package_path = os.path.split(os.path.realpath(__file__))[0]
template_path = os.path.join(package_path, 'web_templates')
media_path = os.path.join(package_path, 'web_media')
top_path = os.path.split(package_path)[0]
bundled_path = os.path.join(top_path, 'bundled')
webpy_path = os.path.join(bundled_path, 'webpy')
sys.path.insert(0, webpy_path)
import web
_rd = None
urls = (
'/', 'index',
'/media/([^/]*)', 'media',
)
from mercurial.node import short
g = { 'node_short': short, 'basename': os.path.basename, }
render = web.template.render(template_path, globals=g)
class index:
def GET(self):
rev_max = _rd.target['tip'].rev()
rev_min = rev_max - 5 if rev_max >= 5 else 0
revs = (_rd.target[r] for r in xrange(rev_max, rev_min, -1))
return render.index(_rd, revs)
class media:
def GET(self, fname):
if '..' in fname:
return ''
else:
with open(os.path.join(media_path, fname)) as f:
content = f.read()
return content
app = web.application(urls, globals())
def load_interface(ui, repo):
global _rd
_rd = api.ReviewDatastore(ui, repo)
print sys.argv
sys.argv = sys.argv[:1] # Seriously, web.py? This is such a hack.
sys.argv = [__file__]
print sys.argv
app.run()