From 91ba90056c104e6219fd8678ecff41495bca861c Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Thu, 9 Mar 2023 01:34:44 +0000 Subject: [PATCH 1/3] adds get_filepath traverses a list of paths for config.toml --- obsws_python/baseclient.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/obsws_python/baseclient.py b/obsws_python/baseclient.py index e1dfc52..10e9d12 100644 --- a/obsws_python/baseclient.py +++ b/obsws_python/baseclient.py @@ -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 + + 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 = {} - filepath = Path.cwd() / "config.toml" - if filepath.exists(): + 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): From 2de71517398924279686c52835166773df38114e Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Thu, 9 Mar 2023 01:36:21 +0000 Subject: [PATCH 2/3] update README advises placing config.toml in user home dir --- README.md | 2 +- examples/events/README.md | 2 +- examples/hotkeys/README.md | 2 +- examples/levels/README.md | 2 +- examples/scene_rotate/README.md | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b1d2a44..6fa8c6b 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/examples/events/README.md b/examples/events/README.md index b9f450d..dff4936 100644 --- a/examples/events/README.md +++ b/examples/events/README.md @@ -6,7 +6,7 @@ Registers a list of callback functions to hook into OBS events. Simply run the code and trigger the events, press `` 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] diff --git a/examples/hotkeys/README.md b/examples/hotkeys/README.md index f800d8b..9526dc4 100644 --- a/examples/hotkeys/README.md +++ b/examples/hotkeys/README.md @@ -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] diff --git a/examples/levels/README.md b/examples/levels/README.md index 5780767..191f681 100644 --- a/examples/levels/README.md +++ b/examples/levels/README.md @@ -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] diff --git a/examples/scene_rotate/README.md b/examples/scene_rotate/README.md index 07ff2d6..56f9658 100644 --- a/examples/scene_rotate/README.md +++ b/examples/scene_rotate/README.md @@ -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] From d1c7462cc645f25d467c60eab1f1f2af8df10dda Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Thu, 9 Mar 2023 01:38:53 +0000 Subject: [PATCH 3/3] patch bump --- obsws_python/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/obsws_python/version.py b/obsws_python/version.py index 6abaa20..841aad2 100644 --- a/obsws_python/version.py +++ b/obsws_python/version.py @@ -1 +1 @@ -version = "1.4.1" +version = "1.4.2"