Add YAPF style + ignore, and format tracked Python files

This commit is contained in:
2025-12-29 18:42:02 -08:00
parent c019c00aed
commit 507946a3e4
108 changed files with 11664 additions and 6494 deletions

View File

@@ -16,7 +16,7 @@ from datetime import datetime
# Add parent directory to path for imports
sys.path.insert(0, str(Path(__file__).parent.parent))
from SYS.utils import format_metadata_value
from config import load_config
from SYS.config import load_config
logger = logging.getLogger(__name__)
@@ -25,7 +25,9 @@ class ExportModal(ModalScreen):
"""Modal screen for exporting files with metadata and tags."""
BINDINGS = [
Binding("escape", "cancel", "Cancel"),
Binding("escape",
"cancel",
"Cancel"),
]
CSS_PATH = "export.tcss"
@@ -59,9 +61,12 @@ class ExportModal(ModalScreen):
self.libraries_select: Optional[Select] = None
self.size_input: Optional[Input] = None
self.format_select: Optional[Select] = None
self.file_ext: Optional[str] = None # Store the file extension for format filtering
self.file_type: Optional[str] = None # Store the file type (audio, video, image, document)
self.default_format: Optional[str] = None # Store the default format to set after mount
self.file_ext: Optional[
str] = None # Store the file extension for format filtering
self.file_type: Optional[
str] = None # Store the file type (audio, video, image, document)
self.default_format: Optional[
str] = None # Store the default format to set after mount
def _determine_file_type(self, ext: str) -> tuple[str, list]:
"""Determine file type from extension and return type and format options.
@@ -108,7 +113,7 @@ class ExportModal(ModalScreen):
options = [("Local", "local")]
try:
from config import (
from SYS.config import (
load_config,
get_hydrus_access_key,
get_hydrus_url,
@@ -133,7 +138,8 @@ class ExportModal(ModalScreen):
def _get_metadata_text(self) -> str:
"""Format metadata from result data in a consistent display format."""
metadata = self.result_data.get("metadata", {})
metadata = self.result_data.get("metadata",
{})
source = self.result_data.get("source", "unknown")
logger.info(
f"_get_metadata_text called - source: {source}, metadata type: {type(metadata)}, keys: {list(metadata.keys()) if metadata else 'empty'}"
@@ -173,7 +179,9 @@ class ExportModal(ModalScreen):
# If we found any fields, display them
if lines:
logger.info(f"_get_metadata_text - Returning {len(lines)} formatted metadata lines")
logger.info(
f"_get_metadata_text - Returning {len(lines)} formatted metadata lines"
)
return "\n".join(lines)
else:
logger.info(f"_get_metadata_text - No matching fields found in metadata")
@@ -205,7 +213,14 @@ class ExportModal(ModalScreen):
with Vertical(id="export-options"):
# Export To selector
self.export_to_select = Select(
[("0x0", "0x0"), ("Libraries", "libraries"), ("Custom Path", "path")],
[
("0x0",
"0x0"),
("Libraries",
"libraries"),
("Custom Path",
"path")
],
id="export-to-select",
)
yield self.export_to_select
@@ -217,12 +232,14 @@ class ExportModal(ModalScreen):
# Custom path input (initially hidden)
self.custom_path_input = Input(
placeholder="Enter custom export path", id="custom-path-input"
placeholder="Enter custom export path",
id="custom-path-input"
)
yield self.custom_path_input
# Get metadata for size and format options
metadata = self.result_data.get("metadata", {})
metadata = self.result_data.get("metadata",
{})
original_size = metadata.get("size", "")
ext = metadata.get("ext", "")
@@ -233,9 +250,10 @@ class ExportModal(ModalScreen):
# Format size in MB for display
if original_size:
size_mb = (
int(original_size / (1024 * 1024))
if isinstance(original_size, (int, float))
else original_size
int(original_size /
(1024 * 1024)) if isinstance(original_size,
(int,
float)) else original_size
)
size_display = f"{size_mb}Mb"
else:
@@ -259,11 +277,8 @@ class ExportModal(ModalScreen):
ext_lower = ext.lower().lstrip(".") # Remove leading dot if present
# Try to find matching format option
for _, value in format_options:
if value and (
ext_lower == value
or f".{ext_lower}" == ext
or ext.endswith(f".{value}")
):
if value and (ext_lower == value or f".{ext_lower}" == ext
or ext.endswith(f".{value}")):
default_format = value
logger.debug(f"Matched extension {ext} to format {value}")
break
@@ -348,11 +363,13 @@ class ExportModal(ModalScreen):
try:
tags_text = self.tags_textarea.text.strip()
export_to = self.export_to_select.value if self.export_to_select else "0x0"
custom_path = self.custom_path_input.value.strip() if self.custom_path_input else ""
custom_path = self.custom_path_input.value.strip(
) if self.custom_path_input else ""
# Get library value - handle Select.BLANK case
library = "local" # default
if self.libraries_select and str(self.libraries_select.value) != "Select.BLANK":
if self.libraries_select and str(self.libraries_select.value
) != "Select.BLANK":
library = str(self.libraries_select.value)
elif self.libraries_select and self.libraries_select:
# If value is Select.BLANK, try to get from the options
@@ -360,7 +377,8 @@ class ExportModal(ModalScreen):
# Get first available library option as fallback
options = self._get_library_options()
if options:
library = options[0][1] # Get the value part of first option tuple
library = options[0][
1] # Get the value part of first option tuple
except Exception:
library = "local"
@@ -376,11 +394,14 @@ class ExportModal(ModalScreen):
# For Hydrus export, filter out metadata-only tags (hash:, url:, relationship:)
if export_to == "libraries" and library == "hydrus":
metadata_prefixes = {"hash:", "url:", "relationship:"}
metadata_prefixes = {"hash:",
"url:",
"relationship:"}
export_tags = {
tag
for tag in export_tags
if not any(tag.lower().startswith(prefix) for prefix in metadata_prefixes)
for tag in export_tags if not any(
tag.lower().startswith(prefix) for prefix in metadata_prefixes
)
}
logger.info(
f"Filtered tags for Hydrus - removed metadata tags, {len(export_tags)} tags remaining"
@@ -391,9 +412,8 @@ class ExportModal(ModalScreen):
if title:
# Add the full title as a tag if not already present
title_tag = f"title:{title}"
if title_tag not in export_tags and not any(
t.startswith("title:") for t in export_tags
):
if title_tag not in export_tags and not any(t.startswith("title:")
for t in export_tags):
export_tags.add(title_tag)
# Extract individual words from title as searchable tags (if reasonable length)
@@ -427,7 +447,8 @@ class ExportModal(ModalScreen):
# Clean up word (remove punctuation)
clean_word = "".join(c for c in word if c.isalnum())
# Only add if not a stop word and has some length
if clean_word and len(clean_word) > 2 and clean_word not in stop_words:
if clean_word and len(
clean_word) > 2 and clean_word not in stop_words:
if clean_word not in export_tags:
export_tags.add(clean_word)
logger.info(
@@ -441,7 +462,9 @@ class ExportModal(ModalScreen):
return
if export_to == "libraries" and not export_tags:
logger.warning("No actual tags for Hydrus export (only metadata was present)")
logger.warning(
"No actual tags for Hydrus export (only metadata was present)"
)
# Don't return - allow export to continue, file will be added to Hydrus even without tags
# Determine export path
@@ -457,7 +480,8 @@ class ExportModal(ModalScreen):
export_path = export_to # "0x0"
# Get metadata from result_data
metadata = self.result_data.get("metadata", {})
metadata = self.result_data.get("metadata",
{})
# Extract file source info from result_data (passed by hub-ui)
file_hash = self.result_data.get("hash")
@@ -528,11 +552,8 @@ def determine_needs_conversion(current_ext: str, target_format: str) -> bool:
True if conversion is needed, False if it's already the target format
"""
# Handle NoSelection or None
if (
not target_format
or target_format == ""
or str(target_format.__class__.__name__) == "NoSelection"
):
if (not target_format or target_format == ""
or str(target_format.__class__.__name__) == "NoSelection"):
return False # No conversion requested
# Normalize the current extension
@@ -543,9 +564,9 @@ def determine_needs_conversion(current_ext: str, target_format: str) -> bool:
return current_ext_lower != target_format_lower
def calculate_size_tolerance(
metadata: dict, user_size_mb: Optional[str]
) -> tuple[Optional[int], Optional[int]]:
def calculate_size_tolerance(metadata: dict,
user_size_mb: Optional[str]) -> tuple[Optional[int],
Optional[int]]:
"""Calculate target size with 1MB grace period.
Args: