author | Chris Jerdonek <chris.jerdonek@gmail.com> |
Sun, 22 Dec 2013 21:27:00 -0800 | |
changeset 20199 | d87ed25733a1 |
parent 19794 | cccc44304b2c |
child 21243 | 8b5c039f2b4f |
permissions | -rw-r--r-- |
11633 | 1 |
# debugshell extension |
2 |
"""a python shell with repo, changelog & manifest objects""" |
|
3 |
||
19773
51799a965446
debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents:
19772
diff
changeset
|
4 |
import sys |
11633 | 5 |
import mercurial |
6 |
import code |
|
7 |
||
19771
3bc675361206
debugshell: abstract out pdb code.interact
Sean Farley <sean.michael.farley@gmail.com>
parents:
11633
diff
changeset
|
8 |
def pdb(ui, repo, msg, **opts): |
11633 | 9 |
objects = { |
10 |
'mercurial': mercurial, |
|
11 |
'repo': repo, |
|
12 |
'cl': repo.changelog, |
|
13 |
'mf': repo.manifest, |
|
14 |
} |
|
19771
3bc675361206
debugshell: abstract out pdb code.interact
Sean Farley <sean.michael.farley@gmail.com>
parents:
11633
diff
changeset
|
15 |
|
3bc675361206
debugshell: abstract out pdb code.interact
Sean Farley <sean.michael.farley@gmail.com>
parents:
11633
diff
changeset
|
16 |
code.interact(msg, local=objects) |
3bc675361206
debugshell: abstract out pdb code.interact
Sean Farley <sean.michael.farley@gmail.com>
parents:
11633
diff
changeset
|
17 |
|
19772
6ccec36a1fd9
debugshell: add function to embed ipython
Sean Farley <sean.michael.farley@gmail.com>
parents:
19771
diff
changeset
|
18 |
def ipdb(ui, repo, msg, **opts): |
6ccec36a1fd9
debugshell: add function to embed ipython
Sean Farley <sean.michael.farley@gmail.com>
parents:
19771
diff
changeset
|
19 |
import IPython |
6ccec36a1fd9
debugshell: add function to embed ipython
Sean Farley <sean.michael.farley@gmail.com>
parents:
19771
diff
changeset
|
20 |
|
6ccec36a1fd9
debugshell: add function to embed ipython
Sean Farley <sean.michael.farley@gmail.com>
parents:
19771
diff
changeset
|
21 |
cl = repo.changelog |
6ccec36a1fd9
debugshell: add function to embed ipython
Sean Farley <sean.michael.farley@gmail.com>
parents:
19771
diff
changeset
|
22 |
mf = repo.manifest |
19794
cccc44304b2c
debugshell: appease pyflakes
Matt Mackall <mpm@selenic.com>
parents:
19773
diff
changeset
|
23 |
cl, mf # use variables to appease pyflakes |
19772
6ccec36a1fd9
debugshell: add function to embed ipython
Sean Farley <sean.michael.farley@gmail.com>
parents:
19771
diff
changeset
|
24 |
|
6ccec36a1fd9
debugshell: add function to embed ipython
Sean Farley <sean.michael.farley@gmail.com>
parents:
19771
diff
changeset
|
25 |
IPython.embed() |
6ccec36a1fd9
debugshell: add function to embed ipython
Sean Farley <sean.michael.farley@gmail.com>
parents:
19771
diff
changeset
|
26 |
|
19771
3bc675361206
debugshell: abstract out pdb code.interact
Sean Farley <sean.michael.farley@gmail.com>
parents:
11633
diff
changeset
|
27 |
def debugshell(ui, repo, **opts): |
11633 | 28 |
bannermsg = "loaded repo : %s\n" \ |
29 |
"using source: %s" % (repo.root, |
|
30 |
mercurial.__path__[0]) |
|
19771
3bc675361206
debugshell: abstract out pdb code.interact
Sean Farley <sean.michael.farley@gmail.com>
parents:
11633
diff
changeset
|
31 |
|
19773
51799a965446
debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents:
19772
diff
changeset
|
32 |
pdbmap = { |
51799a965446
debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents:
19772
diff
changeset
|
33 |
'pdb' : 'code', |
51799a965446
debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents:
19772
diff
changeset
|
34 |
'ipdb' : 'IPython' |
51799a965446
debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents:
19772
diff
changeset
|
35 |
} |
51799a965446
debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents:
19772
diff
changeset
|
36 |
|
51799a965446
debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents:
19772
diff
changeset
|
37 |
debugger = ui.config("ui", "debugger") |
51799a965446
debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents:
19772
diff
changeset
|
38 |
if not debugger: |
51799a965446
debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents:
19772
diff
changeset
|
39 |
debugger = 'pdb' |
51799a965446
debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents:
19772
diff
changeset
|
40 |
|
51799a965446
debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents:
19772
diff
changeset
|
41 |
# if IPython doesn't exist, fallback to code.interact |
51799a965446
debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents:
19772
diff
changeset
|
42 |
try: |
51799a965446
debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents:
19772
diff
changeset
|
43 |
__import__(pdbmap[debugger]) |
51799a965446
debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents:
19772
diff
changeset
|
44 |
except ImportError: |
51799a965446
debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents:
19772
diff
changeset
|
45 |
ui.warn("%s debugger specified but %s module was not found\n" |
51799a965446
debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents:
19772
diff
changeset
|
46 |
% (debugger, pdbmap[debugger])) |
51799a965446
debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents:
19772
diff
changeset
|
47 |
debugger = 'pdb' |
51799a965446
debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents:
19772
diff
changeset
|
48 |
|
51799a965446
debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents:
19772
diff
changeset
|
49 |
getattr(sys.modules[__name__], debugger)(ui, repo, bannermsg, **opts) |
11633 | 50 |
|
51 |
cmdtable = { |
|
52 |
"debugshell|dbsh": (debugshell, []) |
|
53 |
} |