Imported Upstream version 2008.1+svn1648
[opeanno-debian-packaging.git] / debug.py
blob755c3df56ff1190a67ea9b3174fc08bd8bccb1b3
1 #!/usr/bin/env python
3 # ###################################################
4 # Copyright (C) 2008 The OpenAnno Team
5 # team@openanno.org
6 # This file is part of OpenAnno.
8 # OpenAnno is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the
20 # Free Software Foundation, Inc.,
21 # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 # ###################################################
24 if __name__ == '__main__':
25 import openanno
26 import sys
27 import os
28 #find fife and setup search paths
29 openanno.findFIFE()
30 os.execvp(sys.argv[1], sys.argv[1:])
31 else:
32 import inspect
33 import game.main
35 already = []
36 def printTree(obj, deep = 0):
37 global already
38 already.append(obj)
39 ignore = ['__builtins__', 'this', 'grounds', '_instances']
40 try:
41 obj.__dict__
42 except:
43 print str(obj)
44 return
45 print str(obj) + ':'
46 deep += 1
47 for name in obj.__dict__:
48 if name.startswith('__') and name.endswith('__'):
49 continue
50 elif name in ignore:
51 continue
52 elif inspect.ismodule(obj.__dict__[name]) and not obj.__dict__[name].__file__.startswith('/home'):
53 continue
54 elif obj.__dict__[name] in already:
55 continue
56 elif inspect.isfunction(obj.__dict__[name]) or inspect.isclass(obj.__dict__[name]):
57 continue
58 try:
59 obj.__dict__[name].__dict__
60 continue
61 except:
62 pass
63 print (deep * ' ') + str(name) + ': ',
64 printTree(obj.__dict__[name], deep)
65 for name in obj.__dict__:
66 if name.startswith('__') and name.endswith('__'):
67 continue
68 elif name in ignore:
69 continue
70 elif inspect.ismodule(obj.__dict__[name]) and not obj.__dict__[name].__file__.startswith('/home'):
71 continue
72 elif obj.__dict__[name] in already:
73 continue
74 elif inspect.isfunction(obj.__dict__[name]) or inspect.isclass(obj.__dict__[name]):
75 continue
76 try:
77 obj.__dict__[name].__dict__
78 except:
79 continue
80 print (deep * ' ') + str(name) + ': ',
81 printTree(obj.__dict__[name], deep)
83 from game.command import *
84 def cmd(name, *pargs, **kargs):
85 game.main.session.manager.execute(eval(name)(*pargs, **kargs))
87 print 'Debuging tools usage:'
88 print 'import debug (already done): load the tools'
89 print 'debug.printTree(<object>): print a tree of an object (the properties, recursive)'
90 print "debug.cmd('name', *args): create a command and execute it throught the manager ex: debug.cmd('unit.Move', game.main.session.selected_instance, x, y)"
91 print ''