Add config file for specifying backends

This commit is contained in:
2022-09-13 22:16:51 -06:00
parent afb7a456a1
commit 3227730a37
3 changed files with 49 additions and 11 deletions
+34 -9
View File
@@ -1,5 +1,6 @@
from typing import Type from typing import Type
import os
import sys import sys
from urllib import parse from urllib import parse
@@ -20,6 +21,7 @@ from PyQt5.QtGui import QImage
from .qtmpv import MpvObject from .qtmpv import MpvObject
import requests import requests
import toml
class Episode(QObject): class Episode(QObject):
@@ -186,6 +188,31 @@ def DatabaseType(data_source) -> Type:
return Database return Database
def load_config() -> list[str]:
try:
config_dir: str = os.path.join(os.environ["XDG_CONFIG_HOME"], "ikinuki")
except:
config_dir: str = os.path.join(os.environ["HOME"], ".config", "ikinuki")
os.makedirs(config_dir, exist_ok=True)
config_file: str = os.path.join(config_dir, "client.toml")
try:
config: dict = toml.load(config_file)
except FileNotFoundError:
print(f'Config file not found at "{config_file}"')
print("Writing example config file. Please update and relaunch.")
default_config = """# [[backends]]
# address = "127.0.0.1"
# port = 32520"""
with open(config_file, "w") as f:
f.write(default_config)
sys.exit(-1)
return [f'http://{b["address"]}:{b["port"]}/' for b in config["backends"]]
def main(): def main():
app = QApplication(sys.argv) app = QApplication(sys.argv)
@@ -194,15 +221,13 @@ def main():
locale.setlocale(locale.LC_NUMERIC, "C") locale.setlocale(locale.LC_NUMERIC, "C")
data_source = DataSource( try:
[ backends: list[str] = load_config()
# "http://127.0.0.1:8080/a/", except Exception as e:
# "http://127.0.0.1:8080/b/", print(f"ERROR: Could not load config file: {repr(e)}")
# "http://127.0.0.1:8080/c/", sys.exit(-1)
"http://127.0.0.1:32520/",
] data_source = DataSource(backends)
)
# data_source = DataSource([])
qmlRegisterType(DatabaseType(data_source), "Ikinuki.Client", 1, 0, "Database") qmlRegisterType(DatabaseType(data_source), "Ikinuki.Client", 1, 0, "Database")
# qmlRegisterType(Provider, "Ikinuki.Client", 1, 0, "Provider") # qmlRegisterType(Provider, "Ikinuki.Client", 1, 0, "Provider")
Generated
+14 -2
View File
@@ -62,7 +62,7 @@ optional = false
python-versions = ">=3.5" python-versions = ">=3.5"
[package.extras] [package.extras]
screenshot_raw = ["pillow"] screenshot_raw = ["Pillow"]
[[package]] [[package]]
name = "requests" name = "requests"
@@ -82,6 +82,14 @@ urllib3 = ">=1.21.1,<1.27"
socks = ["PySocks (>=1.5.6,!=1.5.7)"] socks = ["PySocks (>=1.5.6,!=1.5.7)"]
use_chardet_on_py3 = ["chardet (>=3.0.2,<6)"] use_chardet_on_py3 = ["chardet (>=3.0.2,<6)"]
[[package]]
name = "toml"
version = "0.10.2"
description = "Python Library for Tom's Obvious, Minimal Language"
category = "main"
optional = false
python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*"
[[package]] [[package]]
name = "urllib3" name = "urllib3"
version = "1.26.12" version = "1.26.12"
@@ -98,7 +106,7 @@ socks = ["PySocks (>=1.5.6,!=1.5.7,<2.0)"]
[metadata] [metadata]
lock-version = "1.1" lock-version = "1.1"
python-versions = "^3.10" python-versions = "^3.10"
content-hash = "7e77956c19bb0148f37be8283857fbd29805184149d6f2c1027daab624c66b80" content-hash = "ab4b6be20253adf487e007f81b07f9f585bd4a61d4e51889f9356dfc0e03e206"
[metadata.files] [metadata.files]
certifi = [ certifi = [
@@ -152,6 +160,10 @@ requests = [
{file = "requests-2.28.1-py3-none-any.whl", hash = "sha256:8fefa2a1a1365bf5520aac41836fbee479da67864514bdb821f31ce07ce65349"}, {file = "requests-2.28.1-py3-none-any.whl", hash = "sha256:8fefa2a1a1365bf5520aac41836fbee479da67864514bdb821f31ce07ce65349"},
{file = "requests-2.28.1.tar.gz", hash = "sha256:7c5599b102feddaa661c826c56ab4fee28bfd17f5abca1ebbe3e7f19d7c97983"}, {file = "requests-2.28.1.tar.gz", hash = "sha256:7c5599b102feddaa661c826c56ab4fee28bfd17f5abca1ebbe3e7f19d7c97983"},
] ]
toml = [
{file = "toml-0.10.2-py2.py3-none-any.whl", hash = "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b"},
{file = "toml-0.10.2.tar.gz", hash = "sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"},
]
urllib3 = [ urllib3 = [
{file = "urllib3-1.26.12-py2.py3-none-any.whl", hash = "sha256:b930dd878d5a8afb066a637fbb35144fe7901e3b209d1cd4f524bd0e9deee997"}, {file = "urllib3-1.26.12-py2.py3-none-any.whl", hash = "sha256:b930dd878d5a8afb066a637fbb35144fe7901e3b209d1cd4f524bd0e9deee997"},
{file = "urllib3-1.26.12.tar.gz", hash = "sha256:3fa96cf423e6987997fc326ae8df396db2a8b7c667747d47ddd8ecba91f4a74e"}, {file = "urllib3-1.26.12.tar.gz", hash = "sha256:3fa96cf423e6987997fc326ae8df396db2a8b7c667747d47ddd8ecba91f4a74e"},
+1
View File
@@ -10,6 +10,7 @@ python = "^3.10"
python-mpv = "^0.5.2" python-mpv = "^0.5.2"
PyQt5 = "^5.15.1" PyQt5 = "^5.15.1"
requests = "^2.28.1" requests = "^2.28.1"
toml = "^0.10.2"
[tool.poetry.scripts] [tool.poetry.scripts]