Fixed issue with cache location not working on first start
This commit is contained in:
@@ -15,7 +15,8 @@ from libremsonic.server.api_objects import Playlist, PlaylistWithSongs, Child
|
||||
|
||||
class Singleton(type):
|
||||
def __getattr__(cls, name):
|
||||
if CacheManager._instance:
|
||||
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.)
|
||||
|
@@ -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):
|
||||
|
Reference in New Issue
Block a user