Skip to content

Commit b780f77

Browse files
authored
Merge pull request #1097 from andreaspagnolo/feature/catImage_onlyOnce
Feature/cat image only once
2 parents 2f80b66 + 56a36b3 commit b780f77

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

core/cat/log.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import sys
55
import json
66
import traceback
7+
import os
8+
from pathlib import Path
79
from pprint import pformat
810
from loguru import logger
911

@@ -143,25 +145,42 @@ def log(self, msg, level="DEBUG"):
143145
for line in lines:
144146
logger.log(level, line)
145147

148+
def _get_welcome_flag_path(self):
149+
"""Get the path for the welcome flag file."""
150+
return Path(".welcome_shown")
151+
152+
def _has_welcome_been_shown(self):
153+
"""Check if welcome message has been shown in this session."""
154+
flag_file = self._get_welcome_flag_path()
155+
return flag_file.exists()
156+
157+
def _mark_welcome_as_shown(self):
158+
"""Mark welcome message as shown."""
159+
flag_file = self._get_welcome_flag_path()
160+
flag_file.touch()
161+
146162
def welcome(self):
147-
"""Welcome message in the terminal."""
163+
"""Welcome message in the terminal."""
164+
165+
# Show full welcome message with ASCII cat
148166
secure = "s" if get_env("CCAT_CORE_USE_SECURE_PROTOCOLS") in ("true", "1") else ""
149167

150168
cat_host = get_env("CCAT_CORE_HOST")
151169
cat_port = get_env("CCAT_CORE_PORT")
152170
cat_address = f"http{secure}://{cat_host}:{cat_port}"
153171

154-
print("\n\n")
155-
with open("cat/welcome.txt", "r") as f:
156-
print(f.read())
172+
# Print ASCII cat only if welcome has not been shown already
173+
if not self._has_welcome_been_shown():
174+
print("\n\n")
175+
with open("cat/welcome.txt", "r") as f:
176+
print(f.read())
177+
# Mark welcome as already shown
178+
self._mark_welcome_as_shown()
157179

158180
left_margin = " " * 15
159181
print(f"\n\n{left_margin} Cat REST API: {cat_address}/docs")
160182
print(f"{left_margin} Cat ADMIN: {cat_address}/admin\n\n")
161183

162-
# self.log_examples()
163-
164-
165184
def log_examples(self):
166185
"""Log examples for the log engine."""
167186

@@ -182,4 +201,4 @@ def intentional_error():
182201

183202

184203
# logger instance
185-
log = CatLogEngine()
204+
log = CatLogEngine()

0 commit comments

Comments
 (0)