File: dbgcall.py

package info (click to toggle)
pydb 1.26-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, squeeze, wheezy
  • size: 2,460 kB
  • ctags: 1,061
  • sloc: python: 4,200; perl: 2,479; sh: 873; lisp: 866; makefile: 634; ansic: 16
file content (38 lines) | stat: -rwxr-xr-x 979 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/python
"""Towers of Hanoi - testing calling debugger with continue and cmds"""
import sys

sys.path.insert(0, '..')
import pydb

pydb.debugger(dbg_cmds=['set basename on', 'set linetrace on', 'step 20'])

def hanoi(n,a,b,c):
    if n-1 > 0:
       hanoi(n-1, a, c, b) 
    print "Move disk %s to %s" % (a, b)
    if n-1 > 0:
       hanoi(n-1, c, b, a) 

if __name__=='__main__':
    i_args=len(sys.argv)
    if i_args != 1 and i_args != 2:
        print "*** Need number of disks or no parameter"
        sys.exit(1)

    n=3
    sys.settrace(None)
    if i_args > 1:
      try: 
        n = int(sys.argv[1])
      except ValueError, msg:
        print "** Expecting an integer, got: %s" % repr(sys.argv[1])
        sys.exit(2)

    pydb.debugger(status='continue', 
                  dbg_cmds=['p "continued"', 'step 2', 'c'])
    if n < 1 or n > 100: 
        print "*** number of disks should be between 1 and 100" 
        sys.exit(2)

    hanoi(n, "a", "b", "c")