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