mercurial/ui.py
changeset 37120 a8a902d7176e
parent 37119 d4a2e0d5d042
child 37134 6890b7e991a4
equal deleted inserted replaced
37119:d4a2e0d5d042 37120:a8a902d7176e
   806             return user
   806             return user
   807         if user is None and self.configbool("ui", "askusername"):
   807         if user is None and self.configbool("ui", "askusername"):
   808             user = self.prompt(_("enter a commit username:"), default=None)
   808             user = self.prompt(_("enter a commit username:"), default=None)
   809         if user is None and not self.interactive():
   809         if user is None and not self.interactive():
   810             try:
   810             try:
   811                 user = '%s@%s' % (util.getuser(),
   811                 user = '%s@%s' % (procutil.getuser(),
   812                                   encoding.strtolocal(socket.getfqdn()))
   812                                   encoding.strtolocal(socket.getfqdn()))
   813                 self.warn(_("no username found, using '%s' instead\n") % user)
   813                 self.warn(_("no username found, using '%s' instead\n") % user)
   814             except KeyError:
   814             except KeyError:
   815                 pass
   815                 pass
   816         if not user:
   816         if not user:
   990                 (util.timer() - starttime) * 1000
   990                 (util.timer() - starttime) * 1000
   991 
   991 
   992     def _isatty(self, fh):
   992     def _isatty(self, fh):
   993         if self.configbool('ui', 'nontty'):
   993         if self.configbool('ui', 'nontty'):
   994             return False
   994             return False
   995         return util.isatty(fh)
   995         return procutil.isatty(fh)
   996 
   996 
   997     def disablepager(self):
   997     def disablepager(self):
   998         self._disablepager = True
   998         self._disablepager = True
   999 
   999 
  1000     def pager(self, command):
  1000     def pager(self, command):
  1086             # Window's built-in `more` cannot be invoked with shell=False, but
  1086             # Window's built-in `more` cannot be invoked with shell=False, but
  1087             # its `more.com` can.  Hide this implementation detail from the
  1087             # its `more.com` can.  Hide this implementation detail from the
  1088             # user so we can also get sane bad PAGER behavior.  MSYS has
  1088             # user so we can also get sane bad PAGER behavior.  MSYS has
  1089             # `more.exe`, so do a cmd.exe style resolution of the executable to
  1089             # `more.exe`, so do a cmd.exe style resolution of the executable to
  1090             # determine which one to use.
  1090             # determine which one to use.
  1091             fullcmd = util.findexe(command)
  1091             fullcmd = procutil.findexe(command)
  1092             if not fullcmd:
  1092             if not fullcmd:
  1093                 self.warn(_("missing pager command '%s', skipping pager\n")
  1093                 self.warn(_("missing pager command '%s', skipping pager\n")
  1094                           % command)
  1094                           % command)
  1095                 return False
  1095                 return False
  1096 
  1096 
  1097             command = fullcmd
  1097             command = fullcmd
  1098 
  1098 
  1099         try:
  1099         try:
  1100             pager = subprocess.Popen(
  1100             pager = subprocess.Popen(
  1101                 command, shell=shell, bufsize=-1,
  1101                 command, shell=shell, bufsize=-1,
  1102                 close_fds=util.closefds, stdin=subprocess.PIPE,
  1102                 close_fds=procutil.closefds, stdin=subprocess.PIPE,
  1103                 stdout=procutil.stdout, stderr=procutil.stderr,
  1103                 stdout=procutil.stdout, stderr=procutil.stderr,
  1104                 env=util.shellenviron(env))
  1104                 env=procutil.shellenviron(env))
  1105         except OSError as e:
  1105         except OSError as e:
  1106             if e.errno == errno.ENOENT and not shell:
  1106             if e.errno == errno.ENOENT and not shell:
  1107                 self.warn(_("missing pager command '%s', skipping pager\n")
  1107                 self.warn(_("missing pager command '%s', skipping pager\n")
  1108                           % command)
  1108                           % command)
  1109                 return False
  1109                 return False
  1275         # Replacing stdin/stdout temporarily is a hard problem on Python 3
  1275         # Replacing stdin/stdout temporarily is a hard problem on Python 3
  1276         # because they have to be text streams with *no buffering*. Instead,
  1276         # because they have to be text streams with *no buffering*. Instead,
  1277         # we use rawinput() only if call_readline() will be invoked by
  1277         # we use rawinput() only if call_readline() will be invoked by
  1278         # PyOS_Readline(), so no I/O will be made at Python layer.
  1278         # PyOS_Readline(), so no I/O will be made at Python layer.
  1279         usereadline = (self._isatty(self.fin) and self._isatty(self.fout)
  1279         usereadline = (self._isatty(self.fin) and self._isatty(self.fout)
  1280                        and util.isstdin(self.fin) and util.isstdout(self.fout))
  1280                        and procutil.isstdin(self.fin)
       
  1281                        and procutil.isstdout(self.fout))
  1281         if usereadline:
  1282         if usereadline:
  1282             try:
  1283             try:
  1283                 # magically add command line editing support, where
  1284                 # magically add command line editing support, where
  1284                 # available
  1285                 # available
  1285                 import readline
  1286                 import readline
  1502             out = self
  1503             out = self
  1503         with self.timeblockedsection(blockedtag):
  1504         with self.timeblockedsection(blockedtag):
  1504             rc = self._runsystem(cmd, environ=environ, cwd=cwd, out=out)
  1505             rc = self._runsystem(cmd, environ=environ, cwd=cwd, out=out)
  1505         if rc and onerr:
  1506         if rc and onerr:
  1506             errmsg = '%s %s' % (os.path.basename(cmd.split(None, 1)[0]),
  1507             errmsg = '%s %s' % (os.path.basename(cmd.split(None, 1)[0]),
  1507                                 util.explainexit(rc)[0])
  1508                                 procutil.explainexit(rc)[0])
  1508             if errprefix:
  1509             if errprefix:
  1509                 errmsg = '%s: %s' % (errprefix, errmsg)
  1510                 errmsg = '%s: %s' % (errprefix, errmsg)
  1510             raise onerr(errmsg)
  1511             raise onerr(errmsg)
  1511         return rc
  1512         return rc
  1512 
  1513 
  1513     def _runsystem(self, cmd, environ, cwd, out):
  1514     def _runsystem(self, cmd, environ, cwd, out):
  1514         """actually execute the given shell command (can be overridden by
  1515         """actually execute the given shell command (can be overridden by
  1515         extensions like chg)"""
  1516         extensions like chg)"""
  1516         return util.system(cmd, environ=environ, cwd=cwd, out=out)
  1517         return procutil.system(cmd, environ=environ, cwd=cwd, out=out)
  1517 
  1518 
  1518     def traceback(self, exc=None, force=False):
  1519     def traceback(self, exc=None, force=False):
  1519         '''print exception traceback if traceback printing enabled or forced.
  1520         '''print exception traceback if traceback printing enabled or forced.
  1520         only to call in exception handler. returns true if traceback
  1521         only to call in exception handler. returns true if traceback
  1521         printed.'''
  1522         printed.'''