diff --git a/backend/src/packages/chaiNNer_standard/utility/directories/back_directory.py b/backend/src/packages/chaiNNer_standard/utility/directories/back_directory.py new file mode 100644 index 000000000..88b5fe903 --- /dev/null +++ b/backend/src/packages/chaiNNer_standard/utility/directories/back_directory.py @@ -0,0 +1,30 @@ +from __future__ import annotations + +from pathlib import Path + +from nodes.properties.inputs import DirectoryInput, NumberInput +from nodes.properties.outputs import DirectoryOutput + +from .. import value_group + + +@value_group.register( + schema_id="chainner:utility:back_directory", + name="Back Directory", + description="Traverse up/back from a directory the specified number of times.", + icon="BsFolder", + inputs=[ + DirectoryInput( + "Directory", must_exist=False, label_style="hidden", has_handle=True + ), + NumberInput("Amount back", has_handle=True, minimum=1, precision=0), + ], + outputs=[ + DirectoryOutput("Directory"), + ], +) +def back_directory_node(directory: Path, amt: int) -> Path: + result = directory + for _ in range(amt): + result = result.parent + return result diff --git a/backend/src/packages/chaiNNer_standard/utility/directories/directory_to_text.py b/backend/src/packages/chaiNNer_standard/utility/directories/directory_to_text.py new file mode 100644 index 000000000..2d122a63b --- /dev/null +++ b/backend/src/packages/chaiNNer_standard/utility/directories/directory_to_text.py @@ -0,0 +1,29 @@ +from __future__ import annotations + +from pathlib import Path + +from nodes.properties.inputs import DirectoryInput +from nodes.properties.outputs import TextOutput + +from .. import value_group + + +@value_group.register( + schema_id="chainner:utility:directory_to_text", + name="Directory to Text", + description="Converts a directory path into usable text.", + icon="BsFolder", + inputs=[ + DirectoryInput( + "Directory", must_exist=False, label_style="hidden", has_handle=True + ), + ], + outputs=[ + TextOutput( + "Directory Text", + output_type="Input0.path", + ), + ], +) +def directory_to_text_node(directory: Path) -> str: + return str(directory) diff --git a/backend/src/packages/chaiNNer_standard/utility/directories/into_directory.py b/backend/src/packages/chaiNNer_standard/utility/directories/into_directory.py new file mode 100644 index 000000000..032d9b29a --- /dev/null +++ b/backend/src/packages/chaiNNer_standard/utility/directories/into_directory.py @@ -0,0 +1,35 @@ +from __future__ import annotations + +import sys +from pathlib import Path + +from nodes.properties.inputs import DirectoryInput, TextInput +from nodes.properties.outputs import DirectoryOutput + +from .. import value_group + +separator = "/" if sys.platform == "linux" else r"\\" + + +@value_group.register( + schema_id="chainner:utility:into_directory", + name="Into Directory", + description="Goes forward into a directory.", + icon="BsFolder", + inputs=[ + DirectoryInput( + "Directory", must_exist=False, label_style="hidden", has_handle=True + ), + TextInput("Folder", has_handle=True), + ], + outputs=[ + DirectoryOutput( + "Directory", + output_type='Directory { path: string::concat(Input0.path, "' + + separator + + '", Input1) }', + ), + ], +) +def into_directory_node(directory: Path, folder: str) -> Path: + return directory / folder