MCPcopy Create free account
hub / github.com/TUM-Dev/NavigaTUM / apply_roomcode_patch

Function apply_roomcode_patch

data/processors/patch.py:18–56  ·  view source on GitHub ↗

Apply patches to objects. Args: ---- objects: list of objects to apply patches to patches: list of patches to apply

(objects: dict[str, Entry], patches: list[Patch])

Source from the content-addressed store, hash-verified

16
17
18def apply_roomcode_patch(objects: dict[str, Entry], patches: list[Patch]) -> None:
19 """
20 Apply patches to objects.
21
22 Args:
23 ----
24 objects: list of objects to apply patches to
25 patches: list of patches to apply
26
27 """
28 compiled_patches: list[tuple[re.Pattern[str], dict[str, object]]] = [
29 (
30 re.compile(p["if_room_code"]),
31 {k: v for k, v in p.items() if k != "if_room_code"},
32 )
33 for p in patches
34 ]
35
36 to_delete = []
37 applied_patches: set[re.Pattern[str]] = set()
38 for room_code, room in objects.items():
39 for patch_check, patch in compiled_patches:
40 if patch_check.match(room_code) is not None:
41 applied_patches.add(patch_check)
42 if patch.get("__delete"):
43 to_delete.append(room_code)
44 continue
45 for patch_key, patched_value in patch.items():
46 room[patch_key] = patched_value
47 room["patched"] = True
48
49 for room_code in to_delete:
50 objects.pop(room_code)
51
52 for patch_check, _ in compiled_patches:
53 if patch_check not in applied_patches:
54 _logger.warning(
55 f"The patch for roomcode: r'{patch_check.pattern}' was never applied. Make sure it is still required.",
56 )

Callers 1

_clean_tumonline_roomsFunction · 0.90

Calls 1

popMethod · 0.80

Tested by

no test coverage detected