SLPDirectoryContents
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
from .single_line_picker import SLPSingleLinePicker
|
||||
from .slp_lora_loader import SLPLoraLoader, SLPLoraLoaderModelOnly
|
||||
from .slp_filename_prefix import SLPFilenamePrefix
|
||||
from .slp_directory_list import SLPDirectoryContents
|
||||
|
||||
NODE_CLASS_MAPPINGS = {
|
||||
SLPSingleLinePicker.NAME: SLPSingleLinePicker,
|
||||
SLPLoraLoader.NAME: SLPLoraLoader,
|
||||
SLPLoraLoaderModelOnly.NAME: SLPLoraLoaderModelOnly,
|
||||
SLPFilenamePrefix.NAME: SLPFilenamePrefix,
|
||||
SLPDirectoryContents.NAME: SLPDirectoryContents
|
||||
}
|
||||
|
||||
NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
@@ -14,6 +16,7 @@ NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
SLPLoraLoader.NAME: SLPLoraLoader.DISPLAY_NAME,
|
||||
SLPLoraLoaderModelOnly.NAME: SLPLoraLoaderModelOnly.DISPLAY_NAME,
|
||||
SLPFilenamePrefix.NAME: SLPFilenamePrefix.DISPLAY_NAME,
|
||||
SLPDirectoryContents.NAME: SLPDirectoryContents.DISPLAY_NAME,
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
from pathlib import Path
|
||||
|
||||
class SLPDirectoryContents:
|
||||
NAME = "HetimaSLPDirectoryContents"
|
||||
DISPLAY_NAME = "SLP Directory Contents"
|
||||
|
||||
CATEGORY = "SingleLinePicker"
|
||||
DESCRIPTION = "Outputs the contents of the directory."
|
||||
|
||||
# 毎回読み込む
|
||||
@classmethod
|
||||
def IS_CHANGED(cls):
|
||||
return float("NaN")
|
||||
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"path": ("STRING", {"multiline": False, "default": "", "tooltip": 'Path to directory'}),
|
||||
"is_full_path": ("BOOLEAN", {"default": True, "tooltip": "Outputs as full path"}),
|
||||
"SLP_format": ("BOOLEAN", {"default": False, "tooltip": "Outputs for SLP List View"}),
|
||||
"prefix": ("STRING", {"multiline": False, "default": "", "tooltip": "Prefix for each output path"}),
|
||||
},
|
||||
"optional": {
|
||||
},
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("STRING",)
|
||||
RETURN_NAMES = ("STRING",)
|
||||
OUTPUT_TOOLTIPS = ("directory contents",)
|
||||
OUTPUT_NODE = True
|
||||
FUNCTION = "execute"
|
||||
|
||||
def execute(self, path="", is_full_path=True, SLP_format=False, prefix=""):
|
||||
dir_path = Path(path)
|
||||
if not path or not dir_path.is_dir():
|
||||
return ("",)
|
||||
|
||||
files = sorted([f for f in dir_path.iterdir()])
|
||||
result_prefix = ""
|
||||
if SLP_format:
|
||||
result_prefix = "#dict\n"
|
||||
results = []
|
||||
for file in files:
|
||||
path_str = ""
|
||||
if is_full_path:
|
||||
path_str = str(file.resolve())
|
||||
else:
|
||||
path_str = file.name
|
||||
if prefix != "":
|
||||
path_str = prefix + path_str
|
||||
if SLP_format:
|
||||
path_str = file.name + ":" + path_str
|
||||
|
||||
results.append(path_str)
|
||||
|
||||
return (result_prefix + "\n".join(results),)
|
||||
Reference in New Issue
Block a user