clan-core/pkgs/moonlight-sunshine-accept/moonlight_sunshine_accept/sunshine/config.py
a-kenji 32d0f1ccd4
All checks were successful
checks / check-links (pull_request) Successful in 21s
checks / checks (pull_request) Successful in 33s
checks / checks-impure (pull_request) Successful in 1m48s
init: sunshine-moonlight-accept module
2024-03-19 12:11:09 +01:00

49 lines
1.6 KiB
Python

import configparser
import os
# address_family = both
# channels = 5
# pkey = /var/lib/sunshine/sunshine.key
# cert = /var/lib/sunshine/sunshine.cert
# file_state = /var/lib/sunshine/state.json
# credentials_file = /var/lib/sunshine/credentials.json
PSEUDO_SECTION = "DEFAULT"
class Config:
_instance = None
def __new__(cls, config_location: str | None = None) -> "Config":
if cls._instance is None:
cls._instance = super().__new__(cls)
cls._instance.config = configparser.ConfigParser()
config = config_location or cls._instance.default_sunshine_config_file()
cls._instance._config_location = config
with open(config) as f:
config_string = f"[{PSEUDO_SECTION}]\n" + f.read()
print(config_string)
cls._instance.config.read_string(config_string)
return cls._instance
def config_location(self) -> str:
return self._config_location
def default_sunshine_config_dir(self) -> str:
return os.path.join(os.path.expanduser("~"), ".config", "sunshine")
def default_sunshine_config_file(self) -> str:
return os.path.join(self.default_sunshine_config_dir(), "sunshine.conf")
def get_private_key(self) -> str:
return self.config.get(PSEUDO_SECTION, "pkey")
def get_certificate(self) -> str:
return self.config.get(PSEUDO_SECTION, "cert")
def get_state_file(self) -> str:
return self.config.get(PSEUDO_SECTION, "file_state")
def get_credentials_file(self) -> str:
return self.config.get(PSEUDO_SECTION, "credentials_file")