changeset 285:5a1e6d27f399

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-----
author mpm@selenic.com
date Wed, 08 Jun 2005 14:45:06 -0800
parents d7c2efd0b541
children bd9d1e93f8d6
files mercurial/ui.py
diffstat 1 files changed, 29 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/ui.py	Wed Jun 08 14:44:32 2005 -0800
+++ b/mercurial/ui.py	Wed Jun 08 14:45:06 2005 -0800
@@ -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))