Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/util.py @ 1609:c50bddfbc812
eliminate backtrace when piping output on windows.
this fixes issue 54.
author | Vadim Gelfer <vadim.gelfer@gmail.com> |
---|---|
date | Mon, 02 Jan 2006 15:25:33 -0800 |
parents | a329e0fda2ae |
children | 84e9b3484ff6 |
comparison
equal
deleted
inserted
replaced
1608:722fd16f6f8c | 1609:c50bddfbc812 |
---|---|
11 """ | 11 """ |
12 | 12 |
13 import os, errno | 13 import os, errno |
14 from i18n import gettext as _ | 14 from i18n import gettext as _ |
15 from demandload import * | 15 from demandload import * |
16 demandload(globals(), "re cStringIO shutil popen2 sys tempfile threading time") | 16 demandload(globals(), "cStringIO errno popen2 re shutil sys tempfile") |
17 demandload(globals(), "threading time") | |
17 | 18 |
18 def pipefilter(s, cmd): | 19 def pipefilter(s, cmd): |
19 '''filter string S through command CMD, returning its output''' | 20 '''filter string S through command CMD, returning its output''' |
20 (pout, pin) = popen2.popen2(cmd, -1, 'b') | 21 (pout, pin) = popen2.popen2(cmd, -1, 'b') |
21 def writer(): | 22 def writer(): |
440 | 441 |
441 # Platform specific variants | 442 # Platform specific variants |
442 if os.name == 'nt': | 443 if os.name == 'nt': |
443 demandload(globals(), "msvcrt") | 444 demandload(globals(), "msvcrt") |
444 nulldev = 'NUL:' | 445 nulldev = 'NUL:' |
445 | 446 |
447 class winstdout: | |
448 '''stdout on windows misbehaves if sent through a pipe''' | |
449 | |
450 def __init__(self, fp): | |
451 self.fp = fp | |
452 | |
453 def __getattr__(self, key): | |
454 return getattr(self.fp, key) | |
455 | |
456 def close(self): | |
457 try: | |
458 self.fp.close() | |
459 except: pass | |
460 | |
461 def write(self, s): | |
462 try: | |
463 return self.fp.write(s) | |
464 except IOError, inst: | |
465 if inst.errno != 0: raise | |
466 self.close() | |
467 raise IOError(errno.EPIPE, 'Broken pipe') | |
468 | |
469 sys.stdout = winstdout(sys.stdout) | |
470 | |
446 try: | 471 try: |
447 import win32api, win32process | 472 import win32api, win32process |
448 filename = win32process.GetModuleFileNameEx(win32api.GetCurrentProcess(), 0) | 473 filename = win32process.GetModuleFileNameEx(win32api.GetCurrentProcess(), 0) |
449 systemrc = os.path.join(os.path.dirname(filename), 'mercurial.ini') | 474 systemrc = os.path.join(os.path.dirname(filename), 'mercurial.ini') |
450 | 475 |
451 except ImportError: | 476 except ImportError: |
452 systemrc = r'c:\mercurial\mercurial.ini' | 477 systemrc = r'c:\mercurial\mercurial.ini' |
453 pass | 478 pass |
454 | 479 |
455 rcpath = (systemrc, | 480 rcpath = (systemrc, |