File: settrace.py.in

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 (51 lines) | stat: -rw-r--r-- 1,131 bytes parent folder | download | duplicates (3)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/python
"""Towers of Hanoi"""
import sys, os

top_builddir = "@top_builddir@"
if top_builddir[-1] != os.path.sep:
    top_builddir += os.path.sep
sys.path.insert(0, os.path.join(top_builddir, 'pydb'))
top_srcdir = "@top_srcdir@"
if top_srcdir[-1] != os.path.sep:
    top_srcdir += os.path.sep
sys.path.insert(0, os.path.join(top_srcdir, 'pydb'))

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)

i_args=len(sys.argv)
if i_args > 3:
    print "usage %s [disks [cmdfile]]" % sys.argv[0]
    sys.exit(1)

n=3
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)

if n < 1 or n > 100: 
    print "*** number of disks should be between 1 and 100" 
    sys.exit(2)

dbg_cmds=['set basename on',
          'where',
          'list',
          'step',
          'step',
          'where',
          'info locals',
          'set linetrace on',
          'continue']

import pydb
pydb.debugger(dbg_cmds)

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