Refactor add_server to take kwargs
MODIFY
plextraktsync/commands/plex_login.py
plextraktsync/commands/plex_login.py
from plexapi.myplex import MyPlexAccount, MyPlexResource, ResourceConnection
from plexapi.server import PlexServer
-from plextraktsync.config.PlexServerConfig import PlexServerConfig
from plextraktsync.config.ServerConfig import ServerConfig
from plextraktsync.factory import factory
from plextraktsync.style import (comment, disabled, error, highlight, prompt,
@@ -218,7 +217,8 @@ def login(username: str, password: str):
CONFIG["PLEX_SERVER"] = server.name
CONFIG.save()
- psc = PlexServerConfig(
+ sc = ServerConfig()
+ sc.add_server(
name=server.name,
token=token,
urls=[
@@ -226,8 +226,6 @@ def login(username: str, password: str):
local_url(),
],
)
- sc = ServerConfig()
- sc.add_server(psc)
sc.save()
click.echo(SUCCESS_MESSAGE)

MODIFY
plextraktsync/config/ServerConfig.py
plextraktsync/config/ServerConfig.py
-from dataclasses import asdict
from os.path import exists
from plextraktsync.config.ConfigLoader import ConfigLoader
@@ -40,14 +39,14 @@ def load(self):
def migrate(self):
from plextraktsync.factory import factory
config = factory.config()
- self.add_server(PlexServerConfig(
+ self.add_server(
name="default",
urls=[
config["PLEX_BASEURL"],
config["PLEX_LOCALURL"],
],
token=config["PLEX_TOKEN"],
- ))
+ )
self.save()
config["PLEX_SERVER"] = "default"
config.save()
@@ -60,11 +59,10 @@ def save(self):
"servers": self.servers,
})
- def add_server(self, config: PlexServerConfig):
+ def add_server(self, **kwargs):
self.load()
- data = asdict(config)
- del data["name"]
+ config = PlexServerConfig(**kwargs)
servers = {
- config.name: data,
+ config.name: config.asdict(),
}
self.merge(servers, self.servers)

Refactor add_server to take kwargs