Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/dispatch.py @ 14438:08bfec2ef031
dispatch: wrap dispatch related information in a request class
currently only stores the arguments.
author | Idan Kamara <idankk86@gmail.com> |
---|---|
date | Thu, 26 May 2011 00:44:11 +0300 |
parents | 005a540e9aee |
children | 80c599eee3f3 |
comparison
equal
deleted
inserted
replaced
14437:cbe13e6bdc34 | 14438:08bfec2ef031 |
---|---|
9 import os, sys, atexit, signal, pdb, socket, errno, shlex, time, traceback, re | 9 import os, sys, atexit, signal, pdb, socket, errno, shlex, time, traceback, re |
10 import util, commands, hg, fancyopts, extensions, hook, error | 10 import util, commands, hg, fancyopts, extensions, hook, error |
11 import cmdutil, encoding | 11 import cmdutil, encoding |
12 import ui as uimod | 12 import ui as uimod |
13 | 13 |
14 class request(object): | |
15 def __init__(self, args): | |
16 self.args = args | |
17 | |
14 def run(): | 18 def run(): |
15 "run the command in sys.argv" | 19 "run the command in sys.argv" |
16 sys.exit(dispatch(sys.argv[1:])) | 20 sys.exit(dispatch(request(sys.argv[1:]))) |
17 | 21 |
18 def dispatch(args): | 22 def dispatch(req): |
19 "run the command specified in args" | 23 "run the command specified in req.args" |
20 try: | 24 try: |
21 u = uimod.ui() | 25 u = uimod.ui() |
22 if '--traceback' in args: | 26 if '--traceback' in req.args: |
23 u.setconfig('ui', 'traceback', 'on') | 27 u.setconfig('ui', 'traceback', 'on') |
24 except util.Abort, inst: | 28 except util.Abort, inst: |
25 sys.stderr.write(_("abort: %s\n") % inst) | 29 sys.stderr.write(_("abort: %s\n") % inst) |
26 if inst.hint: | 30 if inst.hint: |
27 sys.stderr.write(_("(%s)\n") % inst.hint) | 31 sys.stderr.write(_("(%s)\n") % inst.hint) |
31 sys.stderr.write(_("hg: parse error at %s: %s\n") % | 35 sys.stderr.write(_("hg: parse error at %s: %s\n") % |
32 (inst.args[1], inst.args[0])) | 36 (inst.args[1], inst.args[0])) |
33 else: | 37 else: |
34 sys.stderr.write(_("hg: parse error: %s\n") % inst.args[0]) | 38 sys.stderr.write(_("hg: parse error: %s\n") % inst.args[0]) |
35 return -1 | 39 return -1 |
36 return _runcatch(u, args) | 40 return _runcatch(u, req) |
37 | 41 |
38 def _runcatch(ui, args): | 42 def _runcatch(ui, req): |
39 def catchterm(*args): | 43 def catchterm(*args): |
40 raise error.SignalInterrupt | 44 raise error.SignalInterrupt |
41 | 45 |
42 try: | 46 try: |
43 for name in 'SIGBREAK', 'SIGHUP', 'SIGTERM': | 47 for name in 'SIGBREAK', 'SIGHUP', 'SIGTERM': |
48 pass # happens if called in a thread | 52 pass # happens if called in a thread |
49 | 53 |
50 try: | 54 try: |
51 try: | 55 try: |
52 # enter the debugger before command execution | 56 # enter the debugger before command execution |
53 if '--debugger' in args: | 57 if '--debugger' in req.args: |
54 ui.warn(_("entering debugger - " | 58 ui.warn(_("entering debugger - " |
55 "type c to continue starting hg or h for help\n")) | 59 "type c to continue starting hg or h for help\n")) |
56 pdb.set_trace() | 60 pdb.set_trace() |
57 try: | 61 try: |
58 return _dispatch(ui, args) | 62 return _dispatch(ui, req) |
59 finally: | 63 finally: |
60 ui.flush() | 64 ui.flush() |
61 except: | 65 except: |
62 # enter the debugger when we hit an exception | 66 # enter the debugger when we hit an exception |
63 if '--debugger' in args: | 67 if '--debugger' in req.args: |
64 traceback.print_exc() | 68 traceback.print_exc() |
65 pdb.post_mortem(sys.exc_info()[2]) | 69 pdb.post_mortem(sys.exc_info()[2]) |
66 ui.traceback() | 70 ui.traceback() |
67 raise | 71 raise |
68 | 72 |
484 | 488 |
485 commands.norepo = norepo | 489 commands.norepo = norepo |
486 os.chdir(cwd) | 490 os.chdir(cwd) |
487 | 491 |
488 _loaded = set() | 492 _loaded = set() |
489 def _dispatch(ui, args): | 493 def _dispatch(ui, req): |
494 args = req.args | |
490 shellaliasfn = _checkshellalias(ui, args) | 495 shellaliasfn = _checkshellalias(ui, args) |
491 if shellaliasfn: | 496 if shellaliasfn: |
492 return shellaliasfn() | 497 return shellaliasfn() |
493 | 498 |
494 # read --config before doing anything else | 499 # read --config before doing anything else |
594 if cmd not in commands.optionalrepo.split(): | 599 if cmd not in commands.optionalrepo.split(): |
595 if args and not path: # try to infer -R from command args | 600 if args and not path: # try to infer -R from command args |
596 repos = map(cmdutil.findrepo, args) | 601 repos = map(cmdutil.findrepo, args) |
597 guess = repos[0] | 602 guess = repos[0] |
598 if guess and repos.count(guess) == len(repos): | 603 if guess and repos.count(guess) == len(repos): |
599 return _dispatch(ui, ['--repository', guess] + fullargs) | 604 req.args = ['--repository', guess] + fullargs |
605 return _dispatch(ui, req) | |
600 if not path: | 606 if not path: |
601 raise error.RepoError(_("no repository found in %r" | 607 raise error.RepoError(_("no repository found in %r" |
602 " (.hg not found)") % os.getcwd()) | 608 " (.hg not found)") % os.getcwd()) |
603 raise | 609 raise |
604 args.insert(0, repo) | 610 args.insert(0, repo) |