##// END OF EJS Templates
hgweb: use config.config
Matt Mackall -
r8180:6fc30fe7 default
parent child Browse files
Show More
@@ -57,7 +57,7 b' class config:'
57 self._data[section] = sortdict()
57 self._data[section] = sortdict()
58 self._data[section][item] = (value, source)
58 self._data[section][item] = (value, source)
59
59
60 def read(self, path, fp):
60 def read(self, path, fp=None):
61 sectionre = re.compile(r'\[([^\[]+)\]')
61 sectionre = re.compile(r'\[([^\[]+)\]')
62 itemre = re.compile(r'([^=\s]+)\s*=\s*(.*)')
62 itemre = re.compile(r'([^=\s]+)\s*=\s*(.*)')
63 contre = re.compile(r'\s+(\S.*)')
63 contre = re.compile(r'\s+(\S.*)')
@@ -66,6 +66,10 b' class config:'
66 item = None
66 item = None
67 line = 0
67 line = 0
68 cont = 0
68 cont = 0
69
70 if not fp:
71 fp = open(path)
72
69 for l in fp:
73 for l in fp:
70 line += 1
74 line += 1
71 if cont:
75 if cont:
@@ -8,7 +8,8 b''
8
8
9 import os
9 import os
10 from mercurial.i18n import _
10 from mercurial.i18n import _
11 from mercurial import ui, hg, util, templater, templatefilters, error, encoding
11 from mercurial import ui, hg, util, templater, templatefilters
12 from mercurial import config, error, encoding
12 from common import ErrorResponse, get_mtime, staticfile, paritygen,\
13 from common import ErrorResponse, get_mtime, staticfile, paritygen,\
13 get_contact, HTTP_OK, HTTP_NOT_FOUND, HTTP_SERVER_ERROR
14 get_contact, HTTP_OK, HTTP_NOT_FOUND, HTTP_SERVER_ERROR
14 from hgweb_mod import hgweb
15 from hgweb_mod import hgweb
@@ -16,7 +17,7 b' from request import wsgirequest'
16
17
17 # This is a stopgap
18 # This is a stopgap
18 class hgwebdir(object):
19 class hgwebdir(object):
19 def __init__(self, config, parentui=None):
20 def __init__(self, conf, parentui=None):
20 def cleannames(items):
21 def cleannames(items):
21 return [(util.pconvert(name).strip('/'), path)
22 return [(util.pconvert(name).strip('/'), path)
22 for name, path in items]
23 for name, path in items]
@@ -33,28 +34,23 b' class hgwebdir(object):'
33 self.stripecount = None
34 self.stripecount = None
34 self.repos_sorted = ('name', False)
35 self.repos_sorted = ('name', False)
35 self._baseurl = None
36 self._baseurl = None
36 if isinstance(config, (list, tuple)):
37 if isinstance(conf, (list, tuple)):
37 self.repos = cleannames(config)
38 self.repos = cleannames(conf)
38 self.repos_sorted = ('', False)
39 self.repos_sorted = ('', False)
39 elif isinstance(config, dict):
40 elif isinstance(conf, dict):
40 self.repos = util.sort(cleannames(config.items()))
41 self.repos = util.sort(cleannames(conf.items()))
41 else:
42 else:
42 if isinstance(config, util.configparser):
43 if isinstance(conf, config.config):
43 cp = config
44 cp = conf
44 else:
45 else:
45 cp = util.configparser()
46 cp = config.config()
46 cp.read(config)
47 cp.read(conf)
47 self.repos = []
48 self.repos = []
48 if cp.has_section('web'):
49 if cp.has_option('web', 'motd'):
50 self.motd = cp.get('web', 'motd')
49 self.motd = cp.get('web', 'motd')
51 if cp.has_option('web', 'style'):
50 self.style = cp.get('web', 'style', 'paper')
52 self.style = cp.get('web', 'style')
51 self.stripecount = cp.get('web', 'stripes')
53 if cp.has_option('web', 'stripes'):
54 self.stripecount = int(cp.get('web', 'stripes'))
55 if cp.has_option('web', 'baseurl'):
56 self._baseurl = cp.get('web', 'baseurl')
52 self._baseurl = cp.get('web', 'baseurl')
57 if cp.has_section('paths'):
53 if 'paths' in cp:
58 paths = cleannames(cp.items('paths'))
54 paths = cleannames(cp.items('paths'))
59 for prefix, root in paths:
55 for prefix, root in paths:
60 roothead, roottail = os.path.split(root)
56 roothead, roottail = os.path.split(root)
@@ -75,7 +71,6 b' class hgwebdir(object):'
75 if prefix:
71 if prefix:
76 name = prefix + '/' + name
72 name = prefix + '/' + name
77 self.repos.append((name, path))
73 self.repos.append((name, path))
78 if cp.has_section('collections'):
79 for prefix, root in cp.items('collections'):
74 for prefix, root in cp.items('collections'):
80 for path in util.walkrepos(root, followsym=True):
75 for path in util.walkrepos(root, followsym=True):
81 repo = os.path.normpath(path)
76 repo = os.path.normpath(path)
@@ -320,8 +315,7 b' class hgwebdir(object):'
320 style = config('web', 'style', '')
315 style = config('web', 'style', '')
321 if 'style' in req.form:
316 if 'style' in req.form:
322 style = req.form['style'][0]
317 style = req.form['style'][0]
323 if self.stripecount is None:
318 self.stripecount = int(self.stripecount or config('web', 'stripes', 1))
324 self.stripecount = int(config('web', 'stripes', 1))
325 mapfile = templater.stylemap(style)
319 mapfile = templater.stylemap(style)
326 tmpl = templater.templater(mapfile, templatefilters.filters,
320 tmpl = templater.templater(mapfile, templatefilters.filters,
327 defaults={"header": header,
321 defaults={"header": header,
General Comments 0
You need to be logged in to leave comments. Login now