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