Mercurial > hg > hgforest
changeset 99:9e722e8d001d
Replace ConfigParser with mercurial.config when available
Mercurial >= 1.3 no longer uses ConfigParser, so the module is no longer
shipped by Windows py2exe binaries, which means forest no longer works with
them. Use mercurial.config instead.
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Sun, 04 Oct 2009 16:31:31 +0200 |
parents | f5441510cbb0 |
children | 90f5bf44cf59 c63f0686c3b9 |
files | forest.py |
diffstat | 1 files changed, 27 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/forest.py Sun Oct 04 16:21:00 2009 +0200 +++ b/forest.py Sun Oct 04 16:31:31 2009 +0200 @@ -49,7 +49,6 @@ """ -import ConfigParser import errno import os import re @@ -109,16 +108,34 @@ if not hasattr(hgweb, 'protocol'): hgweb.protocol = hgweb.hgweb_mod.hgweb -ConfigError = ConfigParser.Error - -class SnapshotError(ConfigParser.NoSectionError): - pass +# There are no issues with backward compatibility and ConfigParser. +# But since it was replaced in mercurial >= 1.3, the module is not +# longer shipped by Windows binary packages. In this case, use +# mercurial.config instead. +try: + from mercurial import config + ConfigError = error.ConfigError -def readconfig(path): - cfg = ConfigParser.RawConfigParser() - if not cfg.read([path]): - return None - return cfg + def readconfig(path): + cfg = config.config() + try: + cfg.read(path) + return cfg + except IOError: + return None + +except (ImportError, AttributeError): + import ConfigParser + ConfigError = ConfigParser.Error + + def readconfig(path): + cfg = ConfigParser.RawConfigParser() + if not cfg.read([path]): + return None + return cfg + +class SnapshotError(ConfigError): + pass def cmd_options(ui, cmd, remove=None, table=commands.table): aliases, spec = findcmd(ui, cmd, table)