]> git.phdru.name Git - dotfiles.git/blob - lib/python/pdbrc.py
97bd40115cc971d9f286757e6e961333a1e67dc0
[dotfiles.git] / lib / python / pdbrc.py
1 # This is startup file for interactive python debugger pdb.
2 # Use it like this in ~/.pdbrc:
3 # import os
4 # x = execfile("pdbrc.py")
5 # See http://wiki.python.org/moin/PdbRcIdea
6
7 def init():
8     import atexit
9     import os
10     import sys
11     import readline
12
13     # Command line history:
14     histfile = os.path.expanduser("~/.pdb_history")
15
16     try:
17         readline.read_history_file(histfile)
18     except IOError:
19         pass
20
21
22     def savehist(histfile=histfile):
23         import os
24         import readline
25
26         histfilesize = os.environ.get('HISTFILESIZE') \
27             or os.environ.get('HISTSIZE')
28         if histfilesize:
29             try:
30                 histfilesize = int(histfilesize)
31             except ValueError:
32                 pass
33             else:
34                 readline.set_history_length(histfilesize)
35         readline.write_history_file(histfile)
36
37     atexit.register(savehist)
38
39
40     def info(type, value, tb):
41         # return to debugger after fatal exception (Python cookbook 14.5):
42         import pdb
43         import sys
44         import traceback
45
46         if hasattr(sys, 'ps1') or not sys.stderr.isatty():
47             sys.__excepthook__(type, value, tb)
48         traceback.print_exception(type, value, tb)
49         print
50         pdb.pm()
51
52     sys.excepthook = info
53
54 init()
55
56 # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/498182
57 # https://github.com/giampaolo/sysconf/blob/master/home/.pdbrc.py
58 import pdb
59 import rlcompleter
60 pdb.Pdb.complete = rlcompleter.Completer(locals()).complete
61
62 # Cleanup any variables that could otherwise clutter up the namespace.
63 del pdb, readline, rlcompleter