diff --git a/tools/README.txt b/scripts/README.txt similarity index 93% rename from tools/README.txt rename to scripts/README.txt index 89d5b9ce..dfb25797 100644 --- a/tools/README.txt +++ b/scripts/README.txt @@ -1,4 +1,4 @@ -tools/ +scripts/ This directory contains useful scripts for changing many files at once, for example replacing string occurences or converting whitespace. diff --git a/tools/blender-scripts.py b/scripts/blender-scripts.py similarity index 100% rename from tools/blender-scripts.py rename to scripts/blender-scripts.py diff --git a/tools/check-levels.sh b/scripts/check-levels.sh old mode 100755 new mode 100644 similarity index 100% rename from tools/check-levels.sh rename to scripts/check-levels.sh diff --git a/tools/convert-whitespace.sh b/scripts/convert-whitespace.sh old mode 100755 new mode 100644 similarity index 100% rename from tools/convert-whitespace.sh rename to scripts/convert-whitespace.sh diff --git a/tools/fix-eof-eol.sh b/scripts/fix-eof-eol.sh old mode 100755 new mode 100644 similarity index 100% rename from tools/fix-eof-eol.sh rename to scripts/fix-eof-eol.sh diff --git a/tools/git-diff-check-colobot-lint.sh b/scripts/git-diff-check-colobot-lint.sh old mode 100755 new mode 100644 similarity index 100% rename from tools/git-diff-check-colobot-lint.sh rename to scripts/git-diff-check-colobot-lint.sh diff --git a/tools/git-grep-braces.sh b/scripts/git-grep-braces.sh old mode 100755 new mode 100644 similarity index 100% rename from tools/git-grep-braces.sh rename to scripts/git-grep-braces.sh diff --git a/tools/git-submodule-status.sh b/scripts/git-submodule-status.sh old mode 100755 new mode 100644 similarity index 100% rename from tools/git-submodule-status.sh rename to scripts/git-submodule-status.sh diff --git a/tools/mission-time-loop.sh b/scripts/mission-time-loop.sh old mode 100755 new mode 100644 similarity index 100% rename from tools/mission-time-loop.sh rename to scripts/mission-time-loop.sh diff --git a/tools/mission-time.sh b/scripts/mission-time.sh old mode 100755 new mode 100644 similarity index 100% rename from tools/mission-time.sh rename to scripts/mission-time.sh diff --git a/tools/release.py b/scripts/release.py old mode 100755 new mode 100644 similarity index 100% rename from tools/release.py rename to scripts/release.py diff --git a/tools/sed-replace.sh b/scripts/sed-replace.sh old mode 100755 new mode 100644 similarity index 100% rename from tools/sed-replace.sh rename to scripts/sed-replace.sh diff --git a/tools/strip-trailing-whitespace.sh b/scripts/strip-trailing-whitespace.sh old mode 100755 new mode 100644 similarity index 100% rename from tools/strip-trailing-whitespace.sh rename to scripts/strip-trailing-whitespace.sh diff --git a/tools/update-license.py b/scripts/update-license.py similarity index 97% rename from tools/update-license.py rename to scripts/update-license.py index 9f79fc23..a3f17491 100644 --- a/tools/update-license.py +++ b/scripts/update-license.py @@ -1,58 +1,58 @@ -import argparse -import os -from typing import * - -T = TypeVar('T') - -SOURCE_FILES_SEARCH_DIRECTORIES = ['src', 'test'] -LICENSE_HEADER_END = ' * along with this program. If not, see http://gnu.org/licenses' - -def is_source_file(file: str) -> bool: - return file.endswith('.cpp') or file.endswith('.h') - - -def find_all_source_files(directories: list[str]) -> str: - for directory in directories: - for root, found_dirs, found_files in os.walk(directory): - for file in found_files: - if is_source_file(file): - path = os.path.join(root, file) - yield path - - -def find_license_header_end(lines: list[str]) -> Optional[int]: - for idx, line in enumerate(lines): - if LICENSE_HEADER_END in line: - return idx + 2 # One more line with '*/' and idx past end - return None - - -def remove_range(a_list: list[T], begin: int, end: int) -> list[str]: - return a_list[0:begin] + a_list[end:] - - -def remove_license_header(lines: list[str]) -> list[str]: - return remove_range(lines, begin=0, end=find_license_header_end(lines)) - - -def add_license_header_at_beginning(lines: list[str], new_license_header: list[str]) -> list[str]: - return new_license_header + lines - - -def update_license_header(lines: list[str], new_license_header: list[str]) -> list[str]: - return add_license_header_at_beginning(remove_license_header(lines), new_license_header) - - -def main(): - parser = argparse.ArgumentParser() - parser.add_argument('license_header', help='Path to the new license header file', type=str) - args = parser.parse_args() - new_license_header = open(args.license_header).readlines() - for source_file in find_all_source_files(SOURCE_FILES_SEARCH_DIRECTORIES): - print(source_file) - lines = update_license_header(open(source_file).readlines(), new_license_header) - open(source_file, 'w', newline='\n').writelines(lines) - - -if __name__ == '__main__': - main() +import argparse +import os +from typing import * + +T = TypeVar('T') + +SOURCE_FILES_SEARCH_DIRECTORIES = ['src', 'test'] +LICENSE_HEADER_END = ' * along with this program. If not, see http://gnu.org/licenses' + +def is_source_file(file: str) -> bool: + return file.endswith('.cpp') or file.endswith('.h') + + +def find_all_source_files(directories: list[str]) -> str: + for directory in directories: + for root, found_dirs, found_files in os.walk(directory): + for file in found_files: + if is_source_file(file): + path = os.path.join(root, file) + yield path + + +def find_license_header_end(lines: list[str]) -> Optional[int]: + for idx, line in enumerate(lines): + if LICENSE_HEADER_END in line: + return idx + 2 # One more line with '*/' and idx past end + return None + + +def remove_range(a_list: list[T], begin: int, end: int) -> list[str]: + return a_list[0:begin] + a_list[end:] + + +def remove_license_header(lines: list[str]) -> list[str]: + return remove_range(lines, begin=0, end=find_license_header_end(lines)) + + +def add_license_header_at_beginning(lines: list[str], new_license_header: list[str]) -> list[str]: + return new_license_header + lines + + +def update_license_header(lines: list[str], new_license_header: list[str]) -> list[str]: + return add_license_header_at_beginning(remove_license_header(lines), new_license_header) + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('license_header', help='Path to the new license header file', type=str) + args = parser.parse_args() + new_license_header = open(args.license_header).readlines() + for source_file in find_all_source_files(SOURCE_FILES_SEARCH_DIRECTORIES): + print(source_file) + lines = update_license_header(open(source_file).readlines(), new_license_header) + open(source_file, 'w', newline='\n').writelines(lines) + + +if __name__ == '__main__': + main()