-
-
Notifications
You must be signed in to change notification settings - Fork 438
Delete file in TagStudio #282
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
Merged
CyanVoxel
merged 7 commits into
TagStudioDev:file-deletion
from
PeterBouSaada:Delete-Files
Aug 26, 2024
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7fafb06
Added the option to delete files in the right click context menu
PeterBouSaada b6b66ae
Reformatted with Ruff
PeterBouSaada 531554c
Removed unused import
PeterBouSaada eb18230
Updated to use pathlib instead of os
PeterBouSaada a1a695c
- removed unused imports
PeterBouSaada d867238
Swapped stacktrace to logging.exception in `file_deleter.py`
PeterBouSaada 21fab01
Merge branch 'Alpha-v9.4' into Delete-Files
CyanVoxel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,41 @@ | ||
| import logging | ||
| import pathlib | ||
| import subprocess | ||
| import sys | ||
| import traceback | ||
| from pathlib import Path | ||
| from typing import Callable | ||
PeterBouSaada marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ERROR = f"[ERROR]" | ||
| WARNING = f"[WARNING]" | ||
| INFO = f"[INFO]" | ||
|
|
||
| logging.basicConfig(format="%(message)s", level=logging.INFO) | ||
|
|
||
|
|
||
| def delete_file(path: str | Path, callback: Callable): | ||
| _path = str(path) | ||
| _file = Path(_path) | ||
| logging.info(f"Deleting file: {_path}") | ||
| if not _file.exists(): | ||
| logging.error(f"File not found: {_path}") | ||
| return | ||
| try: | ||
| _file.unlink() | ||
| callback() | ||
| except: | ||
| traceback.print_exc() | ||
PeterBouSaada marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| class FileDeleterHelper: | ||
| def __init__(self, filepath: str | Path): | ||
| self.filepath = str(filepath) | ||
|
|
||
| def set_filepath(self, filepath: str | Path): | ||
| self.filepath = str(filepath) | ||
PeterBouSaada marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| def set_delete_callback(self, callback: Callable): | ||
| self.delete_callback = callback | ||
|
|
||
| def delete_file(self): | ||
| delete_file(self.filepath, self.delete_callback) | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.