Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Add config support for servers.yml #1569

Merged
merged 7 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions plextraktsync/config/Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,6 @@ def http_cache(self):

return HttpCacheConfig(**cache)

@property
def sync(self):
from plextraktsync.config.SyncConfig import SyncConfig

return SyncConfig(self)

def initialize(self):
"""
Config load order:
Expand Down
8 changes: 8 additions & 0 deletions plextraktsync/config/PlexServerConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,17 @@ class PlexServerConfig:
urls: list[str]
# The machineIdentifier value of this server
id: str = None
config: dict = None

def asdict(self):
data = asdict(self)
del data["name"]

return data

@property
def sync_config(self):
if self.config is None or "sync" not in self.config or self.config["sync"] is None:
return {}

return self.config["sync"]
7 changes: 6 additions & 1 deletion plextraktsync/config/SyncConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@

if TYPE_CHECKING:
from plextraktsync.config.Config import Config
from plextraktsync.config.PlexServerConfig import PlexServerConfig


class SyncConfig:
def __init__(self, config: Config):
def __init__(self, config: Config, server_config: PlexServerConfig):
self.config = dict(config["sync"])
self.server_config = server_config.sync_config

def __getitem__(self, key):
return self.config[key]
Expand All @@ -18,6 +20,9 @@ def __contains__(self, key):
return key in self.config

def get(self, section, key):
if section in self.server_config and key in self.server_config[section]:
return self.server_config[section][key]

return self[key] if key in self else self[section][key]

@cached_property
Expand Down
6 changes: 3 additions & 3 deletions plextraktsync/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
if TYPE_CHECKING:
from typing import Iterable

from plextraktsync.config.Config import Config
from plextraktsync.config.SyncConfig import SyncConfig
from plextraktsync.media import Media
from plextraktsync.plex.PlexApi import PlexApi
from plextraktsync.trakt.TraktApi import TraktApi
from plextraktsync.walker import Walker


class Sync:
def __init__(self, config: Config, plex: PlexApi, trakt: TraktApi):
self.config = config.sync
def __init__(self, config: SyncConfig, plex: PlexApi, trakt: TraktApi):
self.config = config
self.plex = plex
self.trakt = trakt

Expand Down
9 changes: 7 additions & 2 deletions plextraktsync/util/Factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,10 @@ def session(self):
def sync(self):
from plextraktsync.sync import Sync

config = self.config
plex = self.plex_api
trakt = self.trakt_api

return Sync(config, plex, trakt)
return Sync(self.sync_config, plex, trakt)

@cached_property
def progressbar(self):
Expand Down Expand Up @@ -284,6 +283,12 @@ def invalidate_plex_cache(key, value):

return config

@property
def sync_config(self):
from plextraktsync.config.SyncConfig import SyncConfig

return SyncConfig(self.config, self.server_config)

@cached_property
def queue(self):
from plextraktsync.queue.BackgroundTask import BackgroundTask
Expand Down
Loading