Show More
@@ -1,53 +1,54 b'' | |||
|
1 | 1 | # debugshell extension |
|
2 | 2 | """a python shell with repo, changelog & manifest objects""" |
|
3 | 3 | |
|
4 | 4 | import sys |
|
5 | 5 | import mercurial |
|
6 | 6 | import code |
|
7 | from mercurial import cmdutil | |
|
8 | ||
|
9 | cmdtable = {} | |
|
10 | command = cmdutil.command(cmdtable) | |
|
7 | 11 | |
|
8 | 12 | def pdb(ui, repo, msg, **opts): |
|
9 | 13 | objects = { |
|
10 | 14 | 'mercurial': mercurial, |
|
11 | 15 | 'repo': repo, |
|
12 | 16 | 'cl': repo.changelog, |
|
13 | 17 | 'mf': repo.manifest, |
|
14 | 18 | } |
|
15 | 19 | |
|
16 | 20 | code.interact(msg, local=objects) |
|
17 | 21 | |
|
18 | 22 | def ipdb(ui, repo, msg, **opts): |
|
19 | 23 | import IPython |
|
20 | 24 | |
|
21 | 25 | cl = repo.changelog |
|
22 | 26 | mf = repo.manifest |
|
23 | 27 | cl, mf # use variables to appease pyflakes |
|
24 | 28 | |
|
25 | 29 | IPython.embed() |
|
26 | 30 | |
|
31 | @command('debugshell|dbsh', []) | |
|
27 | 32 | def debugshell(ui, repo, **opts): |
|
28 | 33 | bannermsg = "loaded repo : %s\n" \ |
|
29 | 34 | "using source: %s" % (repo.root, |
|
30 | 35 | mercurial.__path__[0]) |
|
31 | 36 | |
|
32 | 37 | pdbmap = { |
|
33 | 38 | 'pdb' : 'code', |
|
34 | 39 | 'ipdb' : 'IPython' |
|
35 | 40 | } |
|
36 | 41 | |
|
37 | 42 | debugger = ui.config("ui", "debugger") |
|
38 | 43 | if not debugger: |
|
39 | 44 | debugger = 'pdb' |
|
40 | 45 | |
|
41 | 46 | # if IPython doesn't exist, fallback to code.interact |
|
42 | 47 | try: |
|
43 | 48 | __import__(pdbmap[debugger]) |
|
44 | 49 | except ImportError: |
|
45 | 50 | ui.warn("%s debugger specified but %s module was not found\n" |
|
46 | 51 | % (debugger, pdbmap[debugger])) |
|
47 | 52 | debugger = 'pdb' |
|
48 | 53 | |
|
49 | 54 | getattr(sys.modules[__name__], debugger)(ui, repo, bannermsg, **opts) |
|
50 | ||
|
51 | cmdtable = { | |
|
52 | "debugshell|dbsh": (debugshell, []) | |
|
53 | } |
General Comments 0
You need to be logged in to leave comments.
Login now