diff options
| author | Chris Boesch <chrboesch@noreply.codeberg.org> | 2023-04-25 21:46:12 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-25 21:46:12 +0000 |
| commit | 232002f30f24d7d44f763079b331839659b382ad (patch) | |
| tree | e337bdbf46a5a3bdfefedd820c6c7e097bdf6421 /tools/update-patches.py | |
| parent | fa28aedfe1535df42d8d7c3bdecf7b4fc44c1379 (diff) | |
| parent | 213d0712a532292106515882295bd54a7e0a9326 (diff) | |
Merge pull request #254 from chrboesch/tools
Replacing Python-Tools with Zig-Tools
Diffstat (limited to 'tools/update-patches.py')
| -rwxr-xr-x | tools/update-patches.py | 68 |
1 files changed, 0 insertions, 68 deletions
diff --git a/tools/update-patches.py b/tools/update-patches.py deleted file mode 100755 index 76a1c46..0000000 --- a/tools/update-patches.py +++ /dev/null @@ -1,68 +0,0 @@ -#!/usr/bin/env python - -import os -import os.path -import subprocess - - -IGNORE = subprocess.DEVNULL - -EXERCISES_PATH = "exercises" -ANSWERS_PATH = "answers" -PATCHES_PATH = "patches/patches" - - -# Heals all the exercises. -def heal(): - maketree(ANSWERS_PATH) - - with os.scandir(EXERCISES_PATH) as it: - for entry in it: - name = entry.name - - original_path = entry.path - patch_path = os.path.join(PATCHES_PATH, patch_name(name)) - output_path = os.path.join(ANSWERS_PATH, name) - - patch(original_path, patch_path, output_path) - - -def main(): - heal() - - with os.scandir(EXERCISES_PATH) as it: - for entry in it: - name = entry.name - - broken_path = entry.path - healed_path = os.path.join(ANSWERS_PATH, name) - patch_path = os.path.join(PATCHES_PATH, patch_name(name)) - - with open(patch_path, "w") as file: - term = subprocess.run( - ["diff", broken_path, healed_path], - stdout=file, - text=True, - ) - assert term.returncode == 1 - - -def maketree(path): - return os.makedirs(path, exist_ok=True) - - -# Returns path with the patch extension. -def patch_name(path): - name, _ = os.path.splitext(path) - - return name + ".patch" - - -# Applies patch to original, and write the file to output. -def patch(original, patch, output): - subprocess.run( - ["patch", "-i", patch, "-o", output, original], stdout=IGNORE, check=True - ) - - -main() |
