Lint using ruff
This commit is contained in:
parent
7d91041091
commit
fad2d4f312
@ -1,6 +1,5 @@
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import TypeVar, ParamSpec, Callable
|
from typing import TypeVar, ParamSpec, Callable
|
||||||
from functools import wraps
|
|
||||||
|
|
||||||
P = ParamSpec("P")
|
P = ParamSpec("P")
|
||||||
T = TypeVar("T")
|
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:
|
def recursive_dict_merge(base: dict, update: dict) -> dict:
|
||||||
unique_keys = set([*base.keys(), *update.keys()])
|
unique_keys = set([*base.keys(), *update.keys()])
|
||||||
out = {}
|
out = {}
|
||||||
|
@ -1,16 +1,17 @@
|
|||||||
import json
|
import json
|
||||||
from typing import Any, Callable
|
from typing import Any
|
||||||
from dataclasses import dataclass
|
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
import logging
|
import logging
|
||||||
import base64
|
import base64
|
||||||
import sys
|
import sys
|
||||||
|
import importlib
|
||||||
|
|
||||||
from http.server import BaseHTTPRequestHandler
|
from http.server import BaseHTTPRequestHandler
|
||||||
|
|
||||||
from microkodi.repository import I
|
from microkodi.repository import I
|
||||||
from microkodi.programs import Program, PlayerInfo
|
from microkodi.programs import Program, PlayerInfo
|
||||||
from microkodi.helpers import KodiTime, seconds_to_kodi_format, after
|
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]:
|
def jsonrpc_response(id: int, payload: dict[str, Any]) -> dict[str, Any]:
|
||||||
@ -193,7 +194,7 @@ class PlayerRpcObject(JsonRpcObject):
|
|||||||
self.logger.debug(
|
self.logger.debug(
|
||||||
"Trying to import %s to get class %s", module_name, class_name
|
"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)
|
module = importlib.util.module_from_spec(spec)
|
||||||
sys.modules[module_name] = module
|
sys.modules[module_name] = module
|
||||||
spec.loader.exec_module(module)
|
spec.loader.exec_module(module)
|
||||||
@ -371,7 +372,7 @@ class JsonRpcHandler(BaseHTTPRequestHandler):
|
|||||||
auth: str | None = self.headers.get("Authorization")
|
auth: str | None = self.headers.get("Authorization")
|
||||||
if auth is None:
|
if auth is None:
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"Client provided no Authorization header. Method: %s", method
|
"Client provided no Authorization header. Method: %s", method_name
|
||||||
)
|
)
|
||||||
self.send_error(401)
|
self.send_error(401)
|
||||||
return
|
return
|
||||||
@ -379,14 +380,14 @@ class JsonRpcHandler(BaseHTTPRequestHandler):
|
|||||||
auth_type, auth_payload = auth.split(" ")
|
auth_type, auth_payload = auth.split(" ")
|
||||||
if auth_type != "Basic":
|
if auth_type != "Basic":
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"Client provided no Basic authorization. Method: %s", method
|
"Client provided no Basic authorization. Method: %s", method_name
|
||||||
)
|
)
|
||||||
self.send_error(401)
|
self.send_error(401)
|
||||||
return
|
return
|
||||||
credentials = base64.b64decode(auth_payload).decode("utf-8")
|
credentials = base64.b64decode(auth_payload).decode("utf-8")
|
||||||
if credentials != "kodi:1234":
|
if credentials != "kodi:1234":
|
||||||
logger.warn(
|
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)
|
self.send_error(403)
|
||||||
return
|
return
|
||||||
|
@ -5,7 +5,6 @@ import threading
|
|||||||
import argparse
|
import argparse
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import importlib.util
|
import importlib.util
|
||||||
import time
|
|
||||||
|
|
||||||
from PySide6.QtGui import QGuiApplication
|
from PySide6.QtGui import QGuiApplication
|
||||||
from PySide6.QtQml import QQmlApplicationEngine
|
from PySide6.QtQml import QQmlApplicationEngine
|
||||||
@ -51,7 +50,6 @@ def run_kodi_server():
|
|||||||
init_method = getattr(module, "init")
|
init_method = getattr(module, "init")
|
||||||
init_method()
|
init_method()
|
||||||
|
|
||||||
server = HTTPServer
|
|
||||||
httpd = HTTPServer(
|
httpd = HTTPServer(
|
||||||
(
|
(
|
||||||
config.host,
|
config.host,
|
||||||
@ -71,7 +69,6 @@ def main():
|
|||||||
options = parser.parse_args()
|
options = parser.parse_args()
|
||||||
|
|
||||||
logging.basicConfig(level=logging.DEBUG if options.debug else logging.INFO)
|
logging.basicConfig(level=logging.DEBUG if options.debug else logging.INFO)
|
||||||
logger = logging.getLogger("ui")
|
|
||||||
|
|
||||||
# Load the config
|
# Load the config
|
||||||
config = load_config(options.config)
|
config = load_config(options.config)
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
import subprocess
|
import subprocess
|
||||||
from typing import Any, Callable
|
from typing import Any, Callable
|
||||||
from urllib.parse import ParseResult, urlunparse, urldefrag, unquote
|
from urllib.parse import ParseResult, urlunparse
|
||||||
import logging
|
import logging
|
||||||
from dataclasses import dataclass
|
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
import socket
|
import socket
|
||||||
|
@ -160,7 +160,7 @@ class VlcProgram(Program):
|
|||||||
) -> str | None:
|
) -> str | None:
|
||||||
try:
|
try:
|
||||||
req = requests.get(
|
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),
|
auth=("", self._vlc_password),
|
||||||
params={
|
params={
|
||||||
"command": command,
|
"command": command,
|
||||||
|
@ -14,4 +14,4 @@ class _Repository:
|
|||||||
return self._data.get(key)
|
return self._data.get(key)
|
||||||
|
|
||||||
|
|
||||||
I = _Repository()
|
I = _Repository() # noqa:E741
|
||||||
|
@ -25,7 +25,7 @@ class TVHandler:
|
|||||||
try:
|
try:
|
||||||
requests.put(config.tv_power_webhook)
|
requests.put(config.tv_power_webhook)
|
||||||
self.logger.debug("Triggered webhook to enable power to the TV")
|
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")
|
self.logger.warn("Failed to enable power to the TV")
|
||||||
return config.tv_power_webhook is not None
|
return config.tv_power_webhook is not None
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user