forked from Meisoftcoltd/ComfyUI-Sequential-Batcher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpaths.py
More file actions
45 lines (38 loc) · 1.54 KB
/
paths.py
File metadata and controls
45 lines (38 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import pathlib
from folder_paths import folder_names_and_paths
from . import register_node
folder_types = tuple(sorted(folder_names_and_paths.keys()))
folder_default = "checkpoint" if "checkpoint" in folder_types else folder_types[0]
@register_node
class ModelFinder:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"filenames": ("SEQUENCE", ),
"model_type": (folder_types, {"default": folder_default}),
"recursive": ("BOOLEAN", {"default": True}),
"skip_missing": ("BOOLEAN", {"default": False}),
},
}
RETURN_TYPES = ("SEQUENCE", "SEQUENCE")
RETURN_NAMES = ("paths", "stems")
FUNCTION = "go"
CATEGORY = "🔁 Sequential Batcher/Sequence"
def find_models(self, fn, paths, recursive):
for p in paths:
for f in (p.rglob(fn) if recursive else p.glob(fn)):
yield f.relative_to(p)
def go(self, filenames, model_type, recursive, skip_missing):
paths = [pathlib.Path(folder) for folder in folder_names_and_paths[model_type][0]]
result = []
for fn in filenames:
if '..' in fn:
raise Exception(f'".." is not allowed: {fn}.')
found = False
for f in self.find_models(fn, paths, recursive):
found = True
result.append(f)
if not found and not skip_missing:
raise Exception(f'Could not find file: {fn}')
return ([str(f) for f in result], [f.stem for f in result])