]> git.phdru.name Git - dotfiles.git/blob - lib/python/pdbrc.py
0ebe7b513e5cf2cb8b4e0ee738e927ae148111ff
[dotfiles.git] / lib / python / pdbrc.py
1 import atexit
2 import os
3 import sys
4 import readline
5
6 # Command line history:
7 histfile = os.path.expanduser("~/.pdb-history")
8
9 try:
10     readline.read_history_file(histfile)
11 except IOError:
12     pass
13
14
15 def savehist(histfile=histfile):
16     import os
17     import readline
18
19     histfilesize = os.environ.get('HISTFILESIZE') \
20         or os.environ.get('HISTSIZE')
21     if histfilesize:
22         try:
23             histfilesize = int(histfilesize)
24         except ValueError:
25             pass
26         else:
27             readline.set_history_length(histfilesize)
28     readline.write_history_file(histfile)
29
30 atexit.register(savehist)
31
32
33 def info(type, value, tb):
34     # return to debugger after fatal exception (Python cookbook 14.5):
35     import pdb
36     import sys
37     import traceback
38
39     if hasattr(sys, 'ps1') or not sys.stderr.isatty():
40         sys.__excepthook__(type, value, tb)
41     traceback.print_exception(type, value, tb)
42     print
43     pdb.pm()
44
45 sys.excepthook = info
46
47
48 # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/498182
49 import pdb
50 import rlcompleter
51 pdb.Pdb.complete = rlcompleter.Completer().complete
52
53 # Cleanup any variables that could otherwise clutter up the namespace.
54 del atexit, info, os, pdb, readline, rlcompleter, savehist, sys