# HG changeset patch # User mpm@selenic.com # Date 1118270706 28800 # Node ID 5a1e6d27f3998708af924c601a1cd12e6fd386dd # Parent d7c2efd0b54135622d7eafb97f984e6ab3261825 ui: add configuration file support -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 ui: add configuration file support manifest hash: 2d0768a6f3797d4ccc870170b874bfd7aeb2f787 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCp3TyywK+sNU5EO8RArYYAJ4+wWQmO7HIXewuGwB3a5DjiWGHwgCcDpeF Pz2lScnpVZPPbDQiS+VnBnM= =ffwc -----END PGP SIGNATURE----- diff --git a/mercurial/ui.py b/mercurial/ui.py --- a/mercurial/ui.py +++ b/mercurial/ui.py @@ -5,15 +5,39 @@ # This software may be used and distributed according to the terms # of the GNU General Public License, incorporated herein by reference. -import os, sys, re +import os, sys, re, ConfigParser class ui: def __init__(self, verbose=False, debug=False, quiet=False, interactive=True): - self.quiet = quiet and not verbose and not debug - self.verbose = verbose or debug - self.debugflag = debug - self.interactive = interactive + self.cdata = ConfigParser.SafeConfigParser() + self.cdata.read(os.path.expanduser("~/.hgrc")) + + self.quiet = self.configbool("ui", "quiet") + self.verbose = self.configbool("ui", "verbose") + self.debugflag = self.configbool("ui", "debug") + self.interactive = self.configbool("ui", "interactive", True) + + self.quiet = (self.quiet or quiet) and not verbose and not debug + self.verbose = (self.verbose or verbose) or debug + self.debugflag = (self.debugflag or debug) + self.interactive = (self.interactive and interactive) + + def config(self, section, val, default=None): + if self.cdata.has_option(section, val): + return self.cdata.get(section, val) + return default + + def configbool(self, section, val, default=False): + if self.cdata.has_option(section, val): + return self.cdata.getboolean(section, val) + return default + + def configitems(self, section): + if self.cdata.has_section(section): + return self.cdata.items(section) + return [] + def write(self, *args): for a in args: sys.stdout.write(str(a))