Mercurial > public > mercurial-scm > hg
comparison mercurial/ui.py @ 31108:3f8f53190d6a
chg: deduplicate error handling of ui.system()
This moves 'onerr' handling from low-level util.system() to higher level,
which seems better API separation.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 19 Feb 2017 01:16:45 +0900 |
parents | fbce78c58f1e |
children | 268caf97c38f |
comparison
equal
deleted
inserted
replaced
31107:fbce78c58f1e | 31108:3f8f53190d6a |
---|---|
1279 | 1279 |
1280 def system(self, cmd, environ=None, cwd=None, onerr=None, errprefix=None, | 1280 def system(self, cmd, environ=None, cwd=None, onerr=None, errprefix=None, |
1281 blockedtag=None): | 1281 blockedtag=None): |
1282 '''execute shell command with appropriate output stream. command | 1282 '''execute shell command with appropriate output stream. command |
1283 output will be redirected if fout is not stdout. | 1283 output will be redirected if fout is not stdout. |
1284 | |
1285 if command fails and onerr is None, return status, else raise onerr | |
1286 object as exception. | |
1284 ''' | 1287 ''' |
1285 if blockedtag is None: | 1288 if blockedtag is None: |
1286 blockedtag = 'unknown_system_' + cmd.translate(None, _keepalnum) | 1289 blockedtag = 'unknown_system_' + cmd.translate(None, _keepalnum) |
1287 out = self.fout | 1290 out = self.fout |
1288 if any(s[1] for s in self._bufferstates): | 1291 if any(s[1] for s in self._bufferstates): |
1289 out = self | 1292 out = self |
1290 with self.timeblockedsection(blockedtag): | 1293 with self.timeblockedsection(blockedtag): |
1291 return self._runsystem(cmd, environ=environ, cwd=cwd, onerr=onerr, | 1294 rc = self._runsystem(cmd, environ=environ, cwd=cwd, out=out) |
1292 errprefix=errprefix, out=out) | 1295 if rc and onerr: |
1293 | 1296 errmsg = '%s %s' % (os.path.basename(cmd.split(None, 1)[0]), |
1294 def _runsystem(self, cmd, environ, cwd, onerr, errprefix, out): | 1297 util.explainexit(rc)[0]) |
1298 if errprefix: | |
1299 errmsg = '%s: %s' % (errprefix, errmsg) | |
1300 raise onerr(errmsg) | |
1301 return rc | |
1302 | |
1303 def _runsystem(self, cmd, environ, cwd, out): | |
1295 """actually execute the given shell command (can be overridden by | 1304 """actually execute the given shell command (can be overridden by |
1296 extensions like chg)""" | 1305 extensions like chg)""" |
1297 return util.system(cmd, environ=environ, cwd=cwd, onerr=onerr, | 1306 return util.system(cmd, environ=environ, cwd=cwd, out=out) |
1298 errprefix=errprefix, out=out) | |
1299 | 1307 |
1300 def traceback(self, exc=None, force=False): | 1308 def traceback(self, exc=None, force=False): |
1301 '''print exception traceback if traceback printing enabled or forced. | 1309 '''print exception traceback if traceback printing enabled or forced. |
1302 only to call in exception handler. returns true if traceback | 1310 only to call in exception handler. returns true if traceback |
1303 printed.''' | 1311 printed.''' |