feat: Bump version to 0.4.4, add logging for file renaming operations, and update test filenames
This commit is contained in:
BIN
dist/renamer-0.4.4-py3-none-any.whl
vendored
Normal file
BIN
dist/renamer-0.4.4-py3-none-any.whl
vendored
Normal file
Binary file not shown.
@@ -1,6 +1,6 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "renamer"
|
name = "renamer"
|
||||||
version = "0.4.3"
|
version = "0.4.4"
|
||||||
description = "Terminal-based media file renamer and metadata viewer"
|
description = "Terminal-based media file renamer and metadata viewer"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.11"
|
requires-python = ">=3.11"
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ class RenamerApp(App):
|
|||||||
self.scan_files()
|
self.scan_files()
|
||||||
|
|
||||||
def scan_files(self):
|
def scan_files(self):
|
||||||
|
logging.info("scan_files called")
|
||||||
if not self.scan_dir or not self.scan_dir.exists() or not self.scan_dir.is_dir():
|
if not self.scan_dir or not self.scan_dir.exists() or not self.scan_dir.is_dir():
|
||||||
details = self.query_one("#details", Static)
|
details = self.query_one("#details", Static)
|
||||||
details.update("Error: Directory does not exist or is not a directory")
|
details.update("Error: Directory does not exist or is not a directory")
|
||||||
@@ -213,8 +214,12 @@ class RenamerApp(App):
|
|||||||
|
|
||||||
def update_renamed_file(self, old_path: Path, new_path: Path):
|
def update_renamed_file(self, old_path: Path, new_path: Path):
|
||||||
"""Update the tree node for a renamed file."""
|
"""Update the tree node for a renamed file."""
|
||||||
tree = self.query_one("#file_tree", Tree)
|
logging.info(f"update_renamed_file called with old_path={old_path}, new_path={new_path}")
|
||||||
|
|
||||||
|
tree = self.query_one("#file_tree", Tree)
|
||||||
|
logging.info(f"Before update: cursor_node.data = {tree.cursor_node.data if tree.cursor_node else None}")
|
||||||
|
|
||||||
|
# Update only the specific node
|
||||||
def find_node(node):
|
def find_node(node):
|
||||||
if node.data == old_path:
|
if node.data == old_path:
|
||||||
return node
|
return node
|
||||||
@@ -226,14 +231,27 @@ class RenamerApp(App):
|
|||||||
|
|
||||||
node = find_node(tree.root)
|
node = find_node(tree.root)
|
||||||
if node:
|
if node:
|
||||||
|
logging.info(f"Found node for {old_path}, updating to {new_path.name}")
|
||||||
node.label = escape(new_path.name)
|
node.label = escape(new_path.name)
|
||||||
node.data = new_path
|
node.data = new_path
|
||||||
# If this node is currently selected, refresh the details
|
logging.info(f"After update: node.data = {node.data}, node.label = {node.label}")
|
||||||
if tree.cursor_node == node:
|
# Ensure cursor stays on the renamed file
|
||||||
self._start_loading_animation()
|
tree.select_node(node)
|
||||||
threading.Thread(
|
logging.info(f"Selected node: {tree.cursor_node.data if tree.cursor_node else None}")
|
||||||
target=self._extract_and_show_details, args=(new_path,)
|
else:
|
||||||
).start()
|
logging.info(f"No node found for {old_path}")
|
||||||
|
|
||||||
|
logging.info(f"After update: cursor_node.data = {tree.cursor_node.data if tree.cursor_node else None}")
|
||||||
|
|
||||||
|
# Refresh the details if the node is currently selected
|
||||||
|
if tree.cursor_node and tree.cursor_node.data == new_path:
|
||||||
|
logging.info("Refreshing details for renamed file")
|
||||||
|
self._start_loading_animation()
|
||||||
|
threading.Thread(
|
||||||
|
target=self._extract_and_show_details, args=(new_path,)
|
||||||
|
).start()
|
||||||
|
else:
|
||||||
|
logging.info("Not refreshing details, cursor not on renamed file")
|
||||||
|
|
||||||
def on_key(self, event):
|
def on_key(self, event):
|
||||||
if event.key == "right":
|
if event.key == "right":
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ from textual.widgets import Input, Button, Static
|
|||||||
from textual.containers import Vertical, Horizontal, Center, Container
|
from textual.containers import Vertical, Horizontal, Center, Container
|
||||||
from textual.markup import escape
|
from textual.markup import escape
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import logging
|
||||||
|
|
||||||
|
|
||||||
class OpenScreen(Screen):
|
class OpenScreen(Screen):
|
||||||
@@ -128,6 +129,7 @@ class RenameConfirmScreen(Screen):
|
|||||||
self.old_path = old_path
|
self.old_path = old_path
|
||||||
self.new_name = new_name
|
self.new_name = new_name
|
||||||
self.new_path = old_path.parent / new_name
|
self.new_path = old_path.parent / new_name
|
||||||
|
self.was_edited = False
|
||||||
|
|
||||||
def compose(self):
|
def compose(self):
|
||||||
from .formatters.text_formatter import TextFormatter
|
from .formatters.text_formatter import TextFormatter
|
||||||
@@ -165,6 +167,7 @@ Do you want to proceed with renaming?
|
|||||||
if event.input.id == "new_name_input":
|
if event.input.id == "new_name_input":
|
||||||
self.new_name = event.input.value
|
self.new_name = event.input.value
|
||||||
self.new_path = self.old_path.parent / self.new_name
|
self.new_path = self.old_path.parent / self.new_name
|
||||||
|
self.was_edited = True
|
||||||
# Update the display
|
# Update the display
|
||||||
from .formatters.text_formatter import TextFormatter
|
from .formatters.text_formatter import TextFormatter
|
||||||
display = self.query_one("#new_name_display", Static)
|
display = self.query_one("#new_name_display", Static)
|
||||||
@@ -173,6 +176,7 @@ Do you want to proceed with renaming?
|
|||||||
def on_button_pressed(self, event):
|
def on_button_pressed(self, event):
|
||||||
if event.button.id == "rename":
|
if event.button.id == "rename":
|
||||||
try:
|
try:
|
||||||
|
logging.info(f"Renaming {self.old_path} to {self.new_path}")
|
||||||
self.old_path.rename(self.new_path)
|
self.old_path.rename(self.new_path)
|
||||||
# Update the tree node
|
# Update the tree node
|
||||||
self.app.update_renamed_file(self.old_path, self.new_path) # type: ignore
|
self.app.update_renamed_file(self.old_path, self.new_path) # type: ignore
|
||||||
@@ -222,6 +226,7 @@ Do you want to proceed with renaming?
|
|||||||
if event.key == "y":
|
if event.key == "y":
|
||||||
# Trigger rename
|
# Trigger rename
|
||||||
try:
|
try:
|
||||||
|
logging.info(f"Hotkey renaming {self.old_path} to {self.new_path}")
|
||||||
self.old_path.rename(self.new_path)
|
self.old_path.rename(self.new_path)
|
||||||
# Update the tree node
|
# Update the tree node
|
||||||
self.app.update_renamed_file(self.old_path, self.new_path) # type: ignore
|
self.app.update_renamed_file(self.old_path, self.new_path) # type: ignore
|
||||||
|
|||||||
Reference in New Issue
Block a user