Lint using ruff

This commit is contained in:
PapaTutuWawa 2025-01-13 21:58:40 +00:00
parent 7d91041091
commit fad2d4f312
7 changed files with 11 additions and 22 deletions

View File

@ -1,6 +1,5 @@
from dataclasses import dataclass
from typing import TypeVar, ParamSpec, Callable
from functools import wraps
P = ParamSpec("P")
T = TypeVar("T")
@ -43,13 +42,6 @@ def seconds_to_kodi_format(seconds: int) -> KodiTime:
)
def find(l: list[T], pred: Callable[[T], bool]) -> T | None:
for i in l:
if pred(i):
return i
return None
def recursive_dict_merge(base: dict, update: dict) -> dict:
unique_keys = set([*base.keys(), *update.keys()])
out = {}

View File

@ -1,16 +1,17 @@
import json
from typing import Any, Callable
from dataclasses import dataclass
from typing import Any
from urllib.parse import urlparse
import logging
import base64
import sys
import importlib
from http.server import BaseHTTPRequestHandler
from microkodi.repository import I
from microkodi.programs import Program, PlayerInfo
from microkodi.helpers import KodiTime, seconds_to_kodi_format, after
from microkodi.config import Config
def jsonrpc_response(id: int, payload: dict[str, Any]) -> dict[str, Any]:
@ -193,7 +194,7 @@ class PlayerRpcObject(JsonRpcObject):
self.logger.debug(
"Trying to import %s to get class %s", module_name, class_name
)
spec = importlib.util.find_spec(module)
spec = importlib.util.find_spec(module_name)
module = importlib.util.module_from_spec(spec)
sys.modules[module_name] = module
spec.loader.exec_module(module)
@ -371,7 +372,7 @@ class JsonRpcHandler(BaseHTTPRequestHandler):
auth: str | None = self.headers.get("Authorization")
if auth is None:
logger.warn(
"Client provided no Authorization header. Method: %s", method
"Client provided no Authorization header. Method: %s", method_name
)
self.send_error(401)
return
@ -379,14 +380,14 @@ class JsonRpcHandler(BaseHTTPRequestHandler):
auth_type, auth_payload = auth.split(" ")
if auth_type != "Basic":
logger.warn(
"Client provided no Basic authorization. Method: %s", method
"Client provided no Basic authorization. Method: %s", method_name
)
self.send_error(401)
return
credentials = base64.b64decode(auth_payload).decode("utf-8")
if credentials != "kodi:1234":
logger.warn(
"Rejecting request due to wrong credentials. Method: %s", method
"Rejecting request due to wrong credentials. Method: %s", method_name
)
self.send_error(403)
return

View File

@ -5,7 +5,6 @@ import threading
import argparse
from pathlib import Path
import importlib.util
import time
from PySide6.QtGui import QGuiApplication
from PySide6.QtQml import QQmlApplicationEngine
@ -51,7 +50,6 @@ def run_kodi_server():
init_method = getattr(module, "init")
init_method()
server = HTTPServer
httpd = HTTPServer(
(
config.host,
@ -71,7 +69,6 @@ def main():
options = parser.parse_args()
logging.basicConfig(level=logging.DEBUG if options.debug else logging.INFO)
logger = logging.getLogger("ui")
# Load the config
config = load_config(options.config)

View File

@ -1,8 +1,7 @@
import subprocess
from typing import Any, Callable
from urllib.parse import ParseResult, urlunparse, urldefrag, unquote
from urllib.parse import ParseResult, urlunparse
import logging
from dataclasses import dataclass
import os
import json
import socket

View File

@ -160,7 +160,7 @@ class VlcProgram(Program):
) -> str | None:
try:
req = requests.get(
f"http://127.0.0.1:9090/requests/status.xml",
"http://127.0.0.1:9090/requests/status.xml",
auth=("", self._vlc_password),
params={
"command": command,

View File

@ -14,4 +14,4 @@ class _Repository:
return self._data.get(key)
I = _Repository()
I = _Repository() # noqa:E741

View File

@ -25,7 +25,7 @@ class TVHandler:
try:
requests.put(config.tv_power_webhook)
self.logger.debug("Triggered webhook to enable power to the TV")
except Exception as ex:
except Exception:
self.logger.warn("Failed to enable power to the TV")
return config.tv_power_webhook is not None