[PATCH 2 of 3] dispatch: add I/O streams to the request
Idan Kamara
idankk86 at gmail.com
Tue Jun 7 08:55:45 CDT 2011
# HG changeset patch
# User Idan Kamara <idankk86 at gmail.com>
# Date 1307443149 -10800
# Node ID f1a5454549e8878e05a3486c89e791a704345ca5
# Parent 717b9ae1694d3e125f865dc89743166533914240
dispatch: add I/O streams to the request
and assign them to the ui as early as possible.
diff -r 717b9ae1694d -r f1a5454549e8 mercurial/dispatch.py
--- a/mercurial/dispatch.py Tue Jun 07 13:39:09 2011 +0300
+++ b/mercurial/dispatch.py Tue Jun 07 13:39:09 2011 +0300
@@ -12,34 +12,55 @@
import ui as uimod
class request(object):
- def __init__(self, args, ui=None, repo=None):
+ def __init__(self, args, ui=None, repo=None, fin=None, fout=None, ferr=None):
self.args = args
self.ui = ui
self.repo = repo
+ # input/output/error streams
+ self.fin = fin
+ self.fout = fout
+ self.ferr = ferr
+
def run():
"run the command in sys.argv"
sys.exit(dispatch(request(sys.argv[1:])))
def dispatch(req):
"run the command specified in req.args"
+ if req.ferr:
+ ferr = req.ferr
+ elif req.ui:
+ ferr = req.ui.ferr
+ else:
+ ferr = sys.stderr
+
try:
if not req.ui:
req.ui = uimod.ui()
if '--traceback' in req.args:
req.ui.setconfig('ui', 'traceback', 'on')
+
+ # set ui streams from the request
+ if req.fin:
+ req.ui.fin = req.fin
+ if req.fout:
+ req.ui.fout = req.fout
+ if req.ferr:
+ req.ui.ferr = req.ferr
except util.Abort, inst:
- sys.stderr.write(_("abort: %s\n") % inst)
+ ferr.write(_("abort: %s\n") % inst)
if inst.hint:
- sys.stderr.write(_("(%s)\n") % inst.hint)
+ ferr.write(_("(%s)\n") % inst.hint)
return -1
except error.ParseError, inst:
if len(inst.args) > 1:
- sys.stderr.write(_("hg: parse error at %s: %s\n") %
+ ferr.write(_("hg: parse error at %s: %s\n") %
(inst.args[1], inst.args[0]))
else:
- sys.stderr.write(_("hg: parse error: %s\n") % inst.args[0])
+ ferr.write(_("hg: parse error: %s\n") % inst.args[0])
return -1
+
return _runcatch(req)
def _runcatch(req):
More information about the Mercurial-devel
mailing list