Ensure the paths exists
Application crashes in every corner if can't create config or create
logs.
import site
-from os import getenv
-from os.path import abspath, dirname, join
+from os import getenv, makedirs
+from os.path import abspath, dirname, join, exists
from plex_trakt_sync.decorators.memoize import memoize
@@ -11,6 +11,10 @@ def __init__(self):
self.module_path = dirname(abspath(__file__))
self.app_path = dirname(self.module_path)
+ self.ensure_dir(self.config_dir)
+ self.ensure_dir(self.log_dir)
+ self.ensure_dir(self.cache_dir)
+
self.default_config_file = join(self.module_path, "config.default.json")
self.config_file = join(self.config_dir, "config.json")
self.pytrakt_file = join(self.config_dir, ".pytrakt.json")
@@ -58,6 +62,12 @@ def installed(self):
return absdir in paths
+ @staticmethod
+ def ensure_dir(directory):
+ if not exists(directory):
+ makedirs(directory)
+
+
p = Path()
cache_dir = p.cache_dir
