Skip to content

Commit

Permalink
Merge pull request #1569 from glensc/sync-server-config
Browse files Browse the repository at this point in the history
  • Loading branch information
glensc authored Sep 4, 2023
2 parents d23a2e7 + d74e4a5 commit 0892ab3
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 12 deletions.
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

0 comments on commit 0892ab3

Please sign in to comment.