##// END OF EJS Templates
ui: refactor option setting...
Matt Mackall -
r8136:6b5522cb default
parent child Browse files
Show More
@@ -18,7 +18,9 b' def run():'
18 def dispatch(args):
18 def dispatch(args):
19 "run the command specified in args"
19 "run the command specified in args"
20 try:
20 try:
21 u = _ui.ui(traceback='--traceback' in args)
21 u = _ui.ui()
22 if '--traceback' in args:
23 u.setconfig('ui', 'traceback', 'on')
22 except util.Abort, inst:
24 except util.Abort, inst:
23 sys.stderr.write(_("abort: %s\n") % inst)
25 sys.stderr.write(_("abort: %s\n") % inst)
24 return -1
26 return -1
@@ -256,7 +258,7 b' def _dispatch(ui, args):'
256 # (e.g. to change trust settings for reading .hg/hgrc)
258 # (e.g. to change trust settings for reading .hg/hgrc)
257 config = _earlygetopt(['--config'], args)
259 config = _earlygetopt(['--config'], args)
258 if config:
260 if config:
259 ui.updateopts(config=_parseconfig(config))
261 ui.updateopts(_parseconfig(config))
260
262
261 # check for cwd
263 # check for cwd
262 cwd = _earlygetopt(['--cwd'], args)
264 cwd = _earlygetopt(['--cwd'], args)
@@ -335,8 +337,14 b' def _dispatch(ui, args):'
335 (t[4]-s[4], t[0]-s[0], t[2]-s[2], t[1]-s[1], t[3]-s[3]))
337 (t[4]-s[4], t[0]-s[0], t[2]-s[2], t[1]-s[1], t[3]-s[3]))
336 atexit.register(print_time)
338 atexit.register(print_time)
337
339
338 ui.updateopts(options["verbose"], options["debug"], options["quiet"],
340 if options['verbose'] or options['debug'] or options['quiet']:
339 not options["noninteractive"], options["traceback"])
341 ui.setconfig('ui', 'verbose', str(bool(options['verbose'])))
342 ui.setconfig('ui', 'debug', str(bool(options['debug'])))
343 ui.setconfig('ui', 'quiet', str(bool(options['quiet'])))
344 if options['traceback']:
345 ui.setconfig('ui', 'traceback', 'on')
346 if options['noninteractive']:
347 ui.setconfig('ui', 'interactive', 'off')
340
348
341 if options['help']:
349 if options['help']:
342 return commands.help_(ui, cmd, options['version'])
350 return commands.help_(ui, cmd, options['version'])
@@ -25,7 +25,9 b' perms = {'
25 class hgweb(object):
25 class hgweb(object):
26 def __init__(self, repo, name=None):
26 def __init__(self, repo, name=None):
27 if isinstance(repo, str):
27 if isinstance(repo, str):
28 parentui = ui.ui(report_untrusted=False, interactive=False)
28 parentui = ui.ui()
29 parentui.setconfig('ui', 'report_untrusted', 'off')
30 parentui.setconfig('ui', 'interactive', 'off')
29 self.repo = hg.repository(parentui, repo)
31 self.repo = hg.repository(parentui, repo)
30 else:
32 else:
31 self.repo = repo
33 self.repo = repo
@@ -21,8 +21,13 b' class hgwebdir(object):'
21 return [(util.pconvert(name).strip('/'), path)
21 return [(util.pconvert(name).strip('/'), path)
22 for name, path in items]
22 for name, path in items]
23
23
24 self.parentui = parentui or ui.ui(report_untrusted=False,
24 if parentui:
25 interactive = False)
25 self.parentui = parentui
26 else:
27 self.parentui = ui.ui()
28 self.parentui.setconfig('ui', 'report_untrusted', 'off')
29 self.parentui.setconfig('ui', 'interactive', 'off')
30
26 self.motd = None
31 self.motd = None
27 self.style = 'paper'
32 self.style = 'paper'
28 self.stripecount = None
33 self.stripecount = None
@@ -24,19 +24,14 b' def updateconfig(source, dest, sections='
24 dest.set(section, name, value)
24 dest.set(section, name, value)
25
25
26 class ui(object):
26 class ui(object):
27 def __init__(self, verbose=False, debug=False, quiet=False,
27 def __init__(self, parentui=None):
28 interactive=True, traceback=False, report_untrusted=True,
29 parentui=None):
30 self.buffers = []
28 self.buffers = []
29 self.quiet = self.verbose = self.debugflag = self.traceback = False
30 self.interactive = self.report_untrusted = True
31
31 if parentui is None:
32 if parentui is None:
32 # this is the parent of all ui children
33 # this is the parent of all ui children
33 self.parentui = None
34 self.parentui = None
34 self.quiet = quiet
35 self.verbose = verbose
36 self.debugflag = debug
37 self.interactive = interactive
38 self.traceback = traceback
39 self.report_untrusted = report_untrusted
40 self.trusted_users = {}
35 self.trusted_users = {}
41 self.trusted_groups = {}
36 self.trusted_groups = {}
42 self.overlay = util.configparser()
37 self.overlay = util.configparser()
@@ -45,7 +40,6 b' class ui(object):'
45 self.ucdata = None
40 self.ucdata = None
46 # we always trust global config files
41 # we always trust global config files
47 self.readconfig(util.rcpath(), assumetrusted=True)
42 self.readconfig(util.rcpath(), assumetrusted=True)
48 self.updateopts(verbose, debug, quiet, interactive)
49 else:
43 else:
50 # parentui may point to an ui object which is already a child
44 # parentui may point to an ui object which is already a child
51 self.parentui = parentui.parentui or parentui
45 self.parentui = parentui.parentui or parentui
@@ -66,25 +60,16 b' class ui(object):'
66 _isatty = None
60 _isatty = None
67 def isatty(self):
61 def isatty(self):
68 if ui._isatty is None:
62 if ui._isatty is None:
69 ui._isatty = sys.stdin.isatty()
63 try:
64 ui._isatty = sys.stdin.isatty()
65 except AttributeError: # not a real file object
66 ui._isatty = False
70 return ui._isatty
67 return ui._isatty
71
68
72 def updateopts(self, verbose=False, debug=False, quiet=False,
69 def updateopts(self, config):
73 interactive=True, traceback=False, config=[]):
74 for section, name, value in config:
70 for section, name, value in config:
75 self.setconfig(section, name, value)
71 self.setconfig(section, name, value)
76
72
77 if quiet or verbose or debug:
78 self.setconfig('ui', 'quiet', str(bool(quiet)))
79 self.setconfig('ui', 'verbose', str(bool(verbose)))
80 self.setconfig('ui', 'debug', str(bool(debug)))
81
82 if not interactive:
83 self.setconfig('ui', 'interactive', 'False')
84 self.interactive = False
85
86 self.traceback = self.traceback or traceback
87
88 def verbosity_constraints(self):
73 def verbosity_constraints(self):
89 self.quiet = self.configbool('ui', 'quiet')
74 self.quiet = self.configbool('ui', 'quiet')
90 self.verbose = self.configbool('ui', 'verbose')
75 self.verbose = self.configbool('ui', 'verbose')
@@ -215,6 +200,7 b' class ui(object):'
215 if name is None or name == 'report_untrusted':
200 if name is None or name == 'report_untrusted':
216 self.report_untrusted = (
201 self.report_untrusted = (
217 self.configbool("ui", "report_untrusted", True))
202 self.configbool("ui", "report_untrusted", True))
203 self.traceback = self.configbool('ui', 'traceback', False)
218
204
219 # update trust information
205 # update trust information
220 if (section is None or section == 'trusted') and self.trusted_users:
206 if (section is None or section == 'trusted') and self.trusted_users:
@@ -30,9 +30,6 b' class FileLike(object):'
30 def readline(self):
30 def readline(self):
31 print >> sys.__stdout__, 'READLINE'
31 print >> sys.__stdout__, 'READLINE'
32 return self.real.readline()
32 return self.real.readline()
33 def isatty(self):
34 print >> sys.__stdout__, 'ISATTY'
35 return False
36
33
37 sys.stdin = FileLike(sys.stdin)
34 sys.stdin = FileLike(sys.stdin)
38 errors = StringIO()
35 errors = StringIO()
@@ -60,7 +60,7 b" def testui(user='foo', group='bar', tuse"
60 trusted)
60 trusted)
61
61
62 parentui = ui.ui()
62 parentui = ui.ui()
63 parentui.updateopts(debug=debug)
63 parentui.setconfig('ui', 'debug', str(bool(debug)))
64 u = ui.ui(parentui=parentui)
64 u = ui.ui(parentui=parentui)
65 u.readconfig('.hg/hgrc')
65 u.readconfig('.hg/hgrc')
66 if silent:
66 if silent:
@@ -145,7 +145,7 b" print u.config('foobar', 'baz')"
145 print
145 print
146 print "# read trusted, untrusted, new ui, trusted"
146 print "# read trusted, untrusted, new ui, trusted"
147 u = ui.ui()
147 u = ui.ui()
148 u.updateopts(debug=True)
148 u.setconfig('ui', 'debug', 'on')
149 u.readconfig(filename)
149 u.readconfig(filename)
150 u2 = ui.ui(parentui=u)
150 u2 = ui.ui(parentui=u)
151 def username(uid=None):
151 def username(uid=None):
@@ -31,7 +31,10 b' for i in xrange(64):'
31 f.close()
31 f.close()
32
32
33 u = ui.ui()
33 u = ui.ui()
34 u.updateopts(quiet=cmd_quiet, verbose=cmd_verbose, debug=cmd_debug)
34 if cmd_quiet or cmd_debug or cmd_verbose:
35 u.setconfig('ui', 'quiet', str(bool(cmd_quiet)))
36 u.setconfig('ui', 'verbose', str(bool(cmd_verbose)))
37 u.setconfig('ui', 'debug', str(bool(cmd_debug)))
35
38
36 check = ''
39 check = ''
37 if u.debugflag:
40 if u.debugflag:
General Comments 0
You need to be logged in to leave comments. Login now