Files
Alchemist/scripts/cucholix/format_repo5.py
2025-05-23 19:51:22 -07:00

46 lines
1.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import os
import shutil
import re
import unicodedata
import sys
def sanitize_name(name):
normalized = unicodedata.normalize('NFKD', name).encode('ascii', 'ignore').decode('ascii')
return normalized.replace("'", "").replace("", "").replace("`", "").replace('"', '')
def create_formatted_structure(root_folder):
formatted_path = os.path.join(root_folder, 'formatted')
os.makedirs(formatted_path, exist_ok=True)
print(f"Creating formatted structure at: {formatted_path}")
for root, dirs, files in os.walk(root_folder):
for file in files:
if file.endswith('.pchtxt'):
version = file.replace('.pchtxt', '').strip()
# Determine game name: it's the folder just above the .pchtxt file
game_name = os.path.basename(os.path.dirname(os.path.join(root, file)))
game_name = sanitize_name(game_name)
mod_name = "Graphics Mods"
target_dir = os.path.join(formatted_path, f"{game_name} - {mod_name}")
os.makedirs(target_dir, exist_ok=True)
source_path = os.path.join(root, file)
dest_path = os.path.join(target_dir, f"{version}.pchtxt")
shutil.copy2(source_path, dest_path)
print(f"Copied {source_path}{dest_path}")
def main(folder_path):
create_formatted_structure(folder_path)
print("Done!")
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python collect_graphics_mods.py /path/to/root/folder")
sys.exit(1)
folder_path = sys.argv[1]
main(folder_path)