music-kraken-core/music_kraken/utils/debug_utils.py

22 lines
531 B
Python
Raw Normal View History

2023-07-27 21:05:49 +00:00
from pathlib import Path
import json
from .path_manager import LOCATIONS
def dump_to_file(file_name: str, payload: str, is_json: bool = False, exit_after_dump: bool = True):
path = Path(LOCATIONS.TEMP_DIRECTORY, file_name)
print(f"Dumping payload to: \"{path}\"")
if is_json:
payload = json.dumps(json.loads(payload), indent=4)
2024-01-16 12:55:24 +00:00
if isinstance(payload, dict):
payload = json.dumps(payload, indent=4)
2023-07-27 21:05:49 +00:00
with path.open("w") as f:
f.write(payload)
if exit_after_dump:
exit()