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