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