Fixed issue with cache location not working on first start
This commit is contained in:
@@ -15,14 +15,15 @@ from libremsonic.server.api_objects import Playlist, PlaylistWithSongs, Child
|
|||||||
|
|
||||||
class Singleton(type):
|
class Singleton(type):
|
||||||
def __getattr__(cls, name):
|
def __getattr__(cls, name):
|
||||||
if CacheManager._instance:
|
if not CacheManager._instance:
|
||||||
# If the cache has a function to do the thing we want, use it. If
|
CacheManager.reset(None, None)
|
||||||
# not, then go directly to the server (this is useful for things
|
# If the cache has a function to do the thing we want, use it. If
|
||||||
# that just send data to the server.)
|
# not, then go directly to the server (this is useful for things
|
||||||
if hasattr(CacheManager._instance, name):
|
# that just send data to the server.)
|
||||||
return getattr(CacheManager._instance, name)
|
if hasattr(CacheManager._instance, name):
|
||||||
else:
|
return getattr(CacheManager._instance, name)
|
||||||
return getattr(CacheManager._instance.server, name)
|
else:
|
||||||
|
return getattr(CacheManager._instance.server, name)
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@@ -39,30 +39,35 @@ class ServerConfiguration:
|
|||||||
class AppConfiguration:
|
class AppConfiguration:
|
||||||
servers: List[ServerConfiguration]
|
servers: List[ServerConfiguration]
|
||||||
current_server: int
|
current_server: int
|
||||||
cache_location: str
|
_cache_location: str
|
||||||
max_cache_size_mb: int # -1 means unlimited
|
max_cache_size_mb: int # -1 means unlimited
|
||||||
|
|
||||||
def to_json(self):
|
def to_json(self):
|
||||||
return {
|
return {
|
||||||
'servers': [s.__dict__ for s in self.servers],
|
'servers': [s.__dict__ for s in self.servers],
|
||||||
'current_server': self.current_server,
|
'current_server': self.current_server,
|
||||||
'cache_location': self.cache_location,
|
'_cache_location': self._cache_location,
|
||||||
'max_cache_size_mb': self.max_cache_size_mb,
|
'max_cache_size_mb': self.max_cache_size_mb,
|
||||||
}
|
}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_default_configuration(cls):
|
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 = AppConfiguration()
|
||||||
config.servers = []
|
config.servers = []
|
||||||
config.current_server = -1
|
config.current_server = -1
|
||||||
config.cache_location = default_cache_location
|
|
||||||
config.max_cache_size_mb = -1
|
config.max_cache_size_mb = -1
|
||||||
return config
|
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:
|
def get_config(filename: str) -> AppConfiguration:
|
||||||
if not os.path.exists(filename):
|
if not os.path.exists(filename):
|
||||||
|
Reference in New Issue
Block a user