Mercurial > hg-stable
changeset 3433:5ee5a0fec904
add ui.readsections
Given a file name and a set of sections, this function reads the file
and adds only the specified sections to the configuration data.
author | Alexis S. L. Carvalho <alexis@cecm.usp.br> |
---|---|
date | Tue, 17 Oct 2006 16:59:24 -0300 |
parents | 2300632a3bc8 |
children | bf10cd8bc981 |
files | mercurial/ui.py |
diffstat | 1 files changed, 21 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/ui.py Tue Oct 17 11:01:10 2006 -0700 +++ b/mercurial/ui.py Tue Oct 17 16:59:24 2006 -0300 @@ -15,8 +15,10 @@ updateconfig(orig, new) return new -def updateconfig(source, dest): - for section in source.sections(): +def updateconfig(source, dest, sections=None): + if not sections: + sections = source.sections() + for section in sections: if not dest.has_section(section): dest.add_section(section) for name, value in source.items(section, raw=True): @@ -100,6 +102,23 @@ def addreadhook(self, hook): self.readhooks.append(hook) + def readsections(self, filename, *sections): + "read filename and add only the specified sections to the config data" + if not sections: + return + + cdata = util.configparser() + try: + cdata.read(filename) + except ConfigParser.ParsingError, inst: + raise util.Abort(_("failed to parse %s\n%s") % (f, inst)) + + for section in sections: + if not cdata.has_section(section): + cdata.add_section(section) + + updateconfig(cdata, self.cdata, sections) + def fixconfig(self, section=None, name=None, value=None, root=None): # translate paths relative to root (or home) into absolute paths if section is None or section == 'paths':