-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathnuke_uids.py
More file actions
53 lines (40 loc) · 1.79 KB
/
nuke_uids.py
File metadata and controls
53 lines (40 loc) · 1.79 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import os
import re
# Set this to your specific mod folder directory to be 100% safe
# e.g., "res://Downfall" or "." for the current folder
TARGET_DIRECTORY = "."
# Regex pattern to match uid="uid://..." including any trailing space
UID_PATTERN = re.compile(r'\buid="uid://[^"]*"\s*')
def nuke_uids_in_file(file_path):
# CRITICAL: Skip if the file itself is a symlink
if os.path.islink(file_path):
return
try:
with open(file_path, 'r', encoding='utf-8') as f:
content = f.read()
if 'uid="uid://' in content:
cleaned_content = UID_PATTERN.sub('', content)
with open(file_path, 'w', encoding='utf-8') as f:
f.write(cleaned_content)
print(f"Cleaned UIDs from local file: {file_path}")
except Exception as e:
print(f"Error processing {file_path}: {e}")
def main():
print(f"Scanning '{os.path.abspath(TARGET_DIRECTORY)}' strictly for local physical files...")
target_extensions = ('.tscn', '.tres')
count = 0
for root, dirs, files in os.walk(TARGET_DIRECTORY):
# 1. Skip the engine internal cache folder
if '.godot' in root.split(os.sep):
continue
# 2. Prevent os.walk from stepping into symlinked directories
# Modifying the dirs list in-place lets us filter out symlinked folders dynamically
dirs[:] = [d for d in dirs if not os.path.islink(os.path.join(root, d))]
for file in files:
if file.endswith(target_extensions):
file_path = os.path.join(root, file)
nuke_uids_in_file(file_path)
count += 1
print(f"Done! Processed {count} local scene/resource files. Symlinks bypassed safely.")
if __name__ == "__main__":
main()