##// END OF EJS Templates
ui: make interactive a method
Matt Mackall -
r8208:32a2a1e2 default
parent child Browse files
Show More
@@ -76,7 +76,7 b' from mercurial.i18n import _'
76 from mercurial.node import bin
76 from mercurial.node import bin
77
77
78 def prompt(ui, prompt, default=None, rest=': ', empty_ok=False):
78 def prompt(ui, prompt, default=None, rest=': ', empty_ok=False):
79 if not ui.interactive:
79 if not ui.interactive():
80 return default
80 return default
81 if default:
81 if default:
82 prompt += ' [%s]' % default
82 prompt += ' [%s]' % default
@@ -394,7 +394,7 b' def qrecord(ui, repo, patch, *pats, **op'
394
394
395
395
396 def dorecord(ui, repo, committer, *pats, **opts):
396 def dorecord(ui, repo, committer, *pats, **opts):
397 if not ui.interactive:
397 if not ui.interactive():
398 raise util.Abort(_('running non-interactively, use commit instead'))
398 raise util.Abort(_('running non-interactively, use commit instead'))
399
399
400 def recordfunc(ui, repo, message, match, opts):
400 def recordfunc(ui, repo, message, match, opts):
@@ -16,7 +16,7 b' class ui(object):'
16 def __init__(self, src=None):
16 def __init__(self, src=None):
17 self._buffers = []
17 self._buffers = []
18 self.quiet = self.verbose = self.debugflag = self._traceback = False
18 self.quiet = self.verbose = self.debugflag = self._traceback = False
19 self.interactive = self._reportuntrusted = True
19 self._reportuntrusted = True
20 self._ocfg = config.config() # overlay
20 self._ocfg = config.config() # overlay
21 self._tcfg = config.config() # trusted
21 self._tcfg = config.config() # trusted
22 self._ucfg = config.config() # untrusted
22 self._ucfg = config.config() # untrusted
@@ -37,18 +37,6 b' class ui(object):'
37 def copy(self):
37 def copy(self):
38 return ui(self)
38 return ui(self)
39
39
40 _isatty = None
41 def isatty(self):
42 if ui._isatty is None:
43 try:
44 ui._isatty = sys.stdin.isatty()
45 except AttributeError: # not a real file object
46 ui._isatty = False
47 except IOError:
48 # access to stdin is unsafe in a WSGI environment
49 ui._isatty = False
50 return ui._isatty
51
52 def _is_trusted(self, fp, f):
40 def _is_trusted(self, fp, f):
53 st = util.fstat(fp)
41 st = util.fstat(fp)
54 if util.isowner(fp, st):
42 if util.isowner(fp, st):
@@ -112,7 +100,6 b' class ui(object):'
112 if self.verbose and self.quiet:
100 if self.verbose and self.quiet:
113 self.quiet = self.verbose = False
101 self.quiet = self.verbose = False
114 self._reportuntrusted = self.configbool("ui", "report_untrusted", True)
102 self._reportuntrusted = self.configbool("ui", "report_untrusted", True)
115 self.interactive = self.configbool("ui", "interactive", self.isatty())
116 self._traceback = self.configbool('ui', 'traceback', False)
103 self._traceback = self.configbool('ui', 'traceback', False)
117
104
118 # update trust information
105 # update trust information
@@ -259,8 +246,11 b' class ui(object):'
259 try: sys.stderr.flush()
246 try: sys.stderr.flush()
260 except: pass
247 except: pass
261
248
249 def interactive(self):
250 return self.configbool("ui", "interactive") or sys.stdin.isatty()
251
262 def _readline(self, prompt=''):
252 def _readline(self, prompt=''):
263 if self.isatty():
253 if sys.stdin.isatty():
264 try:
254 try:
265 # magically add command line editing support, where
255 # magically add command line editing support, where
266 # available
256 # available
@@ -282,7 +272,7 b' class ui(object):'
282
272
283 If not interactive -- the default is returned
273 If not interactive -- the default is returned
284 """
274 """
285 if not self.interactive:
275 if not self.interactive():
286 self.note(msg, ' ', default, "\n")
276 self.note(msg, ' ', default, "\n")
287 return default
277 return default
288 while True:
278 while True:
@@ -298,7 +288,7 b' class ui(object):'
298 raise util.Abort(_('response expected'))
288 raise util.Abort(_('response expected'))
299
289
300 def getpass(self, prompt=None, default=None):
290 def getpass(self, prompt=None, default=None):
301 if not self.interactive: return default
291 if not self.interactive(): return default
302 try:
292 try:
303 return getpass.getpass(prompt or _('password: '))
293 return getpass.getpass(prompt or _('password: '))
304 except EOFError:
294 except EOFError:
@@ -107,7 +107,7 b' class passwordmgr(urllib2.HTTPPasswordMg'
107 if user and passwd:
107 if user and passwd:
108 return (user, passwd)
108 return (user, passwd)
109
109
110 if not self.ui.interactive:
110 if not self.ui.interactive():
111 raise util.Abort(_('http authorization required'))
111 raise util.Abort(_('http authorization required'))
112
112
113 self.ui.write(_("http authorization required\n"))
113 self.ui.write(_("http authorization required\n"))
General Comments 0
You need to be logged in to leave comments. Login now