import glob
from pprint import pprint
source_path = "/home/jacques/blender-git/blender/source"
files_to_check = set()
for filepath in glob.iglob(source_path + "/**/**", recursive=True):
if filepath.endswith(".hh") or filepath.endswith(".h"):
files_to_check.add(filepath)
ignored_guard_names = {
"__RNA_ACCESS_H__",
"__RNA_TYPES_H__",
"__BLI_TASK_H__",
"__BLI_ENDIAN_SWITCH_H__",
"__BLI_MEMORY_UTILS_H__",
"__PY_CAPI_UTILS_H__",
}
for filepath in sorted(files_to_check):
with open(filepath) as fs:
text = fs.read()
lines = text.splitlines()
for ifndef_line, line in enumerate(lines):
if line.startswith("#ifndef __"):
break
else:
continue
define_line = ifndef_line + 1
guard_name = lines[define_line].split(" ")[1]
if guard_name in ("__RNA_ACCESS_H__", "__RNA_TYPES_H__", "__BLI_TASK_H__", "__BLI_ENDIAN_SWITCH_H__"):ignored_guard_names:
continue
for endif_line, line in reversed(list(enumerate(lines))):
if line.startswith("#endif"):
break
lines[ifndef_line] = "#pragma once"
lines[define_line] = ""
lines[endif_line] = ""
print(filepath)
new_text = "\n".join(lines)
with open(filepath, "w") as fs:
fs.write(new_text)