Making const values actually constant.
Signed-off-by: Cliff Hill <xlorep@darkhelm.org>
This commit is contained in:
@@ -2,25 +2,42 @@
|
||||
import concurrent.futures
|
||||
import dataclasses
|
||||
import datetime
|
||||
import enum
|
||||
import pathlib
|
||||
|
||||
import appdirs # type: ignore
|
||||
|
||||
__all__ = ["APPNAME", "APPAUTHOR", "PATHS"]
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class _Defaults:
|
||||
BATCH_SIZE: int
|
||||
PROCESS_DELAY: int
|
||||
DURATION: int
|
||||
PLAYTIME: datetime.timedelta
|
||||
MAX_TRACKS: int
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class _Paths:
|
||||
CONFIG: pathlib.Path
|
||||
DATA: pathlib.Path
|
||||
CACHE: pathlib.Path
|
||||
LOG: pathlib.Path
|
||||
|
||||
|
||||
APPNAME = "plex-playlist"
|
||||
APPAUTHOR = "Cliff Hill"
|
||||
|
||||
|
||||
class Default(enum.Enum):
|
||||
"""Contains default values used for initializing settings."""
|
||||
_dirs = appdirs.AppDirs(APPNAME, APPAUTHOR)
|
||||
|
||||
BATCH_SIZE: int = 1000
|
||||
PROCESS_DELAY: int = 0
|
||||
DURATION: int = 0
|
||||
PLAYTIME: datetime.timedelta = datetime.timedelta(days=1)
|
||||
MAX_TRACKS: int = 0
|
||||
|
||||
DEFAULTS = _Defaults(
|
||||
BATCH_SIZE=1000,
|
||||
PROCESS_DELAY=0,
|
||||
DURATION=0,
|
||||
PLAYTIME=datetime.timedelta(days=1),
|
||||
MAX_TRACKS=0,
|
||||
)
|
||||
|
||||
|
||||
PROCESS_POOL = concurrent.futures.ProcessPoolExecutor()
|
||||
@@ -28,19 +45,9 @@ MAX_PROCESSES = PROCESS_POOL._max_workers # type: ignore [attr-defined]
|
||||
SETTINGS_FILENAME = "settings.yaml"
|
||||
|
||||
|
||||
@dataclasses.dataclass
|
||||
class Paths:
|
||||
CONFIG: pathlib.Path
|
||||
DATA: pathlib.Path
|
||||
CACHE: pathlib.Path
|
||||
LOG: pathlib.Path
|
||||
|
||||
|
||||
dirs = appdirs.AppDirs(APPNAME, APPAUTHOR)
|
||||
|
||||
PATHS = Paths(
|
||||
CONFIG=pathlib.Path(dirs.user_config_dir),
|
||||
DATA=pathlib.Path(dirs.user_data_dir),
|
||||
CACHE=pathlib.Path(dirs.user_cache_dir),
|
||||
LOG=pathlib.Path(dirs.user_log_dir),
|
||||
PATHS = _Paths(
|
||||
CONFIG=pathlib.Path(_dirs.user_config_dir),
|
||||
DATA=pathlib.Path(_dirs.user_data_dir),
|
||||
CACHE=pathlib.Path(_dirs.user_cache_dir),
|
||||
LOG=pathlib.Path(_dirs.user_log_dir),
|
||||
)
|
||||
|
||||
@@ -45,8 +45,8 @@ class DownloadSettings(base.BaseData["DownloadSettings"]):
|
||||
@classmethod
|
||||
def create(cls: type[DownloadSettings]) -> DownloadSettings:
|
||||
return cls(
|
||||
batch_size=const.Default.BATCH_SIZE.value,
|
||||
process_delay=const.Default.PROCESS_DELAY.value,
|
||||
batch_size=const.DEFAULTS.BATCH_SIZE,
|
||||
process_delay=const.DEFAULTS.PROCESS_DELAY,
|
||||
)
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ class TrackSettings(base.BaseData["TrackSettings"]):
|
||||
|
||||
@classmethod
|
||||
def create(cls: type[TrackSettings]) -> TrackSettings:
|
||||
return cls(duration=const.Default.DURATION.value)
|
||||
return cls(duration=const.DEFAULTS.DURATION)
|
||||
|
||||
|
||||
@dataclasses.dataclass
|
||||
@@ -71,8 +71,8 @@ class PlaylistSettings(base.BaseData["PlaylistSettings"]):
|
||||
@classmethod
|
||||
def create(cls: type[PlaylistSettings]) -> PlaylistSettings:
|
||||
return cls(
|
||||
playtime=const.Default.PLAYTIME.value,
|
||||
max_tracks=const.Default.MAX_TRACKS.value,
|
||||
playtime=const.DEFAULTS.PLAYTIME,
|
||||
max_tracks=const.DEFAULTS.MAX_TRACKS,
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user