Ruff fixes

This commit is contained in:
oitsjustjose 2026-08-28 16:56:45 -05:00
commit 2f5beca13b
3 changed files with 12 additions and 13 deletions

View file

@ -3,7 +3,6 @@ Author: Jose Stovall
Description: Common utilities used to fetch current server statuses Description: Common utilities used to fetch current server statuses
""" """
from typing import List
from docker import DockerClient from docker import DockerClient
from docker.models.containers import Container from docker.models.containers import Container
@ -11,7 +10,7 @@ from docker.models.containers import Container
from server import Server from server import Server
def list_servers(client: DockerClient, all: bool = False) -> List[dict]: def list_servers(client: DockerClient, all: bool = False) -> list[dict]:
""" """
Distills the container data for all servers on the current host into a usable format Distills the container data for all servers on the current host into a usable format
Arguments: Arguments:
@ -20,7 +19,7 @@ def list_servers(client: DockerClient, all: bool = False) -> List[dict]:
(List[Dict[str, any]]) A list of results from __extract_info (List[Dict[str, any]]) A list of results from __extract_info
""" """
containers: List[Container] = list( containers: list[Container] = list(
filter( filter(
lambda x: "itzg/minecraft-server" in x.attrs["Config"]["Image"] and "net.forgeserv.hidden" not in x.labels, lambda x: "itzg/minecraft-server" in x.attrs["Config"]["Image"] and "net.forgeserv.hidden" not in x.labels,
client.containers.list(all=all), client.containers.list(all=all),

View file

@ -16,7 +16,7 @@ class ServerPingResponse:
self.protocol = data["version"]["protocol"] self.protocol = data["version"]["protocol"]
def __str__(self): def __str__(self):
return "Server(description={!r}, icon={!r}, version={!r}, protocol={!r}, players={})".format(self.description, bool(self.icon), self.version, self.protocol, self.players) return f"Server(description={self.description!r}, icon={bool(self.icon)!r}, version={self.version!r}, protocol={self.protocol!r}, players={self.players})"
class Players(list): class Players(list):

View file

@ -2,7 +2,7 @@ import base64
import re import re
from dataclasses import dataclass from dataclasses import dataclass
from os import getenv from os import getenv
from typing import Any, List, Union from typing import Any
from docker.models.containers import Container from docker.models.containers import Container
@ -32,16 +32,16 @@ class ServerConstructorParams:
status: str status: str
type: str type: str
version: str version: str
icon: Union[str, None] icon: str | None
motd: str motd: str
name: str name: str
online: int online: int
max: int max: int
players: List[Player] players: list[Player]
dynmap: Union[str, None] dynmap: str | None
def ping_container_server(container: Container) -> Union[ServerPingResponse, None]: def ping_container_server(container: Container) -> ServerPingResponse | None:
"""Iterates through all Container:Host port binding pairs and attempts to ping the server """Iterates through all Container:Host port binding pairs and attempts to ping the server
Args: Args:
@ -90,13 +90,13 @@ class Server:
self.status: str = params.status self.status: str = params.status
self.type: str = params.type self.type: str = params.type
self.version: str = params.version self.version: str = params.version
self.icon: Union[str, None] = params.icon self.icon: str | None = params.icon
self.motd: str = params.motd self.motd: str = params.motd
self.name: str = params.name self.name: str = params.name
self.online: int = params.online self.online: int = params.online
self.max: int = params.max self.max: int = params.max
self.players: List[Player] = params.players self.players: list[Player] = params.players
self.dynmap: Union[str, None] = params.dynmap self.dynmap: str | None = params.dynmap
def asdict(self) -> dict: def asdict(self) -> dict:
d = self.__dict__ d = self.__dict__
@ -175,7 +175,7 @@ class Server:
# We only care about the right half of the data after the : # We only care about the right half of the data after the :
_, logs = logs.split(" : ") _, logs = logs.split(" : ")
# Find all keys for the log line (universally) # Find all keys for the log line (universally)
keys: List[str] = re.findall("\w+(?=\=)", logs) keys: list[str] = re.findall(r"\w+(?=\=)", logs)
ret = LogDerivedInfo() ret = LogDerivedInfo()
for idx, key in enumerate(keys): for idx, key in enumerate(keys):