-
-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c63b74c
commit b0d4249
Showing
5 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
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
37 changes: 37 additions & 0 deletions
37
backend/src/packages/chaiNNer_standard/utility/directory/directory_go_up.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,37 @@ | ||
from __future__ import annotations | ||
|
||
from pathlib import Path | ||
|
||
from nodes.properties.inputs import DirectoryInput, NumberInput | ||
from nodes.properties.outputs import DirectoryOutput | ||
|
||
from .. import directory_group | ||
|
||
|
||
@directory_group.register( | ||
schema_id="chainner:utility:back_directory", | ||
name="Directory Go Up", | ||
description="Traverse up from a directory the specified number of times.", | ||
icon="BsFolder", | ||
inputs=[ | ||
DirectoryInput(must_exist=False, label_style="hidden"), | ||
NumberInput("Times", minimum=0, default=1, label_style="inline").with_docs( | ||
"How many times to go up.", | ||
"- 0 will return the given directory as is.", | ||
"- 1 will return the parent directory.", | ||
"- 2 will return the grandparent directory.", | ||
"- etc.", | ||
hint=True, | ||
), | ||
], | ||
outputs=[ | ||
DirectoryOutput( | ||
output_type="Directory { path: getParentDirectory(Input0.path, Input1) }", | ||
), | ||
], | ||
) | ||
def directory_go_up_node(directory: Path, amt: int) -> Path: | ||
result = directory | ||
for _ in range(amt): | ||
result = result.parent | ||
return result |
27 changes: 27 additions & 0 deletions
27
backend/src/packages/chaiNNer_standard/utility/directory/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,27 @@ | ||
from __future__ import annotations | ||
|
||
from pathlib import Path | ||
|
||
from nodes.properties.inputs import DirectoryInput | ||
from nodes.properties.outputs import TextOutput | ||
|
||
from .. import directory_group | ||
|
||
|
||
@directory_group.register( | ||
schema_id="chainner:utility:directory_to_text", | ||
name="Directory to Text", | ||
description="Converts a directory path into text.", | ||
icon="BsFolder", | ||
inputs=[ | ||
DirectoryInput(must_exist=False, label_style="hidden"), | ||
], | ||
outputs=[ | ||
TextOutput( | ||
"Dir Text", | ||
output_type="Input0.path", | ||
), | ||
], | ||
) | ||
def directory_to_text_node(directory: Path) -> str: | ||
return str(directory) |
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
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