mirror of
https://github.com/ManiMatter/decluttarr.git
synced 2026-04-20 05:54:17 +02:00
Formatting issues
This commit is contained in:
@@ -18,8 +18,7 @@ def filter_internal_attributes(data, internal_attributes, hide_internal_attr):
|
||||
def clean_dict(data, sensitive_attributes, internal_attributes, hide_internal_attr):
|
||||
"""Clean a dictionary by masking sensitive attributes and filtering internal ones."""
|
||||
cleaned = {
|
||||
k: mask_sensitive_value(v, k, sensitive_attributes)
|
||||
for k, v in data.items()
|
||||
k: mask_sensitive_value(v, k, sensitive_attributes) for k, v in data.items()
|
||||
}
|
||||
return filter_internal_attributes(cleaned, internal_attributes, hide_internal_attr)
|
||||
|
||||
@@ -29,9 +28,20 @@ def clean_list(obj, sensitive_attributes, internal_attributes, hide_internal_att
|
||||
cleaned_list = []
|
||||
for entry in obj:
|
||||
if isinstance(entry, dict):
|
||||
cleaned_list.append(clean_dict(entry, sensitive_attributes, internal_attributes, hide_internal_attr))
|
||||
cleaned_list.append(
|
||||
clean_dict(
|
||||
entry, sensitive_attributes, internal_attributes, hide_internal_attr
|
||||
)
|
||||
)
|
||||
elif hasattr(entry, "__dict__"):
|
||||
cleaned_list.append(clean_dict(vars(entry), sensitive_attributes, internal_attributes, hide_internal_attr))
|
||||
cleaned_list.append(
|
||||
clean_dict(
|
||||
vars(entry),
|
||||
sensitive_attributes,
|
||||
internal_attributes,
|
||||
hide_internal_attr,
|
||||
)
|
||||
)
|
||||
else:
|
||||
cleaned_list.append(entry)
|
||||
return cleaned_list
|
||||
@@ -40,9 +50,13 @@ def clean_list(obj, sensitive_attributes, internal_attributes, hide_internal_att
|
||||
def clean_object(obj, sensitive_attributes, internal_attributes, hide_internal_attr):
|
||||
"""Clean an object (either a dict, class instance, or other types)."""
|
||||
if isinstance(obj, dict):
|
||||
return clean_dict(obj, sensitive_attributes, internal_attributes, hide_internal_attr)
|
||||
return clean_dict(
|
||||
obj, sensitive_attributes, internal_attributes, hide_internal_attr
|
||||
)
|
||||
if hasattr(obj, "__dict__"):
|
||||
return clean_dict(vars(obj), sensitive_attributes, internal_attributes, hide_internal_attr)
|
||||
return clean_dict(
|
||||
vars(obj), sensitive_attributes, internal_attributes, hide_internal_attr
|
||||
)
|
||||
return mask_sensitive_value(obj, "", sensitive_attributes)
|
||||
|
||||
|
||||
@@ -68,7 +82,10 @@ def get_config_as_yaml(
|
||||
# Process list-based config
|
||||
if isinstance(obj, list):
|
||||
cleaned_list = clean_list(
|
||||
obj, sensitive_attributes, internal_attributes, hide_internal_attr,
|
||||
obj,
|
||||
sensitive_attributes,
|
||||
internal_attributes,
|
||||
hide_internal_attr,
|
||||
)
|
||||
if cleaned_list:
|
||||
config_output[key] = cleaned_list
|
||||
@@ -76,9 +93,14 @@ def get_config_as_yaml(
|
||||
# Process dict or class-like object config
|
||||
else:
|
||||
cleaned_obj = clean_object(
|
||||
obj, sensitive_attributes, internal_attributes, hide_internal_attr,
|
||||
obj,
|
||||
sensitive_attributes,
|
||||
internal_attributes,
|
||||
hide_internal_attr,
|
||||
)
|
||||
if cleaned_obj:
|
||||
config_output[key] = cleaned_obj
|
||||
|
||||
return yaml.dump(config_output, indent=2, default_flow_style=False, sort_keys=False).strip()
|
||||
return yaml.dump(
|
||||
config_output, indent=2, default_flow_style=False, sort_keys=False
|
||||
).strip()
|
||||
|
||||
@@ -80,7 +80,6 @@ class DownloadClients:
|
||||
raise ValueError(error)
|
||||
seen.add(name.lower())
|
||||
|
||||
|
||||
def get_download_client_by_name(
|
||||
self, name: str, download_client_type: str | None = None
|
||||
):
|
||||
@@ -116,7 +115,6 @@ class DownloadClients:
|
||||
download_client_type = mapping.get(arr_download_client_implementation)
|
||||
return download_client_type
|
||||
|
||||
|
||||
def list_download_clients(self) -> dict[str, list[str]]:
|
||||
"""
|
||||
Return a dict mapping download_client_type to list of client names
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from packaging import version
|
||||
|
||||
from src.settings._constants import ApiEndpoints, MinVersions
|
||||
from src.utils.common import make_request, wait_and_exit, extract_json_from_response
|
||||
from src.utils.common import extract_json_from_response, make_request, wait_and_exit
|
||||
from src.utils.log_setup import logger
|
||||
|
||||
|
||||
|
||||
@@ -76,15 +76,11 @@ class SabnzbdClient:
|
||||
|
||||
async def fetch_version(self):
|
||||
"""Fetch the current SABnzbd version."""
|
||||
logger.debug("_download_clients_sabnzbd.py/fetch_version: Getting SABnzbd Version")
|
||||
params = {
|
||||
"mode": "version",
|
||||
"apikey": self.api_key,
|
||||
"output": "json"
|
||||
}
|
||||
response = await make_request(
|
||||
"get", self.api_url, self.settings, params=params
|
||||
logger.debug(
|
||||
"_download_clients_sabnzbd.py/fetch_version: Getting SABnzbd Version"
|
||||
)
|
||||
params = {"mode": "version", "apikey": self.api_key, "output": "json"}
|
||||
response = await make_request("get", self.api_url, self.settings, params=params)
|
||||
response_data = response.json()
|
||||
self.version = response_data.get("version", "unknown")
|
||||
logger.debug(
|
||||
@@ -108,11 +104,7 @@ class SabnzbdClient:
|
||||
logger.debug(
|
||||
"_download_clients_sabnzbd.py/check_sabnzbd_reachability: Checking if SABnzbd is reachable"
|
||||
)
|
||||
params = {
|
||||
"mode": "version",
|
||||
"apikey": self.api_key,
|
||||
"output": "json"
|
||||
}
|
||||
params = {"mode": "version", "apikey": self.api_key, "output": "json"}
|
||||
await make_request(
|
||||
"get",
|
||||
self.api_url,
|
||||
@@ -132,11 +124,7 @@ class SabnzbdClient:
|
||||
logger.debug(
|
||||
"_download_clients_sabnzbd.py/check_connected: Checking if SABnzbd is connected"
|
||||
)
|
||||
params = {
|
||||
"mode": "status",
|
||||
"apikey": self.api_key,
|
||||
"output": "json"
|
||||
}
|
||||
params = {"mode": "status", "apikey": self.api_key, "output": "json"}
|
||||
response = await make_request(
|
||||
"get",
|
||||
self.api_url,
|
||||
@@ -164,12 +152,10 @@ class SabnzbdClient:
|
||||
|
||||
async def get_queue_items(self):
|
||||
"""Fetch queue items from SABnzbd."""
|
||||
logger.debug("_download_clients_sabnzbd.py/get_queue_items: Getting queue items")
|
||||
params = {
|
||||
"mode": "queue",
|
||||
"apikey": self.api_key,
|
||||
"output": "json"
|
||||
}
|
||||
logger.debug(
|
||||
"_download_clients_sabnzbd.py/get_queue_items: Getting queue items"
|
||||
)
|
||||
params = {"mode": "queue", "apikey": self.api_key, "output": "json"}
|
||||
response = await make_request(
|
||||
"get",
|
||||
self.api_url,
|
||||
@@ -181,12 +167,10 @@ class SabnzbdClient:
|
||||
|
||||
async def get_history_items(self):
|
||||
"""Fetch history items from SABnzbd."""
|
||||
logger.debug("_download_clients_sabnzbd.py/get_history_items: Getting history items")
|
||||
params = {
|
||||
"mode": "history",
|
||||
"apikey": self.api_key,
|
||||
"output": "json"
|
||||
}
|
||||
logger.debug(
|
||||
"_download_clients_sabnzbd.py/get_history_items: Getting history items"
|
||||
)
|
||||
params = {"mode": "history", "apikey": self.api_key, "output": "json"}
|
||||
response = await make_request(
|
||||
"get",
|
||||
self.api_url,
|
||||
@@ -198,13 +182,15 @@ class SabnzbdClient:
|
||||
|
||||
async def remove_download(self, nzo_id: str):
|
||||
"""Remove a download from SABnzbd queue."""
|
||||
logger.debug(f"_download_clients_sabnzbd.py/remove_download: Removing download {nzo_id}")
|
||||
logger.debug(
|
||||
f"_download_clients_sabnzbd.py/remove_download: Removing download {nzo_id}"
|
||||
)
|
||||
params = {
|
||||
"mode": "queue",
|
||||
"name": "delete",
|
||||
"value": nzo_id,
|
||||
"apikey": self.api_key,
|
||||
"output": "json"
|
||||
"output": "json",
|
||||
}
|
||||
await make_request(
|
||||
"get",
|
||||
@@ -215,13 +201,15 @@ class SabnzbdClient:
|
||||
|
||||
async def pause_download(self, nzo_id: str):
|
||||
"""Pause a download in SABnzbd queue."""
|
||||
logger.debug(f"_download_clients_sabnzbd.py/pause_download: Pausing download {nzo_id}")
|
||||
logger.debug(
|
||||
f"_download_clients_sabnzbd.py/pause_download: Pausing download {nzo_id}"
|
||||
)
|
||||
params = {
|
||||
"mode": "queue",
|
||||
"name": "pause",
|
||||
"value": nzo_id,
|
||||
"apikey": self.api_key,
|
||||
"output": "json"
|
||||
"output": "json",
|
||||
}
|
||||
await make_request(
|
||||
"get",
|
||||
@@ -232,13 +220,15 @@ class SabnzbdClient:
|
||||
|
||||
async def resume_download(self, nzo_id: str):
|
||||
"""Resume a download in SABnzbd queue."""
|
||||
logger.debug(f"_download_clients_sabnzbd.py/resume_download: Resuming download {nzo_id}")
|
||||
logger.debug(
|
||||
f"_download_clients_sabnzbd.py/resume_download: Resuming download {nzo_id}"
|
||||
)
|
||||
params = {
|
||||
"mode": "queue",
|
||||
"name": "resume",
|
||||
"value": nzo_id,
|
||||
"apikey": self.api_key,
|
||||
"output": "json"
|
||||
"output": "json",
|
||||
}
|
||||
await make_request(
|
||||
"get",
|
||||
@@ -249,12 +239,14 @@ class SabnzbdClient:
|
||||
|
||||
async def retry_download(self, nzo_id: str):
|
||||
"""Retry a failed download from SABnzbd history."""
|
||||
logger.debug(f"_download_clients_sabnzbd.py/retry_download: Retrying download {nzo_id}")
|
||||
logger.debug(
|
||||
f"_download_clients_sabnzbd.py/retry_download: Retrying download {nzo_id}"
|
||||
)
|
||||
params = {
|
||||
"mode": "retry",
|
||||
"value": nzo_id,
|
||||
"apikey": self.api_key,
|
||||
"output": "json"
|
||||
"output": "json",
|
||||
}
|
||||
await make_request(
|
||||
"get",
|
||||
@@ -311,11 +303,7 @@ class SabnzbdClient:
|
||||
|
||||
async def get_download_speed(self):
|
||||
"""Get current download speed from SABnzbd status."""
|
||||
params = {
|
||||
"mode": "status",
|
||||
"apikey": self.api_key,
|
||||
"output": "json"
|
||||
}
|
||||
params = {"mode": "status", "apikey": self.api_key, "output": "json"}
|
||||
response = await make_request(
|
||||
"get",
|
||||
self.api_url,
|
||||
|
||||
@@ -23,17 +23,29 @@ class General:
|
||||
self.log_level = general_config.get("log_level", self.log_level.upper())
|
||||
self.test_run = general_config.get("test_run", self.test_run)
|
||||
self.timer = general_config.get("timer", self.timer)
|
||||
self.ssl_verification = general_config.get("ssl_verification", self.ssl_verification)
|
||||
self.ignored_download_clients = general_config.get("ignored_download_clients", self.ignored_download_clients)
|
||||
self.ssl_verification = general_config.get(
|
||||
"ssl_verification", self.ssl_verification
|
||||
)
|
||||
self.ignored_download_clients = general_config.get(
|
||||
"ignored_download_clients", self.ignored_download_clients
|
||||
)
|
||||
|
||||
self.private_tracker_handling = general_config.get("private_tracker_handling", self.private_tracker_handling)
|
||||
self.public_tracker_handling = general_config.get("public_tracker_handling", self.public_tracker_handling)
|
||||
self.private_tracker_handling = general_config.get(
|
||||
"private_tracker_handling", self.private_tracker_handling
|
||||
)
|
||||
self.public_tracker_handling = general_config.get(
|
||||
"public_tracker_handling", self.public_tracker_handling
|
||||
)
|
||||
self.obsolete_tag = general_config.get("obsolete_tag", self.obsolete_tag)
|
||||
self.protected_tag = general_config.get("protected_tag", self.protected_tag)
|
||||
|
||||
# Validate tracker handling settings
|
||||
self.private_tracker_handling = self._validate_tracker_handling(self.private_tracker_handling, "private_tracker_handling")
|
||||
self.public_tracker_handling = self._validate_tracker_handling(self.public_tracker_handling, "public_tracker_handling")
|
||||
self.private_tracker_handling = self._validate_tracker_handling(
|
||||
self.private_tracker_handling, "private_tracker_handling"
|
||||
)
|
||||
self.public_tracker_handling = self._validate_tracker_handling(
|
||||
self.public_tracker_handling, "public_tracker_handling"
|
||||
)
|
||||
self.obsolete_tag = self._determine_obsolete_tag(self.obsolete_tag)
|
||||
|
||||
validate_data_types(self)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from pathlib import Path
|
||||
|
||||
import requests
|
||||
from packaging import version
|
||||
|
||||
@@ -9,10 +10,10 @@ from src.settings._constants import (
|
||||
DetailItemSearchCommand,
|
||||
FullQueueParameter,
|
||||
MinVersions,
|
||||
RefreshItemKey,
|
||||
RefreshItemCommand,
|
||||
RefreshItemKey,
|
||||
)
|
||||
from src.utils.common import make_request, wait_and_exit, extract_json_from_response
|
||||
from src.utils.common import extract_json_from_response, make_request, wait_and_exit
|
||||
from src.utils.log_setup import logger
|
||||
|
||||
|
||||
@@ -154,7 +155,7 @@ class ArrInstance:
|
||||
self.detail_item_id_key = self.detail_item_key + "Id"
|
||||
self.detail_item_ids_key = self.detail_item_key + "Ids"
|
||||
self.detail_item_search_command = getattr(DetailItemSearchCommand, arr_type)
|
||||
if self.arr_type in ('radarr','sonarr'):
|
||||
if self.arr_type in ("radarr", "sonarr"):
|
||||
self.refresh_item_key = getattr(RefreshItemKey, arr_type)
|
||||
self.refresh_item_id_key = self.refresh_item_key + "Id"
|
||||
self.refresh_item_command = getattr(RefreshItemCommand, arr_type)
|
||||
|
||||
@@ -109,7 +109,6 @@ class Jobs:
|
||||
)
|
||||
self.detect_deletions = JobParams()
|
||||
|
||||
|
||||
def _set_job_configs(self, config):
|
||||
# Populate jobs from YAML config
|
||||
for job_name in self.__dict__:
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import yaml
|
||||
|
||||
from src.utils.log_setup import logger
|
||||
|
||||
@@ -23,7 +23,9 @@ def validate_data_types(cls, default_cls=None):
|
||||
continue
|
||||
|
||||
value = getattr(cls, attr)
|
||||
default_source = default_cls if default_cls and hasattr(default_cls, attr) else cls.__class__
|
||||
default_source = (
|
||||
default_cls if default_cls and hasattr(default_cls, attr) else cls.__class__
|
||||
)
|
||||
default_value = getattr(default_source, attr, None)
|
||||
|
||||
if value == default_value:
|
||||
|
||||
Reference in New Issue
Block a user