##// END OF EJS Templates
ui: add configuration file support...
mpm@selenic.com -
r285:5a1e6d27 default
parent child Browse files
Show More
@@ -5,15 +5,39 b''
5 5 # This software may be used and distributed according to the terms
6 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 10 class ui:
11 11 def __init__(self, verbose=False, debug=False, quiet=False,
12 12 interactive=True):
13 self.quiet = quiet and not verbose and not debug
14 self.verbose = verbose or debug
15 self.debugflag = debug
16 self.interactive = interactive
13 self.cdata = ConfigParser.SafeConfigParser()
14 self.cdata.read(os.path.expanduser("~/.hgrc"))
15
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 41 def write(self, *args):
18 42 for a in args:
19 43 sys.stdout.write(str(a))
General Comments 0
You need to be logged in to leave comments. Login now