2017-08-07 06:58:32 +00:00
|
|
|
# This file is part of Supysonic.
|
2014-03-02 17:31:32 +00:00
|
|
|
# Supysonic is a Python implementation of the Subsonic server API.
|
|
|
|
#
|
2020-11-08 14:39:09 +00:00
|
|
|
# Copyright (C) 2013-2020 Alban 'spl0k' Féron
|
2017-08-07 06:58:32 +00:00
|
|
|
# 2017 Óscar García Amor
|
2014-03-02 17:31:32 +00:00
|
|
|
#
|
2017-08-07 06:58:32 +00:00
|
|
|
# Distributed under terms of the GNU AGPLv3 license.
|
2014-03-02 17:31:32 +00:00
|
|
|
|
2017-08-07 06:58:32 +00:00
|
|
|
import os
|
2020-11-08 14:39:09 +00:00
|
|
|
import sys
|
2017-08-07 06:58:32 +00:00
|
|
|
import tempfile
|
2012-10-13 09:29:48 +00:00
|
|
|
|
2019-12-23 15:23:57 +00:00
|
|
|
from configparser import RawConfigParser
|
|
|
|
|
2019-04-10 19:14:46 +00:00
|
|
|
current_config = None
|
2019-06-29 15:25:44 +00:00
|
|
|
|
|
|
|
|
2019-04-10 19:14:46 +00:00
|
|
|
def get_current_config():
|
|
|
|
return current_config or DefaultConfig()
|
|
|
|
|
2019-06-29 15:25:44 +00:00
|
|
|
|
2020-11-22 15:12:14 +00:00
|
|
|
class DefaultConfig:
|
2017-11-27 21:30:13 +00:00
|
|
|
DEBUG = False
|
2017-08-08 08:37:22 +00:00
|
|
|
|
2019-06-29 15:25:44 +00:00
|
|
|
tempdir = os.path.join(tempfile.gettempdir(), "supysonic")
|
2017-11-27 21:30:13 +00:00
|
|
|
BASE = {
|
2019-06-29 15:25:44 +00:00
|
|
|
"database_uri": "sqlite:///" + os.path.join(tempdir, "supysonic.db"),
|
|
|
|
"scanner_extensions": None,
|
2019-07-06 15:04:08 +00:00
|
|
|
"follow_symlinks": False,
|
2017-11-27 21:30:13 +00:00
|
|
|
}
|
|
|
|
WEBAPP = {
|
2019-06-29 15:25:44 +00:00
|
|
|
"cache_dir": tempdir,
|
|
|
|
"cache_size": 1024,
|
|
|
|
"transcode_cache_size": 512,
|
|
|
|
"log_file": None,
|
|
|
|
"log_level": "WARNING",
|
|
|
|
"mount_webui": True,
|
|
|
|
"mount_api": True,
|
2020-11-09 16:31:04 +00:00
|
|
|
"index_ignored_prefixes": "El La Le Las Les Los The",
|
2017-11-27 21:30:13 +00:00
|
|
|
}
|
|
|
|
DAEMON = {
|
2020-11-08 14:39:09 +00:00
|
|
|
"socket": r"\\.\pipe\supysonic"
|
|
|
|
if sys.platform == "win32"
|
|
|
|
else os.path.join(tempdir, "supysonic.sock"),
|
2019-06-29 15:25:44 +00:00
|
|
|
"run_watcher": True,
|
|
|
|
"wait_delay": 5,
|
2019-09-01 12:55:44 +00:00
|
|
|
"jukebox_command": None,
|
2019-06-29 15:25:44 +00:00
|
|
|
"log_file": None,
|
|
|
|
"log_level": "WARNING",
|
2017-11-27 21:30:13 +00:00
|
|
|
}
|
2019-06-29 15:25:44 +00:00
|
|
|
LASTFM = {"api_key": None, "secret": None}
|
2017-11-27 21:30:13 +00:00
|
|
|
TRANSCODING = {}
|
|
|
|
MIMETYPES = {}
|
2017-08-08 08:37:22 +00:00
|
|
|
|
2019-04-10 19:14:46 +00:00
|
|
|
def __init__(self):
|
|
|
|
current_config = self
|
|
|
|
|
2019-06-29 15:25:44 +00:00
|
|
|
|
2017-11-27 21:30:13 +00:00
|
|
|
class IniConfig(DefaultConfig):
|
|
|
|
common_paths = [
|
2019-06-29 15:25:44 +00:00
|
|
|
"/etc/supysonic",
|
|
|
|
os.path.expanduser("~/.supysonic"),
|
|
|
|
os.path.expanduser("~/.config/supysonic/supysonic.conf"),
|
|
|
|
"supysonic.conf",
|
2017-11-27 21:30:13 +00:00
|
|
|
]
|
2013-07-15 12:37:51 +00:00
|
|
|
|
2017-11-27 21:30:13 +00:00
|
|
|
def __init__(self, paths):
|
2020-11-22 15:12:14 +00:00
|
|
|
super().__init__()
|
2019-04-10 19:14:46 +00:00
|
|
|
|
2018-01-08 18:17:00 +00:00
|
|
|
parser = RawConfigParser()
|
2017-11-27 21:30:13 +00:00
|
|
|
parser.read(paths)
|
2013-07-15 12:37:51 +00:00
|
|
|
|
2017-11-27 21:30:13 +00:00
|
|
|
for section in parser.sections():
|
2019-06-29 15:25:44 +00:00
|
|
|
options = {k: self.__try_parse(v) for k, v in parser.items(section)}
|
2017-11-27 21:30:13 +00:00
|
|
|
section = section.upper()
|
2017-11-29 19:09:48 +00:00
|
|
|
|
2017-11-27 21:30:13 +00:00
|
|
|
if hasattr(self, section):
|
|
|
|
getattr(self, section).update(options)
|
|
|
|
else:
|
|
|
|
setattr(self, section, options)
|
2013-07-15 12:37:51 +00:00
|
|
|
|
2017-11-29 19:09:48 +00:00
|
|
|
@staticmethod
|
|
|
|
def __try_parse(value):
|
|
|
|
try:
|
|
|
|
return int(value)
|
|
|
|
except ValueError:
|
2017-12-05 21:15:04 +00:00
|
|
|
try:
|
|
|
|
return float(value)
|
|
|
|
except ValueError:
|
|
|
|
lv = value.lower()
|
2019-06-29 15:25:44 +00:00
|
|
|
if lv in ("yes", "true", "on"):
|
2017-12-05 21:15:04 +00:00
|
|
|
return True
|
2019-09-14 10:39:05 +00:00
|
|
|
if lv in ("no", "false", "off"):
|
2017-12-05 21:15:04 +00:00
|
|
|
return False
|
|
|
|
return value
|
2017-11-29 19:09:48 +00:00
|
|
|
|
2017-11-27 21:30:13 +00:00
|
|
|
@classmethod
|
|
|
|
def from_common_locations(cls):
|
|
|
|
return IniConfig(cls.common_paths)
|