Skip to content

Commit

Permalink
Add some directory manipulation nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyballentine committed Jan 27, 2024
1 parent 36c01c1 commit e36535c
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
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
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)
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

0 comments on commit e36535c

Please sign in to comment.