debugshell.py
65 lines
| 1.5 KiB
| text/x-python
|
PythonLexer
/ contrib / debugshell.py
Vishakh H
|
r11633 | # debugshell extension | ||
"""a python shell with repo, changelog & manifest objects""" | ||||
Pulkit Goyal
|
r28476 | from __future__ import absolute_import | ||
import code | ||||
Vishakh H
|
r11633 | import mercurial | ||
Pulkit Goyal
|
r28476 | import sys | ||
Gregory Szorc
|
r27721 | from mercurial import ( | ||
demandimport, | ||||
Pulkit Goyal
|
r41980 | pycompat, | ||
Yuya Nishihara
|
r32337 | registrar, | ||
Gregory Szorc
|
r27721 | ) | ||
Gregory Szorc
|
r21243 | |||
cmdtable = {} | ||||
Yuya Nishihara
|
r32337 | command = registrar.command(cmdtable) | ||
Vishakh H
|
r11633 | |||
Augie Fackler
|
r43346 | |||
Sean Farley
|
r19771 | def pdb(ui, repo, msg, **opts): | ||
Vishakh H
|
r11633 | objects = { | ||
'mercurial': mercurial, | ||||
'repo': repo, | ||||
'cl': repo.changelog, | ||||
Durham Goode
|
r30375 | 'mf': repo.manifestlog, | ||
Vishakh H
|
r11633 | } | ||
Sean Farley
|
r19771 | |||
code.interact(msg, local=objects) | ||||
Augie Fackler
|
r43346 | |||
Sean Farley
|
r19772 | def ipdb(ui, repo, msg, **opts): | ||
import IPython | ||||
cl = repo.changelog | ||||
Durham Goode
|
r30375 | mf = repo.manifestlog | ||
Augie Fackler
|
r43346 | cl, mf # use variables to appease pyflakes | ||
Sean Farley
|
r19772 | |||
IPython.embed() | ||||
Augie Fackler
|
r43346 | |||
Pulkit Goyal
|
r41980 | @command(b'debugshell|dbsh', []) | ||
Sean Farley
|
r19771 | def debugshell(ui, repo, **opts): | ||
Augie Fackler
|
r43346 | bannermsg = "loaded repo : %s\n" "using source: %s" % ( | ||
pycompat.sysstr(repo.root), | ||||
mercurial.__path__[0], | ||||
) | ||||
Sean Farley
|
r19771 | |||
Augie Fackler
|
r43346 | pdbmap = {'pdb': 'code', 'ipdb': 'IPython'} | ||
Sean Farley
|
r19773 | |||
Pulkit Goyal
|
r41980 | debugger = ui.config(b"ui", b"debugger") | ||
Sean Farley
|
r19773 | if not debugger: | ||
debugger = 'pdb' | ||||
Pulkit Goyal
|
r41980 | else: | ||
debugger = pycompat.sysstr(debugger) | ||||
Sean Farley
|
r19773 | |||
# if IPython doesn't exist, fallback to code.interact | ||||
try: | ||||
Gregory Szorc
|
r27721 | with demandimport.deactivated(): | ||
__import__(pdbmap[debugger]) | ||||
Sean Farley
|
r19773 | except ImportError: | ||
Augie Fackler
|
r43350 | ui.warnnoi18n( | ||
Augie Fackler
|
r43346 | b"%s debugger specified but %s module was not found\n" | ||
% (debugger, pdbmap[debugger]) | ||||
) | ||||
Pulkit Goyal
|
r41980 | debugger = b'pdb' | ||
Sean Farley
|
r19773 | |||
getattr(sys.modules[__name__], debugger)(ui, repo, bannermsg, **opts) | ||||