rna_info_dump.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. #
  17. # ##### END GPL LICENSE BLOCK #####
  18. # <pep8 compliant>
  19. # Used for generating API diffs between releases
  20. # ./blender.bin --background -noaudio --python tests/python/rna_info_dump.py
  21. import bpy
  22. def api_dump(use_properties=True, use_functions=True):
  23. def prop_type(prop):
  24. if prop.type == "pointer":
  25. return prop.fixed_type.identifier
  26. else:
  27. return prop.type
  28. def func_to_str(struct_id_str, func_id, func):
  29. args = []
  30. for prop in func.args:
  31. data_str = "%s %s" % (prop_type(prop), prop.identifier)
  32. if prop.array_length:
  33. data_str += "[%d]" % prop.array_length
  34. if not prop.is_required:
  35. data_str += "=%s" % prop.default_str
  36. args.append(data_str)
  37. data_str = "%s.%s(%s)" % (struct_id_str, func_id, ", ".join(args))
  38. if func.return_values:
  39. return_args = ", ".join(prop_type(arg) for arg in func.return_values)
  40. if len(func.return_values) > 1:
  41. data_str += " --> (%s)" % return_args
  42. else:
  43. data_str += " --> %s" % return_args
  44. return data_str
  45. def prop_to_str(struct_id_str, prop_id, prop):
  46. prop_str = " <-- %s" % prop_type(prop)
  47. if prop.array_length:
  48. prop_str += "[%d]" % prop.array_length
  49. data_str = "%s.%s %s" % (struct_id_str, prop_id, prop_str)
  50. return data_str
  51. def struct_full_id(v):
  52. struct_id_str = v.identifier # "".join(sid for sid in struct_id if struct_id)
  53. for base in v.get_bases():
  54. struct_id_str = base.identifier + "|" + struct_id_str
  55. return struct_id_str
  56. def dump_funcs():
  57. data = []
  58. for _struct_id, v in sorted(struct.items()):
  59. struct_id_str = struct_full_id(v)
  60. funcs = [(func.identifier, func) for func in v.functions]
  61. for func_id, func in funcs:
  62. data.append(func_to_str(struct_id_str, func_id, func))
  63. for prop in v.properties:
  64. if prop.collection_type:
  65. funcs = [(prop.identifier + "." + func.identifier, func) for func in prop.collection_type.functions]
  66. for func_id, func in funcs:
  67. data.append(func_to_str(struct_id_str, func_id, func))
  68. data.sort()
  69. data.append("# * functions *")
  70. return data
  71. def dump_props():
  72. data = []
  73. for _struct_id, v in sorted(struct.items()):
  74. struct_id_str = struct_full_id(v)
  75. props = [(prop.identifier, prop) for prop in v.properties]
  76. for prop_id, prop in props:
  77. data.append(prop_to_str(struct_id_str, prop_id, prop))
  78. for prop in v.properties:
  79. if prop.collection_type:
  80. props = [(prop.identifier + "." + prop_sub.identifier, prop_sub) for prop_sub in prop.collection_type.properties]
  81. for prop_sub_id, prop_sub in props:
  82. data.append(prop_to_str(struct_id_str, prop_sub_id, prop_sub))
  83. data.sort()
  84. data.insert(0, "# * properties *")
  85. return data
  86. import rna_info
  87. struct = rna_info.BuildRNAInfo()[0]
  88. data = []
  89. if use_functions:
  90. data.extend(dump_funcs())
  91. if use_properties:
  92. data.extend(dump_props())
  93. if bpy.app.background:
  94. import sys
  95. sys.stderr.write("\n".join(data))
  96. sys.stderr.write("\n\nEOF\n")
  97. else:
  98. text = bpy.data.texts.new(name="api.py")
  99. text.from_string(data)
  100. print("END")
  101. if __name__ == "__main__":
  102. api_dump()