# # # patch "viewmtn.py" # from [7b4da2d6e174dbee0d81e4460856e7779773ad31] # to [78b92d8c6980db2077c8fb48277b64f5088c74ee] # ============================================================ --- viewmtn.py 7b4da2d6e174dbee0d81e4460856e7779773ad31 +++ viewmtn.py 78b92d8c6980db2077c8fb48277b64f5088c74ee @@ -104,7 +104,7 @@ def normalise_changelog(changelog): changelog = changelog[:-1] return changelog -class Link: +class Link(object): def __init__(self, description=None, link_type=None, **kwargs): self.absolute_uri = None self.relative_uri = None @@ -217,7 +217,7 @@ class FileLink(Link): self.relative_uri = 'revision/' + access_method + '/' + file.in_revision + '/' + urllib.quote(file.name) self.description = hq(file.name) -class Diff: +class Diff(object): def __init__(self, from_rev, to_rev, fname=None): self.obj_type = 'diff' self.fname = fname @@ -339,7 +339,7 @@ class ComparisonRev: if not other: return 1 return cmp(other.date, self.date) -class Renderer: +class Renderer(object): def __init__(self): # any templates that can be inherited from, should be added to the list here self.templates = [ ('base.html', 'base'), @@ -376,7 +376,7 @@ class Renderer: terms.update(kwargs) web.render(template, terms) -class OperationsFactory: +class OperationsFactory(object): def __init__ (self): # has the user specified a dbfiles hash? if so, use it self.ops_instances = {} @@ -414,7 +414,7 @@ from mk2 import MarkovChain from mk2 import MarkovChain -class BranchDivisions: +class BranchDivisions(object): def __init__ (self): self.divisions = None @@ -436,8 +436,8 @@ divisions = BranchDivisions () divisions = BranchDivisions () -class Index: - def GET(self): +class Index(object): + def GET(self, *args): branches = list(ops.branches ()) divisions.calculate_divisions (branches) def division_iter(): @@ -471,11 +471,11 @@ class Index: yield end_div (div) renderer.render('index.html', page_title="Branches", branches=division_iter()) -class About: +class About(object): def GET(self): renderer.render('about.html', page_title="About") -class Tags: +class Tags(object): def GET(self, restrict_branch=None): # otherwise we couldn't use automate again.. tags = list(ops.tags()) @@ -500,11 +500,11 @@ class Tags: return rv renderer.render(template_file, page_title="Tags", tags=tags, revision_ago=revision_ago, branch=restrict_branch) -class Help: +class Help(object): def GET(self): renderer.render('help.html', page_title="Help") -class Changes: +class Changes(object): def __get_last_changes(self, start_from, parent_func, selection_func, n): """returns at least n revisions that are parents of the revisions in start_from, ordered by time (descending). selection_func is called for each revision, and @@ -1194,7 +1194,7 @@ def ancestry_graph(revision): os.system(command) return output_png, output_imagemap -class RevisionGraph: +class RevisionGraph(object): def GET(self, revision): output_png, output_imagemap = ancestry_graph(revision) if os.access(output_png, os.R_OK): @@ -1251,7 +1251,7 @@ class Json(object): return web.notfound() print writer.write(rv) -class BranchHead: +class BranchHead(object): def GET(self, head_method, proxy_to, branch, extra_path): branch = mtn.Branch(branch) valid = ('browse', 'file', 'downloadfile', 'info', 'tar', 'graph') @@ -1286,7 +1286,7 @@ class BranchHead: anyhead=anyhead, head_links=head_links) -class MimeIcon: +class MimeIcon(object): def GET(self, type, sub_type): if not mimeicon: return web.notfound() @@ -1298,7 +1298,7 @@ class MimeIcon: else: return web.notfound() -class RobotsTxt: +class RobotsTxt(object): def GET(self): web.header('Content-Type', 'text/plain') print "User-agent: *" @@ -1311,7 +1311,6 @@ common_urls = ( common_urls = ( # these don't care about multiple databases specified via the URL - r'', 'Index', r'about', 'About', r'help', 'Help', r'robots.txt', 'RobotsTxt', ## FIXME needs o exclude per-db paths @@ -1319,6 +1318,7 @@ perdb_urls = ( ) perdb_urls = ( + r'', 'Index', r'tags', 'Tags', r'json/([A-Za-z]+)/(.*)', 'Json', @@ -1374,19 +1374,22 @@ if __name__ == '__main__': def get_db_closure (fn): the_cls = globals()[fn]() - class PerDBClosure: + class PerDBClosure(object): def GET (self, *args, **kwargs): db, other_args = args[0], args[1:] + print >>sys.stderr, "-> selected db", db the_cls.GET (*other_args, **kwargs) - return PerDBClosure + rv = PerDBClosure + print >>sys.stderr, rv + return rv for url, fn in grouper (2, perdb_urls): url = r'^/([A-Za-z]+/)?' + url urls += (url, fn) fvars[fn] = get_db_closure (fn) - print "fvars::", fvars['Index'] - print "globals:", globals()['Index'] + return urls, fvars + urls, fvars = assemble_urls() func = lambda : per_request_wrapper(web.webpyfunc(urls, fvars=fvars)) web.run(func, globals(), web.reloader)