Mercurial > hg
changeset 8180:6fc30fe7f3e7
hgweb: use config.config
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Sun, 26 Apr 2009 16:50:43 -0500 |
parents | 0f3b8404051b |
children | 03d93882fc93 |
files | mercurial/config.py mercurial/hgweb/hgwebdir_mod.py |
diffstat | 2 files changed, 29 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/config.py Sun Apr 26 16:50:43 2009 -0500 +++ b/mercurial/config.py Sun Apr 26 16:50:43 2009 -0500 @@ -57,7 +57,7 @@ self._data[section] = sortdict() self._data[section][item] = (value, source) - def read(self, path, fp): + def read(self, path, fp=None): sectionre = re.compile(r'\[([^\[]+)\]') itemre = re.compile(r'([^=\s]+)\s*=\s*(.*)') contre = re.compile(r'\s+(\S.*)') @@ -66,6 +66,10 @@ item = None line = 0 cont = 0 + + if not fp: + fp = open(path) + for l in fp: line += 1 if cont:
--- a/mercurial/hgweb/hgwebdir_mod.py Sun Apr 26 16:50:43 2009 -0500 +++ b/mercurial/hgweb/hgwebdir_mod.py Sun Apr 26 16:50:43 2009 -0500 @@ -8,7 +8,8 @@ import os from mercurial.i18n import _ -from mercurial import ui, hg, util, templater, templatefilters, error, encoding +from mercurial import ui, hg, util, templater, templatefilters +from mercurial import config, error, encoding from common import ErrorResponse, get_mtime, staticfile, paritygen,\ get_contact, HTTP_OK, HTTP_NOT_FOUND, HTTP_SERVER_ERROR from hgweb_mod import hgweb @@ -16,7 +17,7 @@ # This is a stopgap class hgwebdir(object): - def __init__(self, config, parentui=None): + def __init__(self, conf, parentui=None): def cleannames(items): return [(util.pconvert(name).strip('/'), path) for name, path in items] @@ -33,28 +34,23 @@ self.stripecount = None self.repos_sorted = ('name', False) self._baseurl = None - if isinstance(config, (list, tuple)): - self.repos = cleannames(config) + if isinstance(conf, (list, tuple)): + self.repos = cleannames(conf) self.repos_sorted = ('', False) - elif isinstance(config, dict): - self.repos = util.sort(cleannames(config.items())) + elif isinstance(conf, dict): + self.repos = util.sort(cleannames(conf.items())) else: - if isinstance(config, util.configparser): - cp = config + if isinstance(conf, config.config): + cp = conf else: - cp = util.configparser() - cp.read(config) + cp = config.config() + cp.read(conf) self.repos = [] - if cp.has_section('web'): - if cp.has_option('web', 'motd'): - self.motd = cp.get('web', 'motd') - if cp.has_option('web', 'style'): - self.style = cp.get('web', 'style') - if cp.has_option('web', 'stripes'): - self.stripecount = int(cp.get('web', 'stripes')) - if cp.has_option('web', 'baseurl'): - self._baseurl = cp.get('web', 'baseurl') - if cp.has_section('paths'): + self.motd = cp.get('web', 'motd') + self.style = cp.get('web', 'style', 'paper') + self.stripecount = cp.get('web', 'stripes') + self._baseurl = cp.get('web', 'baseurl') + if 'paths' in cp: paths = cleannames(cp.items('paths')) for prefix, root in paths: roothead, roottail = os.path.split(root) @@ -75,14 +71,13 @@ if prefix: name = prefix + '/' + name self.repos.append((name, path)) - if cp.has_section('collections'): - for prefix, root in cp.items('collections'): - for path in util.walkrepos(root, followsym=True): - repo = os.path.normpath(path) - name = repo - if name.startswith(prefix): - name = name[len(prefix):] - self.repos.append((name.lstrip(os.sep), repo)) + for prefix, root in cp.items('collections'): + for path in util.walkrepos(root, followsym=True): + repo = os.path.normpath(path) + name = repo + if name.startswith(prefix): + name = name[len(prefix):] + self.repos.append((name.lstrip(os.sep), repo)) self.repos.sort() def run(self): @@ -320,8 +315,7 @@ style = config('web', 'style', '') if 'style' in req.form: style = req.form['style'][0] - if self.stripecount is None: - self.stripecount = int(config('web', 'stripes', 1)) + self.stripecount = int(self.stripecount or config('web', 'stripes', 1)) mapfile = templater.stylemap(style) tmpl = templater.templater(mapfile, templatefilters.filters, defaults={"header": header,