summaryrefslogtreecommitdiffstats
path: root/cli/openbb_cli/utils/utils.py
blob: b38c83a8dabfa67ac5d44e645f767f345f4da124 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""OpenBB Platform CLI utilities."""

import json
from pathlib import Path

HOME_DIRECTORY = Path.home()
OPENBB_PLATFORM_DIRECTORY = Path(HOME_DIRECTORY, ".openbb_platform")
SYSTEM_SETTINGS_PATH = Path(OPENBB_PLATFORM_DIRECTORY, "system_settings.json")


def change_logging_sub_app() -> str:
    """Build OpenBB Platform setting files."""
    with open(SYSTEM_SETTINGS_PATH) as file:
        system_settings = json.load(file)

    initial_logging_sub_app = system_settings.get("logging_sub_app", "")

    system_settings["logging_sub_app"] = "cli"

    with open(SYSTEM_SETTINGS_PATH, "w") as file:
        json.dump(system_settings, file, indent=4)

    return initial_logging_sub_app


def reset_logging_sub_app(initial_logging_sub_app: str):
    """Reset OpenBB Platform setting files."""
    with open(SYSTEM_SETTINGS_PATH) as file:
        system_settings = json.load(file)

    system_settings["logging_sub_app"] = initial_logging_sub_app

    with open(SYSTEM_SETTINGS_PATH, "w") as file:
        json.dump(system_settings, file, indent=4)