constistent classmethod and staticmethod usage

General idea is to use classmethod for every constructor and
statismethod otherwise.
Also use self and cls whenever it's possible to call static and class
methods
This commit is contained in:
2021-03-31 04:15:55 +03:00
parent d449eb3c2e
commit 880c70bd58
18 changed files with 176 additions and 161 deletions

View File

@ -19,7 +19,7 @@
#
from __future__ import annotations
from typing import List, Optional, Tuple
from typing import List, Optional, Tuple, Type
from ahriman.core.configuration import Configuration
from ahriman.models.build_status import BuildStatus, BuildStatusEnum
@ -31,6 +31,20 @@ class Client:
base build status reporter client
"""
@classmethod
def load(cls: Type[Client], configuration: Configuration) -> Client:
"""
load client from settings
:param configuration: configuration instance
:return: client according to current settings
"""
host = configuration.get("web", "host", fallback=None)
port = configuration.getint("web", "port", fallback=None)
if host is not None and port is not None:
from ahriman.core.status.web_client import WebClient
return WebClient(host, port)
return cls()
def add(self, package: Package, status: BuildStatusEnum) -> None:
"""
add new package with status
@ -109,18 +123,3 @@ class Client:
:param package: current package properties
"""
return self.add(package, BuildStatusEnum.Unknown)
@staticmethod
def load(configuration: Configuration) -> Client:
"""
load client from settings
:param configuration: configuration instance
:return: client according to current settings
"""
host = configuration.get("web", "host", fallback=None)
port = configuration.getint("web", "port", fallback=None)
if host is None or port is None:
return Client()
from ahriman.core.status.web_client import WebClient
return WebClient(host, port)