Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/util.py @ 26450:1138e1d05207
util.system: compare fileno to see if it needs stdout redirection
Future patches will reopen stdout to be line-buffered, so sys.stdout may
be different object than sys.__stdout__.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 03 Oct 2015 14:57:24 +0900 |
parents | 127b59787fd5 |
children | a3f7e5461dbd |
comparison
equal
deleted
inserted
replaced
26449:89b7a7883aee | 26450:1138e1d05207 |
---|---|
728 def _sethgexecutable(path): | 728 def _sethgexecutable(path): |
729 """set location of the 'hg' executable""" | 729 """set location of the 'hg' executable""" |
730 global _hgexecutable | 730 global _hgexecutable |
731 _hgexecutable = path | 731 _hgexecutable = path |
732 | 732 |
733 def _isstdout(f): | |
734 fileno = getattr(f, 'fileno', None) | |
735 return fileno and fileno() == sys.__stdout__.fileno() | |
736 | |
733 def system(cmd, environ=None, cwd=None, onerr=None, errprefix=None, out=None): | 737 def system(cmd, environ=None, cwd=None, onerr=None, errprefix=None, out=None): |
734 '''enhanced shell command execution. | 738 '''enhanced shell command execution. |
735 run with environment maybe modified, maybe in different dir. | 739 run with environment maybe modified, maybe in different dir. |
736 | 740 |
737 if command fails and onerr is None, return status, else raise onerr | 741 if command fails and onerr is None, return status, else raise onerr |
763 rc = os.system(cmd) | 767 rc = os.system(cmd) |
764 else: | 768 else: |
765 env = dict(os.environ) | 769 env = dict(os.environ) |
766 env.update((k, py2shell(v)) for k, v in environ.iteritems()) | 770 env.update((k, py2shell(v)) for k, v in environ.iteritems()) |
767 env['HG'] = hgexecutable() | 771 env['HG'] = hgexecutable() |
768 if out is None or out == sys.__stdout__: | 772 if out is None or _isstdout(out): |
769 rc = subprocess.call(cmd, shell=True, close_fds=closefds, | 773 rc = subprocess.call(cmd, shell=True, close_fds=closefds, |
770 env=env, cwd=cwd) | 774 env=env, cwd=cwd) |
771 else: | 775 else: |
772 proc = subprocess.Popen(cmd, shell=True, close_fds=closefds, | 776 proc = subprocess.Popen(cmd, shell=True, close_fds=closefds, |
773 env=env, cwd=cwd, stdout=subprocess.PIPE, | 777 env=env, cwd=cwd, stdout=subprocess.PIPE, |