Cleanup: mark unused arguments in UI scripts
[blender.git] / release / datafiles / blender_icons_geom_update.py
1 #!/usr/bin/env python3
2
3 # This script updates icons from the BLEND file
4 import os
5 import subprocess
6 import sys
7
8
9 def run(cmd):
10     print("   ", " ".join(cmd))
11     # Don't use check_call because asan causes nonzero exitcode :S
12     subprocess.call(cmd)
13
14
15 def edit_text_file(filename, marker_begin, marker_end, content):
16     with open(filename, 'r', encoding='utf-8') as f:
17         data = f.read()
18     marker_begin_index = data.find(marker_begin)
19     marker_end_index = data.find(marker_end, marker_begin_index)
20     # include indentation of marker
21     while data[marker_end_index - 1] in {'\t', ' '}:
22         marker_end_index -= 1
23     if marker_begin_index == -1:
24         print('Error: {!r} not found'.format(marker_begin))
25         return
26     if marker_end_index == -1:
27         print('Error: {!r} not found'.format(marker_end))
28         return
29     marker_begin_index += len(marker_begin) + 1
30     data_update = data[:marker_begin_index] + content + data[marker_end_index:]
31     if data != data_update:
32         with open(filename, 'w', encoding='utf-8') as f:
33             f.write(data_update)
34
35
36 BASEDIR = os.path.abspath(os.path.dirname(__file__))
37 ROOTDIR = os.path.normpath(os.path.join(BASEDIR, "..", ".."))
38
39 blender_bin = os.environ.get("BLENDER_BIN", "blender")
40 if not os.path.exists(blender_bin):
41     blender_bin = os.path.join(ROOTDIR, "blender.bin")
42
43 if not os.path.exists(blender_bin):
44     if sys.platform == 'darwin':
45         blender_app_path = '/Applications/blender.app/Contents/MacOS/blender'
46         if os.path.exists(blender_app_path):
47             blender_bin = blender_app_path
48
49 icons_blend = (
50     os.path.join(ROOTDIR, "..", "lib", "resources", "icon_geom.blend"),
51 )
52
53
54 def names_and_time_from_path(path):
55     for entry in os.scandir(path):
56         name = entry.name
57         if name.endswith(".dat"):
58             yield (name, entry.stat().st_mtime)
59
60
61 # Collect icons files and update CMake.
62 icon_files = []
63
64 # create .dat geometry (which are stored in git)
65 for blend in icons_blend:
66     output_dir = os.path.join(BASEDIR, "icons")
67     files_old = set(names_and_time_from_path(output_dir))
68     cmd = (
69         blender_bin, "--background", "--factory-startup", "-noaudio",
70         blend,
71         "--python", os.path.join(BASEDIR, "blender_icons_geom.py"),
72         "--",
73         "--group", "Export",
74         "--output-dir", output_dir,
75     )
76     run(cmd)
77     files_new = set(names_and_time_from_path(output_dir))
78
79     icon_files.extend([
80         name[:-4]  # no .dat
81         for (name, _) in sorted((files_new - files_old))
82     ])
83
84
85 edit_text_file(
86     os.path.join(ROOTDIR, "source", "blender", "editors", "datafiles", "CMakeLists.txt"),
87     "# BEGIN ICON_GEOM_NAMES",
88     "# END ICON_GEOM_NAMES",
89     "\t" + "\n\t".join(icon_files) + "\n",
90 )