Mercurial > public > mercurial-scm > hg
comparison mercurial/dispatch.py @ 14615:9fba795dd030
dispatch: assign I/O descriptors from the request to the ui
author | Idan Kamara <idankk86@gmail.com> |
---|---|
date | Wed, 08 Jun 2011 14:54:47 +0300 |
parents | ea8938d3a5aa |
children | 110d75f0abb3 |
comparison
equal
deleted
inserted
replaced
14614:afccc64eea73 | 14615:9fba795dd030 |
---|---|
26 "run the command in sys.argv" | 26 "run the command in sys.argv" |
27 sys.exit(dispatch(request(sys.argv[1:]))) | 27 sys.exit(dispatch(request(sys.argv[1:]))) |
28 | 28 |
29 def dispatch(req): | 29 def dispatch(req): |
30 "run the command specified in req.args" | 30 "run the command specified in req.args" |
31 if req.ferr: | |
32 ferr = req.ferr | |
33 elif req.ui: | |
34 ferr = req.ui.ferr | |
35 else: | |
36 ferr = sys.stderr | |
37 | |
31 try: | 38 try: |
32 if not req.ui: | 39 if not req.ui: |
33 req.ui = uimod.ui() | 40 req.ui = uimod.ui() |
34 if '--traceback' in req.args: | 41 if '--traceback' in req.args: |
35 req.ui.setconfig('ui', 'traceback', 'on') | 42 req.ui.setconfig('ui', 'traceback', 'on') |
43 | |
44 # set ui streams from the request | |
45 if req.fin: | |
46 req.ui.fin = req.fin | |
47 if req.fout: | |
48 req.ui.fout = req.fout | |
49 if req.ferr: | |
50 req.ui.ferr = req.ferr | |
36 except util.Abort, inst: | 51 except util.Abort, inst: |
37 sys.stderr.write(_("abort: %s\n") % inst) | 52 ferr.write(_("abort: %s\n") % inst) |
38 if inst.hint: | 53 if inst.hint: |
39 sys.stderr.write(_("(%s)\n") % inst.hint) | 54 ferr.write(_("(%s)\n") % inst.hint) |
40 return -1 | 55 return -1 |
41 except error.ParseError, inst: | 56 except error.ParseError, inst: |
42 if len(inst.args) > 1: | 57 if len(inst.args) > 1: |
43 sys.stderr.write(_("hg: parse error at %s: %s\n") % | 58 ferr.write(_("hg: parse error at %s: %s\n") % |
44 (inst.args[1], inst.args[0])) | 59 (inst.args[1], inst.args[0])) |
45 else: | 60 else: |
46 sys.stderr.write(_("hg: parse error: %s\n") % inst.args[0]) | 61 ferr.write(_("hg: parse error: %s\n") % inst.args[0]) |
47 return -1 | 62 return -1 |
63 | |
48 return _runcatch(req) | 64 return _runcatch(req) |
49 | 65 |
50 def _runcatch(req): | 66 def _runcatch(req): |
51 def catchterm(*args): | 67 def catchterm(*args): |
52 raise error.SignalInterrupt | 68 raise error.SignalInterrupt |