Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix/File Exists Error on test_directories #4338

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions openbb_terminal/core/log/generation/directories.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# IMPORTATION STANDARD
import os
import uuid
from pathlib import Path

Expand All @@ -14,25 +13,23 @@
def get_log_dir() -> Path:
"""Retrieve application's log directory."""

log_dir = USER_DATA_DIRECTORY.joinpath("logs")
log_dir = USER_DATA_DIRECTORY.joinpath("logs").absolute()

if not os.path.isdir(log_dir.absolute()):
os.mkdir(log_dir.absolute())
if not log_dir.is_dir():
log_dir.mkdir(parents=True, exist_ok=True)

log_id = log_dir.absolute().joinpath(".logid")
log_id = (log_dir / ".logid").absolute()

if not os.path.isfile(log_id.absolute()):
if not log_id.is_file():
logging_id = f"{uuid.uuid4()}"
with open(log_id.absolute(), "a") as a_file:
a_file.write(f"{logging_id}\n")
log_id.write_text(logging_id, encoding="utf-8")
else:
with open(log_id.absolute()) as a_file:
logging_id = a_file.readline().rstrip()
logging_id = log_id.read_text(encoding="utf-8").rstrip()

uuid_log_dir = log_dir.absolute().joinpath(logging_id)
uuid_log_dir = (log_dir / logging_id).absolute()

if not os.path.isdir(uuid_log_dir.absolute()):
os.mkdir(uuid_log_dir.absolute())
if not uuid_log_dir.is_dir():
uuid_log_dir.mkdir(parents=True, exist_ok=True)

return uuid_log_dir

Expand Down