Files
TheOnlyAaron-comfyui-pipedream/core/utils.py
T
Claude ec2d8fe326 Implement full Pipedream node pack (v0.1.0)
Seven production pipeline utility nodes for ComfyUI:
- PD Project Context: top-level metadata/token source
- PD Shot Token: lightweight template string resolver
- PD Output Namer: structured output filename builder
- PD Network Output: image writer with UNC path support
- PD Switch: multi-channel wildcard input router (up to 8×8)
- PD Wedge: iteration node with optional auto-queue injection
- PD Rasterizer: dry-run wedge cartesian product previewer

Core infrastructure:
- core/compat.py: legacy + Nodes 2.0 (V3) API compatibility shim
- core/tokens.py: standalone token resolution engine
- core/utils.py: path normalization and directory helpers
- web/pipedream_rasterizer.js: minimal JS for rasterizer preview

https://claude.ai/code/session_015UV4rjSvFatMiNtKhd1sT3
2026-04-03 01:08:21 +00:00

44 lines
1.2 KiB
Python

"""
Shared utility helpers for Pipedream nodes.
Path normalization, directory creation, and other small helpers that
multiple node modules rely on.
"""
import os
import sys
def normalize_path(path: str) -> str:
"""
Normalize slashes for the current platform.
On Windows, forward slashes become backslashes and UNC prefixes
(``\\\\server\\share``) are preserved. On POSIX, backslashes become
forward slashes. Trailing separators are stripped.
"""
if sys.platform == "win32":
path = path.replace("/", "\\")
else:
path = path.replace("\\", "/")
return path.rstrip(os.sep)
def ensure_directory(path: str, create: bool = True) -> str:
"""
Return the directory portion of *path*, optionally creating it.
Raises ``OSError`` with a descriptive message on failure.
"""
directory = os.path.dirname(path)
if not directory:
return directory
if create and not os.path.isdir(directory):
try:
os.makedirs(directory, exist_ok=True)
except OSError as exc:
raise OSError(
f"[Pipedream] Failed to create directory '{directory}': {exc}"
) from exc
return directory