comparison mercurial/hgweb/hgwebdir_mod.py @ 8215:227707c90548

hgweb: some cleanups in hgwebdir, remove double defaults Removed obsolete command, expose useful cleannames function.
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Mon, 27 Apr 2009 11:37:08 +0200
parents a1a5a57efe90
children 25266fe996b0
comparison
equal deleted inserted replaced
8214:a2af1d92b913 8215:227707c90548
13 from common import ErrorResponse, get_mtime, staticfile, paritygen,\ 13 from common import ErrorResponse, get_mtime, staticfile, paritygen,\
14 get_contact, HTTP_OK, HTTP_NOT_FOUND, HTTP_SERVER_ERROR 14 get_contact, HTTP_OK, HTTP_NOT_FOUND, HTTP_SERVER_ERROR
15 from hgweb_mod import hgweb 15 from hgweb_mod import hgweb
16 from request import wsgirequest 16 from request import wsgirequest
17 17
18 # This is a stopgap 18 def cleannames(items):
19 return [(util.pconvert(name).strip('/'), path) for name, path in items]
20
19 class hgwebdir(object): 21 class hgwebdir(object):
22
20 def __init__(self, conf, baseui=None): 23 def __init__(self, conf, baseui=None):
21 def cleannames(items):
22 return [(util.pconvert(name).strip('/'), path)
23 for name, path in items]
24 24
25 if baseui: 25 if baseui:
26 self.ui = baseui.copy() 26 self.ui = baseui.copy()
27 else: 27 else:
28 self.ui = ui.ui() 28 self.ui = ui.ui()
29 self.ui.setconfig('ui', 'report_untrusted', 'off') 29 self.ui.setconfig('ui', 'report_untrusted', 'off')
30 self.ui.setconfig('ui', 'interactive', 'off') 30 self.ui.setconfig('ui', 'interactive', 'off')
31 31
32 self.motd = None 32 self.motd = None
33 self.style = 'paper' 33 self.style = 'paper'
34 self.stripecount = None 34 self.stripecount = 1
35 self.repos_sorted = ('name', False) 35 self.repos_sorted = ('name', False)
36 self._baseurl = None 36 self._baseurl = None
37
37 if isinstance(conf, (list, tuple)): 38 if isinstance(conf, (list, tuple)):
38 self.repos = cleannames(conf) 39 self.repos = cleannames(conf)
39 self.repos_sorted = ('', False) 40 self.repos_sorted = ('', False)
40 elif isinstance(conf, dict): 41 elif isinstance(conf, dict):
41 self.repos = sorted(cleannames(conf.items())) 42 self.repos = sorted(cleannames(conf.items()))
46 cp = config.config() 47 cp = config.config()
47 cp.read(conf) 48 cp.read(conf)
48 self.repos = [] 49 self.repos = []
49 self.motd = cp.get('web', 'motd') 50 self.motd = cp.get('web', 'motd')
50 self.style = cp.get('web', 'style', 'paper') 51 self.style = cp.get('web', 'style', 'paper')
51 self.stripecount = cp.get('web', 'stripes') 52 self.stripecount = cp.get('web', 'stripes', 1)
52 self._baseurl = cp.get('web', 'baseurl') 53 self._baseurl = cp.get('web', 'baseurl')
53 if 'paths' in cp: 54 if 'paths' in cp:
54 paths = cleannames(cp.items('paths')) 55 paths = cleannames(cp.items('paths'))
55 for prefix, root in paths: 56 for prefix, root in paths:
56 roothead, roottail = os.path.split(root) 57 roothead, roottail = os.path.split(root)
308 309
309 staticurl = config('web', 'staticurl') or url + 'static/' 310 staticurl = config('web', 'staticurl') or url + 'static/'
310 if not staticurl.endswith('/'): 311 if not staticurl.endswith('/'):
311 staticurl += '/' 312 staticurl += '/'
312 313
313 style = self.style 314 style = 'style' in req.form and req.form['style'][0] or self.style
314 if style is None:
315 style = config('web', 'style', '')
316 if 'style' in req.form:
317 style = req.form['style'][0]
318 self.stripecount = int(self.stripecount or config('web', 'stripes', 1))
319 mapfile = templater.stylemap(style) 315 mapfile = templater.stylemap(style)
320 tmpl = templater.templater(mapfile, templatefilters.filters, 316 tmpl = templater.templater(mapfile, templatefilters.filters,
321 defaults={"header": header, 317 defaults={"header": header,
322 "footer": footer, 318 "footer": footer,
323 "motd": motd, 319 "motd": motd,