65 lines
2.1 KiB
Python
65 lines
2.1 KiB
Python
# SPDX-License-Identifier: MIT
|
|
# Copyright (C) 2025 ComfyUI-Sharp Contributors
|
|
|
|
"""
|
|
Sharp PreStartup Script
|
|
Copies example assets to ComfyUI input folder on startup.
|
|
"""
|
|
import os
|
|
import shutil
|
|
|
|
|
|
def copy_assets():
|
|
"""Copy all files from assets/ directory to ComfyUI input/ directory."""
|
|
try:
|
|
import folder_paths
|
|
|
|
input_folder = folder_paths.get_input_directory()
|
|
custom_node_dir = os.path.dirname(os.path.abspath(__file__))
|
|
assets_folder = os.path.join(custom_node_dir, "assets")
|
|
|
|
if not os.path.exists(assets_folder):
|
|
print(f"[SHARP] Warning: assets folder not found at {assets_folder}")
|
|
return
|
|
|
|
copied_count = 0
|
|
for root, dirs, files in os.walk(assets_folder):
|
|
# Skip hidden directories like .ipynb_checkpoints
|
|
dirs[:] = [d for d in dirs if not d.startswith('.')]
|
|
|
|
# Calculate relative path from assets folder
|
|
rel_path = os.path.relpath(root, assets_folder)
|
|
|
|
# Create corresponding subdirectory in destination
|
|
if rel_path != '.':
|
|
dest_dir = os.path.join(input_folder, rel_path)
|
|
os.makedirs(dest_dir, exist_ok=True)
|
|
else:
|
|
dest_dir = input_folder
|
|
|
|
# Copy files (skip hidden files)
|
|
for file in files:
|
|
if file.startswith('.'):
|
|
continue
|
|
|
|
source_file = os.path.join(root, file)
|
|
dest_file = os.path.join(dest_dir, file)
|
|
|
|
if not os.path.exists(dest_file):
|
|
shutil.copy2(source_file, dest_file)
|
|
copied_count += 1
|
|
rel_dest = os.path.join(rel_path, file) if rel_path != '.' else file
|
|
print(f"[SHARP] Copied {rel_dest} to input/")
|
|
|
|
if copied_count > 0:
|
|
print(f"[SHARP] Copied {copied_count} asset(s) to {input_folder}")
|
|
else:
|
|
print(f"[SHARP] All assets already exist in {input_folder}")
|
|
|
|
except Exception as e:
|
|
print(f"[SHARP] Error copying assets: {e}")
|
|
|
|
|
|
# Run on import
|
|
copy_assets()
|