mirror of
https://github.com/onyx-and-iris/obsws-python.git
synced 2024-11-22 04:40:53 +00:00
adds get_filepath
traverses a list of paths for config.toml
This commit is contained in:
parent
5e68262a80
commit
91ba90056c
@ -4,6 +4,7 @@ import json
|
|||||||
import logging
|
import logging
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from random import randint
|
from random import randint
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
import websocket
|
import websocket
|
||||||
|
|
||||||
@ -36,11 +37,26 @@ class ObsClient:
|
|||||||
import tomllib
|
import tomllib
|
||||||
except ModuleNotFoundError:
|
except ModuleNotFoundError:
|
||||||
import tomli as tomllib
|
import tomli as tomllib
|
||||||
|
|
||||||
|
def get_filepath() -> Optional[Path]:
|
||||||
|
"""
|
||||||
|
traverses a list of paths for a 'config.toml'
|
||||||
|
returns the first config file found or None.
|
||||||
|
"""
|
||||||
|
filepaths = [
|
||||||
|
Path.cwd() / "config.toml",
|
||||||
|
Path.home() / "config.toml",
|
||||||
|
Path.home() / ".config" / "obsws-python" / "config.toml",
|
||||||
|
]
|
||||||
|
for filepath in filepaths:
|
||||||
|
if filepath.exists():
|
||||||
|
return filepath
|
||||||
|
|
||||||
conn = {}
|
conn = {}
|
||||||
filepath = Path.cwd() / "config.toml"
|
if filepath := get_filepath():
|
||||||
if filepath.exists():
|
|
||||||
with open(filepath, "rb") as f:
|
with open(filepath, "rb") as f:
|
||||||
conn = tomllib.load(f)
|
conn = tomllib.load(f)
|
||||||
|
self.logger.info(f"loading config from {filepath}")
|
||||||
return conn["connection"] if "connection" in conn else conn
|
return conn["connection"] if "connection" in conn else conn
|
||||||
|
|
||||||
def authenticate(self):
|
def authenticate(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user