comparison mercurial/hgweb/hgwebdir_mod.py @ 2538:f4b7d71c1c60

Cleanup hgweb and hgwebdir's run method a bit.
author Eric Hopper <hopper@omnifarious.org>
date Fri, 30 Jun 2006 09:50:25 -0700
parents b6975008d44f
children 345bac2bc4ec
comparison
equal deleted inserted replaced
2537:b6975008d44f 2538:f4b7d71c1c60
18 class hgwebdir(object): 18 class hgwebdir(object):
19 def __init__(self, config): 19 def __init__(self, config):
20 def cleannames(items): 20 def cleannames(items):
21 return [(name.strip(os.sep), path) for name, path in items] 21 return [(name.strip(os.sep), path) for name, path in items]
22 22
23 self.origconfig = config
24 self.motd = "" 23 self.motd = ""
25 self.repos_sorted = ('name', False) 24 self.repos_sorted = ('name', False)
26 if isinstance(config, (list, tuple)): 25 if isinstance(config, (list, tuple)):
27 self.repos = cleannames(config) 26 self.repos = cleannames(config)
28 self.repos_sorted = ('', False) 27 self.repos_sorted = ('', False)
46 name = name[len(prefix):] 45 name = name[len(prefix):]
47 self.repos.append((name.lstrip(os.sep), repo)) 46 self.repos.append((name.lstrip(os.sep), repo))
48 self.repos.sort() 47 self.repos.sort()
49 48
50 def run(self): 49 def run(self):
51 if os.environ['GATEWAY_INTERFACE'][0:6] != "CGI/1.": 50 if not os.environ.get('GATEWAY_INTERFACE', '').startswith("CGI/1."):
52 raise RuntimeError("This function is only intended to be called while running as a CGI script.") 51 raise RuntimeError("This function is only intended to be called while running as a CGI script.")
53 import mercurial.hgweb.wsgicgi as wsgicgi 52 import mercurial.hgweb.wsgicgi as wsgicgi
54 from request import wsgiapplication 53 from request import wsgiapplication
55 def make_web_app(): 54 def make_web_app():
56 return self.__class__(self.origconfig) 55 return self
57 wsgicgi.launch(wsgiapplication(make_web_app)) 56 wsgicgi.launch(wsgiapplication(make_web_app))
58 57
59 def run_wsgi(self, req): 58 def run_wsgi(self, req):
60 def header(**map): 59 def header(**map):
61 header_file = cStringIO.StringIO(''.join(tmpl("header", **map))) 60 header_file = cStringIO.StringIO(''.join(tmpl("header", **map)))