#
#
# patch "templates/base.html"
# from [941ad9f0b2cc72c729f78185d140cce2f5088e29]
# to [828ac669dcf846b15ebedc558c7da907079dd685]
#
# patch "templates/index.html"
# from [e0ae8e2a7cc89a8ff8d012742104ded01f6cf968]
# to [08145fdb8457c0f05ead0cdec4717e0f7f0de864]
#
# patch "viewmtn.py"
# from [b33f71afb2e598fadb81114ed5a569af368d390b]
# to [574970773ca270f6282d13161905dae81274170b]
#
============================================================
--- templates/base.html 941ad9f0b2cc72c729f78185d140cce2f5088e29
+++ templates/base.html 828ac669dcf846b15ebedc558c7da907079dd685
@@ -18,6 +18,9 @@
Tags |
Help |
About
+
+#block extramenu
+#end block
#block body
============================================================
--- templates/index.html e0ae8e2a7cc89a8ff8d012742104ded01f6cf968
+++ templates/index.html 08145fdb8457c0f05ead0cdec4717e0f7f0de864
@@ -9,6 +9,21 @@
Select one of the branches and you will be shown a list of recent changes that have occurred within it.
-If you are looking for a particular revision (for example, a release) the list of tags might be useful.
+If you are looking for a particular revision (for example, a release) the list of tags
+might be useful.
+
+
+Branch |
+#for branch in $branches
+
+
+ #filter Filter
+ $link($branch).html()
+ #filter WebSafe
+ |
+
+#end for
+
+
#end def
============================================================
--- viewmtn.py b33f71afb2e598fadb81114ed5a569af368d390b
+++ viewmtn.py 574970773ca270f6282d13161905dae81274170b
@@ -1,9 +1,11 @@
#!/usr/bin/env python
+import cgi
+import mtn
import web
import config
-
import urlparse
+hq = cgi.escape
# /about.psp -> /about
@@ -27,39 +29,146 @@
# /getjson.py -> /json[...] (private)
+class Link:
+ def __init__(self, description=None):
+ self.relative_uri = None
+ self.description = description
+ def html(self):
+ return '%s' % (self.relative_uri,
+ self.description)
+
+class RevisionLink(Link):
+ def __init__(self, revision, **kwargs):
+ Link.__init__(*(self, ), **kwargs)
+ self.relative_uri = 'revision/info/%s' % (revision)
+ self.description = revision.abbrev()
+
+class TagLink(Link):
+ def __init__(self, tag, **kwargs):
+ Link.__init__(*(self, ), **kwargs)
+ self.relative_uri = 'revision/info/%s' % (tag.revision)
+ self.description = tag.name
+
+class BranchLink(Link):
+ def __init__(self, branch, **kwargs):
+ Link.__init__(*(self, ), **kwargs)
+ self.relative_uri = 'branch/changes/' + hq(branch.name)
+ self.description = hq(branch.name)
+
+type_to_link_class = {
+ 'tag' : TagLink,
+ 'branch' : BranchLink
+}
+
+def link(obj):
+ link_class = type_to_link_class.get(obj.obj_type)
+ if not link_class:
+ raise LinkException("Unable to link to objects of type: '%s'" % (obj.obj_type))
+ return link_class(obj)
+
class Renderer:
def __init__(self):
# any templates that can be inherited from, should be added to the list here
- templates = [ ('base.html', 'base'), ]
- for template, mod_name in templates:
- web.render(template, None, True, mod_name)
+ self.templates = [ ('base.html', 'base'),
+ ('revision.html', 'revision'), ]
+ self._templates_loaded = False
+
+ # these variables will be available to any template
self.terms = {
+ 'context' : web.context, # fugly
'dynamic_uri_path' : config.dynamic_uri_path,
'dynamic_join' : lambda path: urlparse.urljoin(config.dynamic_uri_path, path),
+ 'link' : link,
'static_uri_path' : config.static_uri_path,
'static_join' : lambda path: urlparse.urljoin(config.static_uri_path, path),
}
+
+ def load_templates(self):
+ if self._templates_loaded: return
+ for template, mod_name in self.templates:
+ web.render(template, None, True, mod_name)
+ self._templates_loaded = True
+
def render(self, template, **kwargs):
+ self.load_templates()
terms = self.terms.copy()
terms.update(kwargs)
web.render(template, terms)
renderer = Renderer()
+ops = mtn.Operations([config.monotone, config.dbfile])
class Index:
def GET(self):
- renderer.render('index.html', page_title="Branches")
+ renderer.render('index.html', page_title="Branches", branches=ops.branches())
class About:
def GET(self):
renderer.render('about.html', page_title="About")
- page_title = "About"
-id_re = r'[A-Za-z0-9]{40}'
+class Tags:
+ def GET(self):
+ renderer.render('tags.html', page_title="Tags", tags=ops.tags())
+
+class Help:
+ def GET(self):
+ renderer.render('help.html', page_title="Help")
+
+class RevisionInfo:
+ def GET(self, revision):
+ revision = mtn.Revision(revision)
+ renderer.render('revisioninfo.html',
+ page_title="Revision %s" % revision.abbrev(),
+ revision=revision)
+
+class RevisionDiff:
+ def GET(self, revision_from, revision_to):
+ revision_from = mtn.Revision(revision_from)
+ revision_to = mtn.Revision(revision_to)
+ renderer.render('revisiondiff.html',
+ page_title="Diff from %s to %s" % (revision_from.abbrev(), revision_to.abbrev()),
+ revision_from=revision_from,
+ revision_to=revision_to)
+
+class RevisionFile:
+ def GET(self, revision, file):
+ revision = mtn.Revision(revision)
+ print "file %s from revision %s" % (file, revision)
+
+class RevisionBrowse:
+ def GET(self, revision, path):
+ revision = mtn.Revision(revision)
+ renderer.render('revisionpath.html',
+ page_title=revision,
+ path=path)
+
+class RevisionTar:
+ def GET(self, revision):
+ revision = mtn.Revision(revision)
+ print "not implemented"
+
+class Json:
+ def GET(self, method, data):
+ print "Bah."
+
branch_re = r''
urls = (
'/', 'Index',
- '/about', 'About'
+ '/about', 'About',
+ '/tags', 'Tags',
+ '/help', 'Help',
+ '/json/(A-Za-z)/(.*)', 'Json',
+
+ '/revision/browse/('+mtn.revision_re+')/(.*)', 'RevisionBrowse',
+ '/revision/diff/('+mtn.revision_re+')/with/('+mtn.revision_re+')', 'RevisionDiff',
+ '/revision/file/('+mtn.revision_re+')/(.*)', 'RevisionFile',
+ '/revision/info/('+mtn.revision_re+')', 'RevisionInfo',
+ '/revision/tar/('+mtn.revision_re+')', 'RevisionTar',
+
+ '/branch/changes/(.*)', 'BranchChanges',
+ '/branch/head/(.*)', 'BranchHead',
+ '/branch/tar/(.*)', 'BranchTar'
+
)
if __name__ == '__main__':