Mercurial > hg
comparison mercurial/utils/procutil.py @ 37463:bbd240f81ac5
procutil: make explainexit() simply return a message (API)
Almost all callers want it.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 07 Apr 2018 21:23:42 +0900 |
parents | c0d0fd87ba7c |
children | 632b92899203 |
comparison
equal
deleted
inserted
replaced
37462:c0d0fd87ba7c | 37463:bbd240f81ac5 |
---|---|
77 pass | 77 pass |
78 | 78 |
79 closefds = pycompat.isposix | 79 closefds = pycompat.isposix |
80 | 80 |
81 def explainexit(code): | 81 def explainexit(code): |
82 """return a 2-tuple (desc, code) describing a subprocess status | 82 """return a message describing a subprocess status |
83 (codes from kill are negative - not os.system/wait encoding)""" | 83 (codes from kill are negative - not os.system/wait encoding)""" |
84 if code >= 0: | 84 if code >= 0: |
85 return _("exited with status %d") % code, code | 85 return _("exited with status %d") % code |
86 return _("killed by signal %d") % -code, code | 86 return _("killed by signal %d") % -code |
87 | 87 |
88 class _pfile(object): | 88 class _pfile(object): |
89 """File-like wrapper for a stream opened by subprocess.Popen()""" | 89 """File-like wrapper for a stream opened by subprocess.Popen()""" |
90 | 90 |
91 def __init__(self, proc, fp): | 91 def __init__(self, proc, fp): |
177 code = system(cmd) | 177 code = system(cmd) |
178 if pycompat.sysplatform == 'OpenVMS' and code & 1: | 178 if pycompat.sysplatform == 'OpenVMS' and code & 1: |
179 code = 0 | 179 code = 0 |
180 if code: | 180 if code: |
181 raise error.Abort(_("command '%s' failed: %s") % | 181 raise error.Abort(_("command '%s' failed: %s") % |
182 (cmd, explainexit(code)[0])) | 182 (cmd, explainexit(code))) |
183 with open(outname, 'rb') as fp: | 183 with open(outname, 'rb') as fp: |
184 return fp.read() | 184 return fp.read() |
185 finally: | 185 finally: |
186 try: | 186 try: |
187 if inname: | 187 if inname: |