-
-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some directory manipulation nodes
- Loading branch information
1 parent
36c01c1
commit e36535c
Showing
3 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
backend/src/packages/chaiNNer_standard/utility/directories/back_directory.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
29 changes: 29 additions & 0 deletions
29
backend/src/packages/chaiNNer_standard/utility/directories/directory_to_text.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
35 changes: 35 additions & 0 deletions
35
backend/src/packages/chaiNNer_standard/utility/directories/into_directory.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |