Merge pull request #24 from onyx-and-iris/dev

check user home directory for config.toml
This commit is contained in:
Adem 2023-03-11 22:48:43 +03:00 committed by GitHub
commit 9c41f2bb59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 24 additions and 8 deletions

View File

@ -43,7 +43,7 @@ port = 4455
password = "mystrongpass"
```
It should be placed next to your `__main__.py` file.
It should be placed in your user home directory.
#### Otherwise:

View File

@ -6,7 +6,7 @@ Registers a list of callback functions to hook into OBS events.
Simply run the code and trigger the events, press `<Enter>` to exit.
This example assumes the existence of a `config.toml`, placed next to `__main__.py`:
This example assumes the existence of a `config.toml`, placed in your user home directory:
```toml
[connection]

View File

@ -8,7 +8,7 @@ Requires [Python Keyboard library](https://github.com/boppreh/keyboard).
Simply run the code and press the assigned hotkeys. Press `ctrl+enter` to exit.
This example assumes the existence of a `config.toml`, placed next to `__main__.py`:
This example assumes the existence of a `config.toml`, placed in your user home directory:
```toml
[connection]

View File

@ -4,7 +4,7 @@ Prints POSTFADER level values for audio device `Desktop Audio`. If mute toggled
## Use
This example assumes the existence of a `config.toml`, placed next to `__main__.py`:
This example assumes the existence of a `config.toml`, placed in your user home directory:
```toml
[connection]

View File

@ -4,7 +4,7 @@ Collects the names of all available scenes, rotates through them and prints thei
## Use
This example assumes the existence of a `config.toml`, placed next to `__main__.py`:
This example assumes the existence of a `config.toml`, placed in your user home directory:
```toml
[connection]

View File

@ -4,6 +4,7 @@ import json
import logging
from pathlib import Path
from random import randint
from typing import Optional
import websocket
@ -36,11 +37,26 @@ class ObsClient:
import tomllib
except ModuleNotFoundError:
import tomli as tomllib
conn = {}
filepath = Path.cwd() / "config.toml"
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 = {}
if filepath := get_filepath():
with open(filepath, "rb") as f:
conn = tomllib.load(f)
self.logger.info(f"loading config from {filepath}")
return conn["connection"] if "connection" in conn else conn
def authenticate(self):

View File

@ -1 +1 @@
version = "1.4.1"
version = "1.4.2"