Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions docs/nodetool_os.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,36 @@ Use cases:
- **exist_ok**: Don't error if directory already exists (bool)


## CreateTemporaryDirectory

Create a temporary directory on disk.

Use cases:
- Provide working directories for intermediate results
- Store ephemeral data across nodes

**Tags:** files, directory, temporary, create

**Fields:**
- **prefix**: Prefix for the directory name (str)
- **suffix**: Suffix for the directory name (str)
- **dir**: Parent directory for the temp directory (str)

## CreateTemporaryFile

Create a temporary file on disk.

Use cases:
- Provide scratch storage for workflows
- Generate unique filenames for intermediate data

**Tags:** files, temporary, create

**Fields:**
- **prefix**: Prefix for the temp file name (str)
- **suffix**: Suffix for the temp file name (str)
- **dir**: Directory where the file is created (str)

## CreatedTime

Get file creation timestamp.
Expand Down
49 changes: 49 additions & 0 deletions src/nodetool/nodes/nodetool/os.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
)

import subprocess
import tempfile


class GetEnvironmentVariable(BaseNode):
Expand Down Expand Up @@ -228,6 +229,54 @@ async def process(self, context: ProcessingContext):
os.makedirs(expanded_path, exist_ok=self.exist_ok)


class CreateTemporaryFile(BaseNode):
"""
Create a temporary file on disk.
files, temporary, create

Use cases:
- Provide scratch storage for workflows
- Generate unique filenames for intermediate data
"""

prefix: str = Field(default="", description="Prefix for the temp file name")
suffix: str = Field(default="", description="Suffix for the temp file name")
dir: str = Field(default="", description="Directory where the file is created")

async def process(self, context: ProcessingContext) -> FilePath:
if Environment.is_production():
raise ValueError("This node is not available in production")
tmp_dir = os.path.expanduser(self.dir) if self.dir else None
tmp = tempfile.NamedTemporaryFile(
prefix=self.prefix, suffix=self.suffix, dir=tmp_dir, delete=False
)
path = tmp.name
tmp.close()
return FilePath(path=path)


class CreateTemporaryDirectory(BaseNode):
"""
Create a temporary directory on disk.
files, directory, temporary, create

Use cases:
- Provide working directories for intermediate results
- Store ephemeral data across nodes
"""

prefix: str = Field(default="", description="Prefix for the directory name")
suffix: str = Field(default="", description="Suffix for the directory name")
dir: str = Field(default="", description="Parent directory for the temp directory")

async def process(self, context: ProcessingContext) -> FilePath:
if Environment.is_production():
raise ValueError("This node is not available in production")
tmp_dir = os.path.expanduser(self.dir) if self.dir else None
path = tempfile.mkdtemp(prefix=self.prefix, suffix=self.suffix, dir=tmp_dir)
return FilePath(path=path)


class GetFileSize(BaseNode):
"""
Get file size in bytes.
Expand Down
Loading
Loading