Blender V2.61 - r43446

rna_dump.py

Go to the documentation of this file.
00001  # ***** BEGIN GPL LICENSE BLOCK *****
00002  #
00003  # This program is free software; you can redistribute it and/or
00004  # modify it under the terms of the GNU General Public License
00005  # as published by the Free Software Foundation; either version 2
00006  # of the License, or (at your option) any later version.
00007  #
00008  # This program is distributed in the hope that it will be useful,
00009  # but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  # GNU General Public License for more details.
00012  #
00013  # You should have received a copy of the GNU General Public License
00014  # along with this program; if not, write to the Free Software Foundation,
00015  # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00016  #
00017  # Contributor(s): Campbell Barton
00018  #
00019  # #**** END GPL LICENSE BLOCK #****
00020 
00021 # <pep8 compliant>
00022 
00023 if 1:
00024     # Print once every 1000
00025     GEN_PATH = True
00026     PRINT_DATA = False
00027     PRINT_DATA_INT = 1000
00028     VERBOSE = False
00029     VERBOSE_TYPE = False
00030     MAX_RECURSIVE = 8
00031 else:
00032     # Print everything
00033     GEN_PATH = True
00034     PRINT_DATA = True
00035     PRINT_DATA_INT = 0
00036     VERBOSE = False
00037     VERBOSE_TYPE = False
00038     MAX_RECURSIVE = 8
00039 
00040 seek_count = [0]
00041 
00042 
00043 def seek(r, txt, recurs):
00044 
00045     seek_count[0] += 1
00046 
00047     if PRINT_DATA_INT:
00048         if not (seek_count[0] % PRINT_DATA_INT):
00049             print(seek_count[0], txt)
00050 
00051     if PRINT_DATA:
00052         print(txt)
00053 
00054     newtxt = ''
00055 
00056     if recurs > MAX_RECURSIVE:
00057         #print ("Recursion is over max")
00058         #print (txt)
00059         return
00060 
00061     type_r = type(r)
00062 
00063     # print(type_r)
00064     # print(dir(r))
00065 
00066     # basic types
00067     if type_r in (float, int, bool, type(None)):
00068         if PRINT_DATA:
00069             print(txt + ' -> ' + str(r))
00070         return
00071 
00072     if type_r == str:
00073         if PRINT_DATA:
00074             print(txt + ' -> "' + str(r) + '"')
00075         return
00076 
00077     try:
00078         keys = r.keys()
00079     except:
00080         keys = None
00081 
00082     if keys != None:
00083         if PRINT_DATA:
00084             print(txt + '.keys() - ' + str(r.keys()))
00085 
00086     try:
00087         __members__ = dir(r)
00088     except:
00089         __members__ = []
00090 
00091     for item in __members__:
00092         if item.startswith("__"):
00093             continue
00094 
00095         if GEN_PATH:
00096             newtxt = txt + '.' + item
00097 
00098         if item == 'rna_type' and VERBOSE_TYPE == False:  # just avoid because it spits out loads of data
00099             continue
00100 
00101         value = getattr(r, item, None)
00102 
00103         seek(value, newtxt, recurs + 1)
00104 
00105     if keys:
00106         for k in keys:
00107             if GEN_PATH:
00108                 newtxt = txt + '["' + k + '"]'
00109             seek(r.__getitem__(k), newtxt, recurs + 1)
00110 
00111     else:
00112         try:
00113             length = len(r)
00114         except:
00115             length = 0
00116 
00117         if VERBOSE == False and length >= 4:
00118             for i in (0, length - 1):
00119                 if i > 0:
00120                     if PRINT_DATA:
00121                         print((" " * len(txt)) + " ... skipping " + str(length - 2) + " items ...")
00122 
00123                 if GEN_PATH:
00124                     newtxt = txt + '[' + str(i) + ']'
00125                 seek(r[i], newtxt, recurs + 1)
00126         else:
00127             for i in range(length):
00128                 if GEN_PATH:
00129                     newtxt = txt + '[' + str(i) + ']'
00130                 seek(r[i], newtxt, recurs + 1)
00131 
00132 seek(bpy.data, 'bpy.data', 0)
00133 # seek(bpy.types, 'bpy.types', 0)
00134 '''
00135 for d in dir(bpy.types):
00136     t = getattr(bpy.types, d)
00137     try:    r = t.bl_rna
00138     except: r = None
00139     if r:
00140         seek(r, 'bpy.types.' + d + '.bl_rna', 0)
00141 '''
00142 
00143 #print dir(bpy)
00144 #import sys
00145 #sys.exit()
00146 
00147 print("iter over ", seek_count, "rna items")