Skip to content

Commit

Permalink
Refactor Plugin.enabled to take config argument
Browse files Browse the repository at this point in the history
  • Loading branch information
glensc committed Apr 10, 2024
1 parent e14687c commit 0a86d09
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 14 deletions.
5 changes: 3 additions & 2 deletions plextraktsync/sync/ClearCollectedPlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from plextraktsync.plugin import hookimpl

if TYPE_CHECKING:
from plextraktsync.config.SyncConfig import SyncConfig
from plextraktsync.sync.Sync import Sync
from plextraktsync.trakt.TraktApi import TraktApi
from plextraktsync.trakt.types import TraktMedia
Expand All @@ -23,8 +24,8 @@ def __init__(self, trakt: TraktApi):
self.trakt_lists = None

@classmethod
def enabled(cls, sync: Sync):
return sync.config.clear_collected
def enabled(cls, config: SyncConfig):
return config.clear_collected

@classmethod
def factory(cls, sync: Sync):
Expand Down
5 changes: 3 additions & 2 deletions plextraktsync/sync/LikedListsPlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from plextraktsync.plugin import hookimpl

if TYPE_CHECKING:
from plextraktsync.config.SyncConfig import SyncConfig
from plextraktsync.sync.Sync import Sync
from plextraktsync.trakt.TraktApi import TraktApi
from plextraktsync.trakt.TraktUserListCollection import \
Expand All @@ -19,8 +20,8 @@ def __init__(self, trakt: TraktApi):
self.trakt = trakt

@classmethod
def enabled(cls, sync: Sync):
return sync.config.sync_liked_lists
def enabled(cls, config: SyncConfig):
return config.sync_liked_lists

@classmethod
def factory(cls, sync: Sync):
Expand Down
5 changes: 3 additions & 2 deletions plextraktsync/sync/SyncCollectionPlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from plextraktsync.plugin import hookimpl

if TYPE_CHECKING:
from plextraktsync.config.SyncConfig import SyncConfig
from plextraktsync.media.Media import Media
from plextraktsync.sync.Sync import Sync

Expand All @@ -14,8 +15,8 @@ class SyncCollectionPlugin:
logger = logging.getLogger(__name__)

@classmethod
def enabled(cls, sync: Sync):
return sync.config.plex_to_trakt["collection"]
def enabled(cls, config: SyncConfig):
return config.plex_to_trakt["collection"]

@classmethod
def factory(cls, sync: Sync):
Expand Down
4 changes: 2 additions & 2 deletions plextraktsync/sync/SyncRatingsPlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def __init__(self, config: SyncConfig):
self.shows = None

@classmethod
def enabled(cls, sync: Sync):
return sync.config.sync_ratings
def enabled(cls, config: SyncConfig):
return config.sync_ratings

@classmethod
def factory(cls, sync: Sync):
Expand Down
4 changes: 2 additions & 2 deletions plextraktsync/sync/SyncWatchedPlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def __init__(self, config: SyncConfig):
self.trakt_to_plex = config.trakt_to_plex["watched_status"]

@classmethod
def enabled(cls, sync: Sync):
return sync.config.sync_watched_status
def enabled(cls, config: SyncConfig):
return config.sync_watched_status

@classmethod
def factory(cls, sync: Sync):
Expand Down
6 changes: 3 additions & 3 deletions plextraktsync/sync/WatchListPlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ def __init__(self, config: SyncConfig, plex: PlexApi, trakt: TraktApi):
self.trakt = trakt

@classmethod
def enabled(cls, sync: Sync):
def enabled(cls, config: SyncConfig):
return any([
sync.config.plex_to_trakt["watchlist"],
sync.config.trakt_to_plex["watchlist"],
config.plex_to_trakt["watchlist"],
config.trakt_to_plex["watchlist"],
])

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion plextraktsync/sync/plugin/SyncPluginManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def plugins(self):

def register_plugins(self, sync: Sync):
for plugin in self.plugins:
enabled = plugin.enabled(sync)
enabled = plugin.enabled(sync.config)
self.logger.info(f"Enable sync plugin '{plugin.__name__}': {enabled}")
if not enabled:
continue
Expand Down

0 comments on commit 0a86d09

Please sign in to comment.