Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update/griptape1.1.0 #5

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
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
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

<!-- ## [Unreleased]

### Added
### Changed
### Deprecated
### Removed
### Fixed
### Security -->

## [0.3.00] - 2025-04-01
### Added
- [CHANGELOG.md](CHANGELOG.md)
- Added note in metadata_tool [README.md](docs/file_extras/tools/metadata_tool/README.md) about requiring [exiftool](https://exiftool.org/).

### Changed
- Updated to `Griptape Framework 1.1.0`
- Updated metadata tool to use `os.path.abspath` for filepath
- Updated metadata tool to check for `ExifTool`
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ A Griptape repository for working with files.

### Tools

* [Metadata Tool](docs/file_extras/tools/metadata_tool/README.md) - Will read and write metadata from a file.
* [Open File Tool](docs/file_extras/tools/open_file_tool/README.md) - Will open any file using the user's default application for that file type.

## Installing
Expand Down
5 changes: 4 additions & 1 deletion docs/file_extras/tools/metadata_tool/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,7 @@ will output:
- sword
- clouds
- sun
```
```

## Requirements
This tool requires [ExifTool](https://exiftool.org/) to be installed on your system. Please follow the installation instructions for your particular operating system.
20 changes: 19 additions & 1 deletion griptape/file_extras/tools/metadata_tool/metadata.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import subprocess
import json
import os
import subprocess


class Metadata:
Expand All @@ -8,11 +9,28 @@ class Metadata:
"""

def __init__(self, file_path: str):
if not self._check_exiftool():
raise EnvironmentError("ExifTool is not installed or not found in PATH.")
if not os.path.exists(file_path):
raise FileNotFoundError(f"File not found: {file_path}")
self.file = file_path
self.data = {}
self.flag = {}
self.get()

def _check_exiftool(self):
"""Check if ExifTool is available on the system."""
try:
result = subprocess.run(
["exiftool", "-ver"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
)
return result.returncode == 0
except FileNotFoundError:
return False

def get(self):
"""Extract metadata from a file using ExifTool and store it as a dictionary."""
try:
Expand Down
23 changes: 16 additions & 7 deletions griptape/file_extras/tools/metadata_tool/tool.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from griptape.file_extras.tools.metadata_tool.metadata import Metadata
from griptape.utils.decorators import activity
import os

from schema import Literal, Schema

from griptape.artifacts import TextArtifact
from griptape.file_extras.tools.metadata_tool.metadata import Metadata
from griptape.tools import BaseTool
from schema import Literal, Schema
from griptape.utils.decorators import activity


class MetadataTool(BaseTool):
Expand All @@ -23,9 +26,12 @@ class MetadataTool(BaseTool):
),
}
)
def read_metadata(self, image_path: str) -> TextArtifact:
def read_metadata(self, params: dict) -> TextArtifact:
"""Extract metadata from a file using ExifTool."""
metadata_obj = Metadata(image_path)
# get the file path from the parameters
image_path = params["values"]["image_path"]
absolute_path = os.path.abspath(image_path)
metadata_obj = Metadata(file_path=absolute_path)
return TextArtifact(metadata_obj.data)

@activity(
Expand All @@ -45,8 +51,11 @@ def read_metadata(self, image_path: str) -> TextArtifact:
),
}
)
def write_metadata(self, image_path: str, kv_pairs: dict) -> TextArtifact:
def write_metadata(self, params: dict) -> TextArtifact:
"""Writes metadata to a file using ExifTool."""
metadata_obj = Metadata(image_path)
image_path = params["values"]["image_path"]
absolute_path = os.path.abspath(image_path)
kv_pairs = params["values"]["kv_pairs"]
metadata_obj = Metadata(file_path=absolute_path)
metadata_obj.set(**kv_pairs)
return TextArtifact(metadata_obj.data)
Loading