comparison mercurial/ui.py @ 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 619e775aa7f9
children c3d873ef4b31 b2293093b89e
comparison
equal deleted inserted replaced
284:d7c2efd0b541 285:5a1e6d27f399
3 # Copyright 2005 Matt Mackall <mpm@selenic.com> 3 # Copyright 2005 Matt Mackall <mpm@selenic.com>
4 # 4 #
5 # This software may be used and distributed according to the terms 5 # This software may be used and distributed according to the terms
6 # of the GNU General Public License, incorporated herein by reference. 6 # of the GNU General Public License, incorporated herein by reference.
7 7
8 import os, sys, re 8 import os, sys, re, ConfigParser
9 9
10 class ui: 10 class ui:
11 def __init__(self, verbose=False, debug=False, quiet=False, 11 def __init__(self, verbose=False, debug=False, quiet=False,
12 interactive=True): 12 interactive=True):
13 self.quiet = quiet and not verbose and not debug 13 self.cdata = ConfigParser.SafeConfigParser()
14 self.verbose = verbose or debug 14 self.cdata.read(os.path.expanduser("~/.hgrc"))
15 self.debugflag = debug 15
16 self.interactive = interactive 16 self.quiet = self.configbool("ui", "quiet")
17 self.verbose = self.configbool("ui", "verbose")
18 self.debugflag = self.configbool("ui", "debug")
19 self.interactive = self.configbool("ui", "interactive", True)
20
21 self.quiet = (self.quiet or quiet) and not verbose and not debug
22 self.verbose = (self.verbose or verbose) or debug
23 self.debugflag = (self.debugflag or debug)
24 self.interactive = (self.interactive and interactive)
25
26 def config(self, section, val, default=None):
27 if self.cdata.has_option(section, val):
28 return self.cdata.get(section, val)
29 return default
30
31 def configbool(self, section, val, default=False):
32 if self.cdata.has_option(section, val):
33 return self.cdata.getboolean(section, val)
34 return default
35
36 def configitems(self, section):
37 if self.cdata.has_section(section):
38 return self.cdata.items(section)
39 return []
40
17 def write(self, *args): 41 def write(self, *args):
18 for a in args: 42 for a in args:
19 sys.stdout.write(str(a)) 43 sys.stdout.write(str(a))
20 def readline(self): 44 def readline(self):
21 return sys.stdin.readline()[:-1] 45 return sys.stdin.readline()[:-1]