Mercurial > hg
changeset 1882:c0320567931f
merge util.esystem and util.system.
author | Vadim Gelfer <vadim.gelfer@gmail.com> |
---|---|
date | Fri, 10 Mar 2006 22:42:59 -0800 |
parents | 05c7d75be925 |
children | b98160cfb2f3 |
files | mercurial/localrepo.py mercurial/ui.py mercurial/util.py |
diffstat | 3 files changed, 21 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/localrepo.py Fri Mar 10 22:24:19 2006 -0800 +++ b/mercurial/localrepo.py Fri Mar 10 22:42:59 2006 -0800 @@ -55,7 +55,7 @@ def runhook(name, cmd): self.ui.note(_("running hook %s: %s\n") % (name, cmd)) env = dict([('HG_' + k.upper(), v) for k, v in args.iteritems()]) - r = util.esystem(cmd, environ=env, cwd=self.root) + r = util.system(cmd, environ=env, cwd=self.root) if r: desc, r = util.explain_exit(r) if throw:
--- a/mercurial/ui.py Fri Mar 10 22:24:19 2006 -0800 +++ b/mercurial/ui.py Fri Mar 10 22:42:59 2006 -0800 @@ -209,7 +209,9 @@ os.environ.get("EDITOR", "vi")) os.environ["HGUSER"] = self.username() - util.system("%s \"%s\"" % (editor, name), errprefix=_("edit failed")) + util.system("%s \"%s\"" % (editor, name), + environ={'HGUSER': self.username()}, + onerr=util.Abort, errprefix=_("edit failed")) t = open(name).read() t = re.sub("(?m)^HG:.*\n", "", t)
--- a/mercurial/util.py Fri Mar 10 22:24:19 2006 -0800 +++ b/mercurial/util.py Fri Mar 10 22:42:59 2006 -0800 @@ -315,19 +315,13 @@ (files and filematch(fn)))), (inc or exc or (pats and pats != [('glob', '**')])) and True) -def system(cmd, errprefix=None): - """execute a shell command that must succeed""" - rc = os.system(cmd) - if rc: - errmsg = "%s %s" % (os.path.basename(cmd.split(None, 1)[0]), - explain_exit(rc)[0]) - if errprefix: - errmsg = "%s: %s" % (errprefix, errmsg) - raise Abort(errmsg) +def system(cmd, environ={}, cwd=None, onerr=None, errprefix=None): + '''enhanced shell command execution. + run with environment maybe modified, maybe in different dir. -def esystem(cmd, environ={}, cwd=None): - '''enhanced shell command execution. - run with environment maybe modified, maybe in different dir.''' + if command fails and onerr is None, return status. if ui object, + print error message and return status, else raise onerr object as + exception.''' oldenv = {} for k in environ: oldenv[k] = os.environ.get(k) @@ -338,7 +332,17 @@ os.environ[k] = str(v) if cwd is not None and oldcwd != cwd: os.chdir(cwd) - return os.system(cmd) + rc = os.system(cmd) + if rc and onerr: + errmsg = '%s %s' % (os.path.basename(cmd.split(None, 1)[0]), + explain_exit(rc)[0]) + if errprefix: + errmsg = '%s: %s' % (errprefix, errmsg) + try: + onerr.warn(errmsg + '\n') + except AttributeError: + raise onerr(errmsg) + return rc finally: for k, v in oldenv.iteritems(): if v is None: