50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
import yaml
|
|
import uuid
|
|
import re
|
|
|
|
file_path = "gold_edition/template_windows_os_gold.yaml"
|
|
group_uuid_raw = "a571c0d144b14fd4a87a9d9b2aa9fcd6"
|
|
|
|
def is_valid_32_uuid(val):
|
|
# exact 32 hex chars
|
|
return bool(re.match(r'^[0-9a-f]{32}$', val.lower()))
|
|
|
|
with open(file_path, 'r', encoding='utf-8') as f:
|
|
content = yaml.safe_load(f)
|
|
|
|
# Update Group UUID
|
|
for group in content.get('template_groups', []):
|
|
if group['name'] == 'Templates/Applications':
|
|
group['uuid'] = group_uuid_raw
|
|
|
|
# Fix other UUIDs
|
|
uuid_map = {}
|
|
|
|
def fix(node):
|
|
if isinstance(node, dict):
|
|
if 'uuid' in node:
|
|
val = str(node['uuid']).replace('-', '') # Strip dashes if present
|
|
|
|
# If it matches our target group UUID, keep it
|
|
if val == group_uuid_raw:
|
|
node['uuid'] = val
|
|
elif not is_valid_32_uuid(val) or val.isdigit(): # regenerate if invalid OR if it looks like just numbers (failed manual fixes)
|
|
if val not in uuid_map:
|
|
uuid_map[val] = str(uuid.uuid4()).replace('-', '')
|
|
node['uuid'] = uuid_map[val]
|
|
else:
|
|
node['uuid'] = val # use stripped version
|
|
|
|
for k, v in node.items():
|
|
fix(v)
|
|
elif isinstance(node, list):
|
|
for item in node:
|
|
fix(item)
|
|
|
|
fix(content)
|
|
|
|
with open(file_path, 'w', encoding='utf-8') as f:
|
|
yaml.dump(content, f, sort_keys=False, allow_unicode=True)
|
|
|
|
print("UUIDs fixed (32 chars).")
|