diff --git a/rename-ai-snaps b/rename-ai-snaps index 5786998..02c743d 100755 --- a/rename-ai-snaps +++ b/rename-ai-snaps @@ -13,6 +13,7 @@ checkpoint model and LoRA names, and moves files into: import json import os import re +import shutil import sys import time from pathlib import Path @@ -355,12 +356,23 @@ def sanitize_dir_name(name): # ── main ─────────────────────────────────────────────────────────────────── +def nas_mount_base(): + """Return the NAS mount base path for this machine.""" + candidates = [ + "/mini.nas/miniShare1", + os.path.expanduser("~/mnt/mini.nas/miniShare1"), + os.path.expanduser("~/mnt/miniShare1"), + ] + for p in candidates: + if os.path.isdir(p): + return p + return candidates[-1] + + def main(): import argparse - DEFAULT_OUTPUT = os.path.expanduser( - "~/mnt/mini.nas/miniShare1/Pictures/Images/AI" - ) + DEFAULT_OUTPUT = os.path.join(nas_mount_base(), "Pictures", "Images", "AI") parser = argparse.ArgumentParser( description="Scan PNGs for AI prompt metadata and reorg into model/lora folders.", @@ -518,10 +530,10 @@ def main(): new_path = new_path.with_name(f"{stem}_{counter}{new_path.suffix}") counter += 1 try: - old_path.rename(new_path) + shutil.move(old_path, new_path) moved += 1 - except FileNotFoundError: - print(f" SKIPPED (not found): {old_path.name}") + except (FileNotFoundError, OSError) as e: + print(f" SKIPPED ({e}): {old_path.name}") print(f" Moved {moved} file(s)." if not args.dry_run else "") else: moved = 0 @@ -584,9 +596,9 @@ def main(): np = np.with_name(f"{stem}_{counter}{np.suffix}") counter += 1 try: - p.rename(np) - except FileNotFoundError: - print(f" SKIPPED (not found): {p.name}") + shutil.move(p, np) + except (FileNotFoundError, OSError) as e: + print(f" SKIPPED ({e}): {p.name}") moved += len(items) - i break else: @@ -606,10 +618,10 @@ def main(): counter += 1 print(f" (file existed, saved as {new_path.name})") try: - old_path.rename(new_path) + shutil.move(old_path, new_path) moved += 1 - except FileNotFoundError: - print(f" SKIPPED (not found): {old_path.name}") + except (FileNotFoundError, OSError) as e: + print(f" SKIPPED ({e}): {old_path.name}") i += 1 print(f"\n Moved: {moved} Skipped: {skipped}") diff --git a/sync-comfyui-snaps b/sync-comfyui-snaps index 6920f29..066b403 100755 --- a/sync-comfyui-snaps +++ b/sync-comfyui-snaps @@ -21,7 +21,6 @@ NIMO_SRC="/home/schmeeve/ComfyUI/output" SHARE="//mini.nas/miniShare1" NAS_SUBPATH="Pictures" -MOUNTPOINT="${HOME}/mnt/miniShare1" CREDENTIALS="${HOME}/.smb/mini.nas" RENAME_SCRIPT="${HOME}/git/schmeeve-toolz/rename-ai-snaps" @@ -30,22 +29,29 @@ ORGANIZE_SCRIPT="${HOME}/git/schmeeve-toolz/organize-images" START="$(date +%s)" echo "[sync-comfyui-snaps] Starting at $(date)" -# 1. Mount NAS if not already mounted -if mount | grep -q "${MOUNTPOINT}"; then - echo "[sync-comfyui-snaps] Already mounted at ${MOUNTPOINT}" +# 1. Determine NAS mount — use pre-mounted /mini.nas/miniShare1 on nimo.loc +# if available; otherwise mount via CIFS under ~/mnt/miniShare1 +if [ -d "/mini.nas/miniShare1" ]; then + MOUNTPOINT="/mini.nas/miniShare1" + echo "[sync-comfyui-snaps] Using existing mount at ${MOUNTPOINT}" else - echo "[sync-comfyui-snaps] Mounting ${SHARE} → ${MOUNTPOINT}" - mkdir -p "${MOUNTPOINT}" - OPTS="username=schmeeve,uid=$(id -u),gid=$(id -g),forceuid,forcegid,nounix,serverino" - if [ -f "${CREDENTIALS}" ]; then - OPTS="${OPTS},credentials=${CREDENTIALS}" + MOUNTPOINT="${HOME}/mnt/miniShare1" + if mount | grep -q "${MOUNTPOINT}"; then + echo "[sync-comfyui-snaps] Already mounted at ${MOUNTPOINT}" + else + echo "[sync-comfyui-snaps] Mounting ${SHARE} → ${MOUNTPOINT}" + mkdir -p "${MOUNTPOINT}" + OPTS="username=schmeeve,uid=$(id -u),gid=$(id -g),forceuid,forcegid,nounix,serverino" + if [ -f "${CREDENTIALS}" ]; then + OPTS="${OPTS},credentials=${CREDENTIALS}" + fi + sudo mount -t cifs "${SHARE}" "${MOUNTPOINT}" -o "${OPTS}" + if ! mount | grep -q "${MOUNTPOINT}"; then + echo "[sync-comfyui-snaps] ERROR: Failed to mount ${SHARE}" + exit 1 + fi + echo "[sync-comfyui-snaps] Mounted at ${MOUNTPOINT}" fi - sudo mount -t cifs "${SHARE}" "${MOUNTPOINT}" -o "${OPTS}" - if ! mount | grep -q "${MOUNTPOINT}"; then - echo "[sync-comfyui-snaps] ERROR: Failed to mount ${SHARE}" - exit 1 - fi - echo "[sync-comfyui-snaps] Mounted at ${MOUNTPOINT}" fi DEST="${MOUNTPOINT}/${NAS_SUBPATH}" @@ -67,9 +73,10 @@ rsync -vu --checksum \ "${SRC}" "${DEST}/" # 3. Rename AI snaps (non-interactive for automation) +AI_OUTPUT="${DEST}/Images/AI" if [ -x "${RENAME_SCRIPT}" ]; then - echo "[sync-comfyui-snaps] Running rename-ai-snaps on ${DEST}" - "${RENAME_SCRIPT}" "${DEST}" --no-interactive + echo "[sync-comfyui-snaps] Running rename-ai-snaps on ${DEST} → ${AI_OUTPUT}" + "${RENAME_SCRIPT}" "${DEST}" --output "${AI_OUTPUT}" --no-interactive else echo "[sync-comfyui-snaps] WARNING: rename-ai-snaps not found at ${RENAME_SCRIPT}" fi