mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 14:32:22 -04:00

I noticed it when I looked at some files now used in AnkiDroid, wanting to be sure we clearly indicate that we have AGPLv3 code linked in the app
39 lines
1.2 KiB
Python
Executable file
39 lines
1.2 KiB
Python
Executable file
# Copyright: Ankitects Pty Ltd and contributors
|
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
import sys, subprocess, os, difflib
|
|
|
|
clang_format = sys.argv[1]
|
|
workspace = os.environ.get("BUILD_WORKSPACE_DIRECTORY", "")
|
|
want_fix = bool(workspace)
|
|
|
|
found_bad = False
|
|
for path in sys.argv[2:]:
|
|
with open(path) as file:
|
|
orig = file.read()
|
|
new = subprocess.check_output(
|
|
# [clang_format, "--style={'BasedOnStyle': 'google', 'IndentWidth': 4}", path]
|
|
[clang_format, "--style=google", path]
|
|
).decode("utf-8")
|
|
if orig != new:
|
|
if want_fix:
|
|
with open(os.path.join(workspace, path), "w", newline="\n") as file:
|
|
file.write(new)
|
|
print("fixed", path)
|
|
else:
|
|
print(f"Bad formatting in {path}")
|
|
print(
|
|
"\n".join(
|
|
difflib.unified_diff(
|
|
orig.splitlines(),
|
|
new.splitlines(),
|
|
fromfile="bad",
|
|
tofile="good",
|
|
lineterm="",
|
|
)
|
|
)
|
|
)
|
|
found_bad = True
|
|
|
|
if found_bad:
|
|
sys.exit(1)
|