Make path module dynamic using class
MODIFY
plex_trakt_sync/config.py
plex_trakt_sync/config.py
from dotenv import load_dotenv
-from plex_trakt_sync.path import (PTS_CACHE_DIR, config_file,
+from plex_trakt_sync.path import (cache_dir, config_file,
default_config_file, env_file)
"""
@@ -57,7 +57,7 @@ def initialize(self):
self.initialized = True
- self["cache"]["path"] = self["cache"]["path"].replace("$PTS_CACHE_DIR", PTS_CACHE_DIR)
+ self["cache"]["path"] = self["cache"]["path"].replace("$PTS_CACHE_DIR", cache_dir)
def save(self):
with open(self.env_file, "w") as txt:

MODIFY
plex_trakt_sync/path.py
plex_trakt_sync/path.py
+import site
from os import getenv
from os.path import abspath, dirname, join
-app_path = dirname(dirname(abspath(__file__)))
-PTS_CONFIG_DIR = getenv("PTS_CONFIG_DIR", app_path)
-PTS_CACHE_DIR = getenv("PTS_CACHE_DIR", app_path)
-PTS_LOG_DIR = getenv("PTS_LOG_DIR", app_path)
+class Path:
+ def __init__(self):
+ self.app_path = dirname(dirname(abspath(__file__)))
-default_config_file = join(app_path, "config.default.json")
-config_file = join(PTS_CONFIG_DIR, "config.json")
-pytrakt_file = join(PTS_CONFIG_DIR, ".pytrakt.json")
-env_file = join(PTS_CONFIG_DIR, ".env")
-log_file = join(PTS_LOG_DIR, "last_update.log")
+ self.default_config_file = join(self.app_path, "config.default.json")
+ self.config_file = join(self.config_dir, "config.json")
+ self.pytrakt_file = join(self.config_dir, ".pytrakt.json")
+ self.env_file = join(self.config_dir, ".env")
+ self.log_file = join(self.log_dir, "last_update.log")
+
+ @property
+ def config_dir(self):
+ return getenv("PTS_CONFIG_DIR", self.app_path)
+
+ @property
+ def cache_dir(self):
+ return getenv("PTS_CACHE_DIR", self.app_path)
+
+ @property
+ def log_dir(self):
+ return getenv("PTS_LOG_DIR", self.app_path)
+
+
+p = Path()
+
+default_config_file = p.default_config_file
+config_file = p.config_file
+pytrakt_file = p.pytrakt_file
+env_file = p.env_file
+log_file = p.log_file
+cache_dir = p.cache_dir

Make path module dynamic using class