This commit is contained in:
nose
2025-12-11 12:47:30 -08:00
parent 6b05dc5552
commit 65d12411a2
92 changed files with 17447 additions and 14308 deletions

View File

@@ -25,18 +25,28 @@ def _make_cache_key(config_dir: Optional[Path], filename: str, actual_path: Opti
def get_hydrus_instance(config: Dict[str, Any], instance_name: str = "home") -> Optional[Dict[str, Any]]:
"""Get a specific Hydrus instance config by name.
Supports both formats:
- New: config["storage"]["hydrus"][instance_name] = {"key": "...", "url": "..."}
- Old: config["HydrusNetwork"][instance_name] = {"key": "...", "url": "..."}
Supports multiple formats:
- Current: config["store"]["hydrusnetwork"][instance_name]
- Legacy: config["storage"]["hydrus"][instance_name]
- Old: config["HydrusNetwork"][instance_name]
Args:
config: Configuration dict
instance_name: Name of the Hydrus instance (default: "home")
Returns:
Dict with "key" and "url" keys, or None if not found
Dict with access key and URL, or None if not found
"""
# Try new format first
# Try current format first: config["store"]["hydrusnetwork"]["home"]
store = config.get("store", {})
if isinstance(store, dict):
hydrusnetwork = store.get("hydrusnetwork", {})
if isinstance(hydrusnetwork, dict):
instance = hydrusnetwork.get(instance_name)
if isinstance(instance, dict):
return instance
# Try legacy format: config["storage"]["hydrus"]
storage = config.get("storage", {})
if isinstance(storage, dict):
hydrus_config = storage.get("hydrus", {})
@@ -45,7 +55,7 @@ def get_hydrus_instance(config: Dict[str, Any], instance_name: str = "home") ->
if isinstance(instance, dict):
return instance
# Fall back to old format
# Fall back to old format: config["HydrusNetwork"]
hydrus_network = config.get("HydrusNetwork")
if not isinstance(hydrus_network, dict):
return None
@@ -60,9 +70,10 @@ def get_hydrus_instance(config: Dict[str, Any], instance_name: str = "home") ->
def get_hydrus_access_key(config: Dict[str, Any], instance_name: str = "home") -> Optional[str]:
"""Get Hydrus access key for an instance.
Supports both old flat format and new nested format:
Supports multiple formats:
- Current: config["store"]["hydrusnetwork"][name]["Hydrus-Client-API-Access-Key"]
- Legacy: config["storage"]["hydrus"][name]["key"]
- Old: config["HydrusNetwork_Access_Key"]
- New: config["HydrusNetwork"][instance_name]["key"]
Args:
config: Configuration dict
@@ -72,7 +83,18 @@ def get_hydrus_access_key(config: Dict[str, Any], instance_name: str = "home") -
Access key string, or None if not found
"""
instance = get_hydrus_instance(config, instance_name)
key = instance.get("key") if instance else config.get("HydrusNetwork_Access_Key")
if instance:
# Try current format key name
key = instance.get("Hydrus-Client-API-Access-Key")
if key:
return str(key).strip()
# Try legacy key name
key = instance.get("key")
if key:
return str(key).strip()
# Fall back to old flat format
key = config.get("HydrusNetwork_Access_Key")
return str(key).strip() if key else None
@@ -140,8 +162,9 @@ def resolve_output_dir(config: Dict[str, Any]) -> Path:
def get_local_storage_path(config: Dict[str, Any]) -> Optional[Path]:
"""Get local storage path from config.
Supports both formats:
- New: config["storage"]["local"]["path"]
Supports multiple formats:
- New: config["store"]["folder"]["default"]["path"]
- Old: config["storage"]["local"]["path"]
- Old: config["Local"]["path"]
Args:
@@ -150,7 +173,18 @@ def get_local_storage_path(config: Dict[str, Any]) -> Optional[Path]:
Returns:
Path object if found, None otherwise
"""
# Try new format first
# Try new format first: store.folder.default.path
store = config.get("store", {})
if isinstance(store, dict):
folder_config = store.get("folder", {})
if isinstance(folder_config, dict):
default_config = folder_config.get("default", {})
if isinstance(default_config, dict):
path_str = default_config.get("path")
if path_str:
return Path(str(path_str)).expanduser()
# Fall back to storage.local.path format
storage = config.get("storage", {})
if isinstance(storage, dict):
local_config = storage.get("local", {})
@@ -159,7 +193,7 @@ def get_local_storage_path(config: Dict[str, Any]) -> Optional[Path]:
if path_str:
return Path(str(path_str)).expanduser()
# Fall back to old format
# Fall back to old Local format
local_config = config.get("Local", {})
if isinstance(local_config, dict):
path_str = local_config.get("path")