From 85a70204d938d91a0087486590e82f19f993b852 Mon Sep 17 00:00:00 2001 From: Sumner Evans Date: Sun, 23 Jun 2019 18:59:53 -0600 Subject: [PATCH] Fixed issue with cache location not working on first start --- libremsonic/cache_manager.py | 17 +++++++++-------- libremsonic/config.py | 19 ++++++++++++------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/libremsonic/cache_manager.py b/libremsonic/cache_manager.py index 27440db..f86988e 100644 --- a/libremsonic/cache_manager.py +++ b/libremsonic/cache_manager.py @@ -15,14 +15,15 @@ from libremsonic.server.api_objects import Playlist, PlaylistWithSongs, Child class Singleton(type): def __getattr__(cls, name): - if CacheManager._instance: - # If the cache has a function to do the thing we want, use it. If - # not, then go directly to the server (this is useful for things - # that just send data to the server.) - if hasattr(CacheManager._instance, name): - return getattr(CacheManager._instance, name) - else: - return getattr(CacheManager._instance.server, name) + if not CacheManager._instance: + CacheManager.reset(None, None) + # If the cache has a function to do the thing we want, use it. If + # not, then go directly to the server (this is useful for things + # that just send data to the server.) + if hasattr(CacheManager._instance, name): + return getattr(CacheManager._instance, name) + else: + return getattr(CacheManager._instance.server, name) return None diff --git a/libremsonic/config.py b/libremsonic/config.py index 8c9e135..87ccf1c 100644 --- a/libremsonic/config.py +++ b/libremsonic/config.py @@ -39,30 +39,35 @@ class ServerConfiguration: class AppConfiguration: servers: List[ServerConfiguration] current_server: int - cache_location: str + _cache_location: str max_cache_size_mb: int # -1 means unlimited def to_json(self): return { 'servers': [s.__dict__ for s in self.servers], 'current_server': self.current_server, - 'cache_location': self.cache_location, + '_cache_location': self._cache_location, 'max_cache_size_mb': self.max_cache_size_mb, } @classmethod def get_default_configuration(cls): - default_cache_location = (os.environ.get('XDG_DATA_HOME') - or os.path.expanduser('~/.local/share')) - default_cache_location = os.path.join(default_cache_location, - 'libremsonic') config = AppConfiguration() config.servers = [] config.current_server = -1 - config.cache_location = default_cache_location config.max_cache_size_mb = -1 return config + @property + def cache_location(self): + if (hasattr(self, '_cache_location') + and self._cache_location is not None): + return self.cache_location + else: + default_cache_location = (os.environ.get('XDG_DATA_HOME') + or os.path.expanduser('~/.local/share')) + return os.path.join(default_cache_location, 'libremsonic') + def get_config(filename: str) -> AppConfiguration: if not os.path.exists(filename):