sapling/contrib/debugshell.py

60 lines
1.4 KiB
Python
Raw Normal View History

2010-07-20 21:59:49 +04:00
# debugshell extension
"""a python shell with repo, changelog & manifest objects"""
2016-03-06 00:49:08 +03:00
from __future__ import absolute_import
2010-07-20 21:59:49 +04:00
import code
2016-03-06 00:49:08 +03:00
import mercurial
import sys
from mercurial import (
cmdutil,
demandimport,
)
cmdtable = {}
command = cmdutil.command(cmdtable)
2010-07-20 21:59:49 +04:00
def pdb(ui, repo, msg, **opts):
2010-07-20 21:59:49 +04:00
objects = {
'mercurial': mercurial,
'repo': repo,
'cl': repo.changelog,
'mf': repo.manifest,
}
code.interact(msg, local=objects)
def ipdb(ui, repo, msg, **opts):
import IPython
cl = repo.changelog
mf = repo.manifest
2013-09-24 01:28:01 +04:00
cl, mf # use variables to appease pyflakes
IPython.embed()
@command('debugshell|dbsh', [])
def debugshell(ui, repo, **opts):
2010-07-20 21:59:49 +04:00
bannermsg = "loaded repo : %s\n" \
"using source: %s" % (repo.root,
mercurial.__path__[0])
pdbmap = {
'pdb' : 'code',
'ipdb' : 'IPython'
}
debugger = ui.config("ui", "debugger")
if not debugger:
debugger = 'pdb'
# if IPython doesn't exist, fallback to code.interact
try:
with demandimport.deactivated():
__import__(pdbmap[debugger])
except ImportError:
ui.warn("%s debugger specified but %s module was not found\n"
% (debugger, pdbmap[debugger]))
debugger = 'pdb'
getattr(sys.modules[__name__], debugger)(ui, repo, bannermsg, **opts)