File: settrace.py.in

package info (click to toggle)
pydb 1.19-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,952 kB
  • ctags: 1,412
  • sloc: python: 3,065; perl: 2,479; sh: 586; makefile: 555; lisp: 265; ansic: 16
file content (50 lines) | stat: -rw-r--r-- 1,103 bytes parent folder | download
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
#!/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=['where',
          'list',
          'step',
          'step',
          'where',
          'info locals',
          'set linetrace on',
          'continue']

import pydb
pydb.set_trace(dbg_cmds)

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