826051d9ceba00b08656a43417b67ea1eaeb8b8b
[blender.git] / source / blender / python / rna_dump.py
1  # ***** BEGIN GPL LICENSE BLOCK *****
2  #
3  # This program is free software; you can redistribute it and/or
4  # modify it under the terms of the GNU General Public License
5  # as published by the Free Software Foundation; either version 2
6  # of the License, or (at your option) any later version.
7  #
8  # This program is distributed in the hope that it will be useful,
9  # but WITHOUT ANY WARRANTY; without even the implied warranty of
10  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  # GNU General Public License for more details.
12  #
13  # You should have received a copy of the GNU General Public License
14  # along with this program; if not, write to the Free Software Foundation,
15  # Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
16  #
17  # Contributor(s): Campbell Barton
18  #
19  # #**** END GPL LICENSE BLOCK #****
20
21
22 PRINT_DATA = True
23 VERBOSE = False
24 VERBOSE_TYPE = False
25 SKIP_RECURSIVE = False
26
27
28 def seek(r, txt):
29         print(txt)
30         newtxt = ''
31         
32         if len(txt) > 200:
33                 print ("Somthing is wrong")
34                 print (txt)
35                 return
36         
37         type_r = type(r)
38         
39         # print(type_r)
40         # print(dir(r))
41         
42         # basic types
43         if type_r in (float, int, bool, type(None)):
44                 if PRINT_DATA:
45                         print(txt + ' -> ' + str(r))
46                 return
47         
48         if type_r == str:
49                 if PRINT_DATA:
50                         print(txt + ' -> "' + str(r) + '"')
51                 return
52         
53         try:    keys = r.keys()
54         except: keys = None
55         
56         if keys != None:
57                 if PRINT_DATA:
58                         print(txt + '.keys() - ' + str(r.keys()))
59         
60         try:    __members__ = dir(r)
61         except: __members__ = []
62         
63         for item in __members__:
64                 if item.startswith('__'):
65                         continue
66                         
67                 if PRINT_DATA:  newtxt = txt + '.' + item
68                 
69                 if item == 'rna_type' and VERBOSE_TYPE==False: # just avoid because it spits out loads of data
70                         continue
71                 
72                 if SKIP_RECURSIVE:
73                         if item in txt:
74                                 if PRINT_DATA:
75                                         print(newtxt + ' - (skipping to avoid recursive search)')
76                                 continue
77                 
78                 try:    value = getattr(r, item)
79                 except: value = None
80                 
81                 seek( value, newtxt)
82         
83         
84         if keys:
85                 for k in keys:
86                         if PRINT_DATA:  newtxt = txt + '["' + k + '"]'
87                         seek(r.__getitem__(k), newtxt)
88         
89         else:
90                 try:    length = len( r )
91                 except: length = 0
92                 
93                 if VERBOSE==False and length >= 4:
94                         for i in (0, length-1):
95                                 if i>0:
96                                         if PRINT_DATA:
97                                                 print((' '*len(txt)) + ' ... skipping '+str(length-2)+' items ...')
98                                 
99                                 if PRINT_DATA:  newtxt = txt + '[' + str(i) + ']'
100                                 seek(r[i], newtxt)
101                 else:
102                         for i in range(length):
103                                 if PRINT_DATA:  newtxt = txt + '[' + str(i) + ']'
104                                 seek(r[i], newtxt)
105
106 #print (dir(bpy))
107 seek(bpy, 'bpy')
108
109
110 #print dir(bpy)
111 #import sys
112 #sys.exit()