Blender V2.61 - r43446

rna_info_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 # ##### END GPL LICENSE BLOCK #####
00018 
00019 # <pep8 compliant>
00020 
00021 # Used for generating API diff's between releases
00022 #  ./blender.bin --background -noaudio --python release/test/rna_info_dump.py
00023 
00024 import bpy
00025 
00026 
00027 def api_dump(use_properties=True, use_functions=True):
00028 
00029     def prop_type(prop):
00030         if prop.type == "pointer":
00031             return prop.fixed_type.identifier
00032         else:
00033             return prop.type
00034 
00035     def func_to_str(struct_id_str, func_id, func):
00036 
00037         args = []
00038         for prop in func.args:
00039             data_str = "%s %s" % (prop_type(prop), prop.identifier)
00040             if prop.array_length:
00041                 data_str += "[%d]" % prop.array_length
00042             if not prop.is_required:
00043                 data_str += "=%s" % prop.default_str
00044             args.append(data_str)
00045 
00046         data_str = "%s.%s(%s)" % (struct_id_str, func_id, ", ".join(args))
00047         if func.return_values:
00048             return_args = ", ".join(prop_type(arg) for arg in func.return_values)
00049             if len(func.return_values) > 1:
00050                 data_str += "  -->  (%s)" % return_args
00051             else:
00052                 data_str += "  -->  %s" % return_args
00053         return data_str
00054 
00055     def prop_to_str(struct_id_str, prop_id, prop):
00056 
00057         prop_str = "  <--  %s" % prop_type(prop)
00058         if prop.array_length:
00059             prop_str += "[%d]" % prop.array_length
00060 
00061         data_str = "%s.%s %s" % (struct_id_str, prop_id, prop_str)
00062         return data_str
00063 
00064     def struct_full_id(v):
00065         struct_id_str = v.identifier  # "".join(sid for sid in struct_id if struct_id)
00066 
00067         for base in v.get_bases():
00068             struct_id_str = base.identifier + "|" + struct_id_str
00069 
00070         return struct_id_str
00071 
00072     def dump_funcs():
00073         data = []
00074         for struct_id, v in sorted(struct.items()):
00075             struct_id_str = struct_full_id(v)
00076 
00077             funcs = [(func.identifier, func) for func in v.functions]
00078 
00079             for func_id, func in funcs:
00080                 data.append(func_to_str(struct_id_str, func_id, func))
00081 
00082             for prop in v.properties:
00083                 if prop.collection_type:
00084                     funcs = [(prop.identifier + "." + func.identifier, func) for func in prop.collection_type.functions]
00085                     for func_id, func in funcs:
00086                         data.append(func_to_str(struct_id_str, func_id, func))
00087         data.sort()
00088         data.append("# * functions *")
00089         return data
00090 
00091     def dump_props():
00092         data = []
00093         for struct_id, v in sorted(struct.items()):
00094             struct_id_str = struct_full_id(v)
00095 
00096             props = [(prop.identifier, prop) for prop in v.properties]
00097 
00098             for prop_id, prop in props:
00099                 data.append(prop_to_str(struct_id_str, prop_id, prop))
00100 
00101             for prop in v.properties:
00102                 if prop.collection_type:
00103                     props = [(prop.identifier + "." + prop_sub.identifier, prop_sub) for prop_sub in prop.collection_type.properties]
00104                     for prop_sub_id, prop_sub in props:
00105                         data.append(prop_to_str(struct_id_str, prop_sub_id, prop_sub))
00106         data.sort()
00107         data.insert(0, "# * properties *")
00108         return data
00109 
00110     import rna_info
00111     struct = rna_info.BuildRNAInfo()[0]
00112     data = []
00113 
00114     if use_functions:
00115         data.extend(dump_funcs())
00116 
00117     if use_properties:
00118         data.extend(dump_props())
00119 
00120     if bpy.app.background:
00121         import sys
00122         sys.stderr.write("\n".join(data))
00123         sys.stderr.write("\n\nEOF\n")
00124     else:
00125         text = bpy.data.texts.new(name="api.py")
00126         text.from_string(data)
00127 
00128     print("END")
00129 
00130 if __name__ == "__main__":
00131     api_dump()