Files
sn0w12-ComfyUI-Sn0w-Scripts/src/check_folder_paths.py
T
2024-06-29 21:52:15 +02:00

34 lines
1021 B
Python

import json
import os
import folder_paths
from ..sn0w import Logger
def check_lora_folders():
logger = Logger()
custom_paths = ["loras_15", "loras_xl", "loras_3"]
existing_paths = []
dir_path = os.path.dirname(os.path.realpath(__file__))
if os.path.basename(dir_path) == "src":
dir_path = os.path.dirname(dir_path)
json_path = os.path.join(dir_path, "web/settings/sn0w_settings.json")
# Ensure the directory exists
os.makedirs(os.path.dirname(json_path), exist_ok=True)
for path in custom_paths:
try:
lora_path = folder_paths.get_filename_list(path)
if lora_path:
existing_paths.append(path)
except Exception as e:
logger.log(f"{path} doesn't exist: {e}", "WARNING")
# Write the result to a JSON file in /web/settings
data = {"loaders_enabled": existing_paths}
with open(json_path, "w", encoding="utf-8") as json_file:
json.dump(data, json_file, indent=4)
return existing_paths