976d90f26b
Key improvements: - Add intelligent file update checking with 30-second buffer to avoid unnecessary operations - Implement efficient PDF to PNG conversion (only when source is newer) - Add smart file copying (skip if target is up-to-date) - Create proper folder structure using plot_root/source_name pattern - Improve template with better text handling for long plot names - Add text wrapping, truncation, and hover tooltips for plot names - Remove unnecessary directory cleaning for true incremental updates - Fix title display issue (was showing '.' instead of 'Gallery') - Add comprehensive logging showing what's processed vs skipped Performance benefits: - Subsequent runs are significantly faster (only processes changed files) - Reduces ImageMagick conversions and file I/O operations - Maintains file system timing robustness with buffer delays UI improvements: - Better handling of long filenames with word wrapping - Constrained text areas prevent overlap between thumbnails - Hover tooltips show full names when truncated - Responsive grid layout maintained
65 lines
1.5 KiB
Python
65 lines
1.5 KiB
Python
from dataclasses import dataclass, field, asdict
|
|
from pathlib import Path
|
|
|
|
import yaml
|
|
|
|
|
|
@dataclass
|
|
class GalleryItem:
|
|
name: str
|
|
path: Path
|
|
|
|
|
|
@dataclass
|
|
class Config:
|
|
web_folder: str = ""
|
|
backup_folder: str = ""
|
|
png_dpi: int = 400
|
|
plot_root: str = "gallery"
|
|
sources: list[GalleryItem] = field(default_factory=list)
|
|
|
|
@classmethod
|
|
def from_yaml(cls, yaml_file: str) -> "Config":
|
|
"""
|
|
Load configuration from a YAML file.
|
|
|
|
Args:
|
|
yaml_file (str): Path to the YAML file.
|
|
strict (bool):
|
|
If True, raises an error if a key in the YAML file does not exist in the Config class.
|
|
If False (default), adds all keys as attributes
|
|
|
|
Returns:
|
|
Config: Instance of this class
|
|
"""
|
|
|
|
with open(yaml_file, "r") as f:
|
|
new_config: dict = yaml.safe_load(f)
|
|
|
|
new_config["sources"] = [
|
|
GalleryItem(name=src["name"], path=Path(src["path"]))
|
|
for src in new_config.get("sources", False)
|
|
]
|
|
|
|
instance = cls(**{
|
|
k: v
|
|
for k, v in new_config.items()
|
|
})
|
|
|
|
return instance
|
|
|
|
def to_yaml(self, yaml_file: str) -> None:
|
|
"""
|
|
Save the current configuration to a YAML file.
|
|
|
|
Args:
|
|
yaml_file (str): Path to the YAML file.
|
|
"""
|
|
with open(yaml_file, "w") as f:
|
|
yaml.dump(asdict(self), f, default_flow_style=False)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
config = Config()
|
|
config.to_yaml("config.yaml")
|