forked from ietf-tools/datatracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch_libraries.py
More file actions
31 lines (25 loc) · 1.26 KB
/
Copy pathpatch_libraries.py
File metadata and controls
31 lines (25 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Copyright The IETF Trust 2024, All Rights Reserved
import django
from django.conf import settings
from django.core.management.base import BaseCommand, CommandError
from pathlib import Path
from ietf.utils import patch
class Command(BaseCommand):
"""Apply IETF patches to libraries"""
requires_system_checks = tuple()
def handle(self, *args, **options):
library_path = Path(django.__file__).parent.parent
top_dir = Path(settings.BASE_DIR).parent
# All patches in settings.CHECKS_LIBRARY_PATCHES_TO_APPLY must have a
# relative file path starting from the site-packages dir, e.g.
# 'django/db/models/fields/__init__.py'
for patch_file in settings.CHECKS_LIBRARY_PATCHES_TO_APPLY:
patch_set = patch.fromfile(top_dir / Path(patch_file))
if not patch_set:
raise CommandError(f"Could not parse patch file '{patch_file}'")
if not patch_set.apply(root=bytes(library_path)):
raise CommandError(f"Could not apply the patch from '{patch_file}'")
if patch_set.already_patched:
self.stdout.write(f"Patch from '{patch_file}' was already applied")
else:
self.stdout.write(f"Applied the patch from '{patch_file}'")