mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
added function to load global settings from mongo
This commit is contained in:
parent
a9442274ec
commit
e7781a4540
1 changed files with 38 additions and 0 deletions
|
|
@ -185,6 +185,44 @@ def validate_path_string(path: str) -> (bool, str):
|
|||
return True, "valid path"
|
||||
|
||||
|
||||
def get_pype_global_settings(url: str) -> dict:
|
||||
"""Load global settings from Mongo database.
|
||||
|
||||
We are loading data from database `pype` and collection `settings`.
|
||||
There we expect document type `global_settings`.
|
||||
|
||||
Returns:
|
||||
dict: With settings data. Empty dictionary is returned if not found.
|
||||
"""
|
||||
try:
|
||||
components = decompose_url(url)
|
||||
except RuntimeError:
|
||||
return {}
|
||||
mongo_kwargs = {
|
||||
"host": compose_url(**components),
|
||||
"serverSelectionTimeoutMS": 2000
|
||||
}
|
||||
port = components.get("port")
|
||||
if port is not None:
|
||||
mongo_kwargs["port"] = int(port)
|
||||
|
||||
try:
|
||||
# Create mongo connection
|
||||
client = MongoClient(**mongo_kwargs)
|
||||
# Access settings collection
|
||||
col = client["pype"]["settings"]
|
||||
# Query global settings
|
||||
global_settings = col.find_one({"type": "global_settings"}) or {}
|
||||
# Close Mongo connection
|
||||
client.close()
|
||||
|
||||
except Exception:
|
||||
# TODO log traceback or message
|
||||
return {}
|
||||
|
||||
return global_settings.get("data") or {}
|
||||
|
||||
|
||||
def get_pype_path_from_db(url: str) -> Union[str, None]:
|
||||
"""Get Pype path from database.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue