Listing the "Blender Foundation" as copyright holder implied the Blender Foundation holds copyright to files which may include work from many developers. While keeping copyright on headers makes sense for isolated libraries, Blender's own code may be refactored or moved between files in a way that makes the per file copyright holders less meaningful. Copyright references to the "Blender Foundation" have been replaced with "Blender Authors", with the exception of `./extern/` since these this contains libraries which are more isolated, any changed to license headers there can be handled on a case-by-case basis. Some directories in `./intern/` have also been excluded: - `./intern/cycles/` it's own `AUTHORS` file is planned. - `./intern/opensubdiv/`. An "AUTHORS" file has been added, using the chromium projects authors file as a template. Design task: #110784 Ref !110783.
66 lines
1.7 KiB
Python
66 lines
1.7 KiB
Python
# SPDX-FileCopyrightText: 2023 Blender Authors
|
|
#
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
from typing import (
|
|
Callable,
|
|
Generator,
|
|
Optional,
|
|
Sequence,
|
|
)
|
|
|
|
TextOpFn = Callable[
|
|
# file_name, data_src
|
|
[str, str],
|
|
# data_dst or None when no change is made.
|
|
Optional[str]
|
|
]
|
|
|
|
|
|
def operation_wrap(fn: str, text_operation: TextOpFn) -> None:
|
|
with open(fn, "r", encoding="utf-8") as f:
|
|
data_src = f.read()
|
|
data_dst = text_operation(fn, data_src)
|
|
|
|
if data_dst is None or (data_src == data_dst):
|
|
return
|
|
|
|
with open(fn, "w", encoding="utf-8") as f:
|
|
f.write(data_dst)
|
|
|
|
|
|
def run(
|
|
*,
|
|
directories: Sequence[str],
|
|
is_text: Callable[[str], bool],
|
|
text_operation: TextOpFn,
|
|
use_multiprocess: bool,
|
|
) -> None:
|
|
print(directories)
|
|
|
|
import os
|
|
|
|
def source_files(path: str) -> Generator[str, None, None]:
|
|
for dirpath, dirnames, filenames in os.walk(path):
|
|
dirnames[:] = [d for d in dirnames if not d.startswith(".")]
|
|
for filename in filenames:
|
|
if filename.startswith("."):
|
|
continue
|
|
filepath = os.path.join(dirpath, filename)
|
|
if is_text(filepath):
|
|
yield filepath
|
|
|
|
if use_multiprocess:
|
|
args = [
|
|
(fn, text_operation) for directory in directories
|
|
for fn in source_files(directory)
|
|
]
|
|
import multiprocessing
|
|
job_total = multiprocessing.cpu_count()
|
|
pool = multiprocessing.Pool(processes=job_total * 2)
|
|
pool.starmap(operation_wrap, args)
|
|
else:
|
|
for directory in directories:
|
|
for fn in source_files(directory):
|
|
operation_wrap(fn, text_operation)
|