bl_keymap_completeness.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. # simple script to test 'bl_keymap_utils.keymap_hierarchy' contains correct values.
  20. # Needed for 'bl_keymap_utils.keymap_hierarchy' which inspects tools.
  21. import sys
  22. import os
  23. sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, "release", "scripts", "startup"))
  24. del sys, os
  25. from bl_keymap_utils import keymap_hierarchy
  26. def check_maps():
  27. maps = {}
  28. def fill_maps(seq):
  29. for km_name, km_space_type, km_region_type, km_sub in seq:
  30. maps[km_name] = (km_space_type, km_region_type)
  31. fill_maps(km_sub)
  32. fill_maps(keymap_hierarchy.generate())
  33. import bpy
  34. keyconf = bpy.context.window_manager.keyconfigs.active
  35. maps_bl = set(keyconf.keymaps.keys())
  36. maps_py = set(maps.keys())
  37. err = False
  38. # Check keyconfig contains only maps that exist in blender
  39. test = maps_py - maps_bl
  40. if test:
  41. print("Keymaps that are in 'bl_keymap_utils.keymap_hierarchy' but not blender")
  42. for km_id in test:
  43. if callable(km_id):
  44. # Keymap functions of tools are not in blender anyway...
  45. continue
  46. print("\t%s" % km_id)
  47. # TODO T65963, broken keymap hierarchy tests disabled until fixed.
  48. # err = True
  49. test = maps_bl - maps_py
  50. if test:
  51. print("Keymaps that are in blender but not in 'bl_keymap_utils.keymap_hierarchy'")
  52. for km_id in test:
  53. km = keyconf.keymaps[km_id]
  54. print(" ('%s', '%s', '%s', [])," % (km_id, km.space_type, km.region_type))
  55. # TODO T65963, broken keymap hierarchy tests disabled until fixed.
  56. # err = True
  57. # Check space/region's are OK
  58. print("Comparing keymap space/region types...")
  59. for km_id, km in keyconf.keymaps.items():
  60. km_py = maps.get(km_id)
  61. if km_py is not None:
  62. km_space_type, km_region_type = km_py
  63. if km_space_type != km.space_type or km_region_type != km.region_type:
  64. print(" Error:")
  65. print(" expected -- ('%s', '%s', '%s', [])," % (km_id, km.space_type, km.region_type))
  66. print(" got -- ('%s', '%s', '%s', [])," % (km_id, km_space_type, km_region_type))
  67. print("done!")
  68. return err
  69. def main():
  70. err = check_maps()
  71. import bpy
  72. if err and bpy.app.background:
  73. # alert CTest we failed
  74. import sys
  75. sys.exit(1)
  76. if __name__ == "__main__":
  77. main()