mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-28 13:01:38 +00:00
Logging : masOS+DiscordBot (#1580)
* Log Generation : refactor log_dir handling * Data Collection : fix boto3 edge case * Logging : linting
This commit is contained in:
@@ -86,7 +86,7 @@ class LogSender(Thread):
|
||||
file=file,
|
||||
object_key=object_key,
|
||||
tmp_file=tmp_file,
|
||||
copy=last,
|
||||
last=last,
|
||||
)
|
||||
except Exception:
|
||||
self.fails_increment()
|
||||
|
||||
@@ -83,7 +83,7 @@ def send_to_s3(
|
||||
file: Path,
|
||||
object_key: str,
|
||||
tmp_file: Path,
|
||||
copy: bool = False,
|
||||
last: bool = False,
|
||||
):
|
||||
api_url = DEFAULT_API_URL
|
||||
bucket = DEFAULT_BUCKET
|
||||
@@ -94,13 +94,14 @@ def send_to_s3(
|
||||
|
||||
tmp_file.parent.mkdir(exist_ok=True)
|
||||
|
||||
if copy:
|
||||
if last:
|
||||
copyfile(file, tmp_file)
|
||||
else:
|
||||
file.rename(tmp_file)
|
||||
|
||||
if (
|
||||
aws_settings.aws_access_key_id != "REPLACE_ME"
|
||||
not last
|
||||
and aws_settings.aws_access_key_id != "REPLACE_ME"
|
||||
and aws_settings.aws_secret_access_key != "REPLACE_ME"
|
||||
):
|
||||
send_to_s3_directly(
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
# IMPORTATION STANDARD
|
||||
import os
|
||||
import uuid
|
||||
from pathlib import Path
|
||||
|
||||
@@ -12,28 +11,23 @@ from pathlib import Path
|
||||
def get_log_dir() -> Path:
|
||||
"""Retrieve application's log directory."""
|
||||
|
||||
file_path = Path(__file__)
|
||||
log_dir = file_path.parent.parent.parent.parent.absolute().joinpath("logs")
|
||||
log_dir = Path(__file__).parent.parent.parent.parent.joinpath("logs")
|
||||
log_dir.mkdir(exist_ok=True)
|
||||
logid_file = log_dir.joinpath(".logid")
|
||||
|
||||
if not os.path.isdir(log_dir.absolute()):
|
||||
os.mkdir(log_dir.absolute())
|
||||
if not logid_file.is_file():
|
||||
logid = str(uuid.uuid4())
|
||||
|
||||
log_id = log_dir.absolute().joinpath(".logid")
|
||||
|
||||
if not os.path.isfile(log_id.absolute()):
|
||||
logging_id = f"{uuid.uuid4()}"
|
||||
with open(log_id.absolute(), "a") as a_file:
|
||||
a_file.write(f"{logging_id}\n")
|
||||
with open(logid_file, "w") as f:
|
||||
f.write(f"{logid}\n")
|
||||
else:
|
||||
with open(log_id.absolute()) as a_file:
|
||||
logging_id = a_file.readline().rstrip()
|
||||
with open(logid_file) as a_file:
|
||||
logid = a_file.readline().rstrip()
|
||||
|
||||
uuid_log_dir = log_dir.absolute().joinpath(logging_id)
|
||||
logid_dir = log_dir.joinpath(logid)
|
||||
logid_dir.mkdir(exist_ok=True)
|
||||
|
||||
if not os.path.isdir(uuid_log_dir.absolute()):
|
||||
os.mkdir(uuid_log_dir.absolute())
|
||||
|
||||
return uuid_log_dir
|
||||
return logid_dir
|
||||
|
||||
|
||||
def get_log_sub_dir(name: str):
|
||||
|
||||
@@ -51,7 +51,18 @@ START_TIMESTAMP = int(time.time())
|
||||
def get_app_id() -> str:
|
||||
"""UUID of the current installation."""
|
||||
|
||||
app_id = get_log_dir().stem
|
||||
try:
|
||||
app_id = get_log_dir().stem
|
||||
except OSError as e:
|
||||
if e.errno == 30:
|
||||
print("Please move the application into a writable location.")
|
||||
print(
|
||||
"Note for macOS users: copy `Gamestonk Terminal` folder outside the DMG."
|
||||
)
|
||||
else:
|
||||
raise e
|
||||
except Exception as e:
|
||||
raise e
|
||||
|
||||
return app_id
|
||||
|
||||
|
||||
Reference in New Issue
Block a user