From 66342eecef3ba02f9c0868440b258119d809ab7c Mon Sep 17 00:00:00 2001 From: Lucas Date: Fri, 3 Jul 2026 17:30:48 +0200 Subject: [PATCH 1/4] feat!: add reference to start and init command --- ctOS.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/ctOS.py b/ctOS.py index b41f4f4..35c378b 100644 --- a/ctOS.py +++ b/ctOS.py @@ -1,10 +1,10 @@ -from test import demo +from src.start.init import demo from src.start.start import start from src.help import help import sys from dotenv import load_dotenv from src.music.music import music_command - +from src.music.init_token import init load_dotenv() def main(): @@ -16,11 +16,15 @@ def main(): if sys.argv[1] == "--music": music_command() return - if sys.argv[1] == "--help" or "-h": - help() - if sys.argv[1] == "hello": + if sys.argv[1] == "--init": + init() + return + if sys.argv[1] == "--start": demo() start() + return + if sys.argv[1] == "--help" or "-h": + help() else: return 84 main() \ No newline at end of file From d6164a4c963ac143634b01553fcaef0a86c5d0fb Mon Sep 17 00:00:00 2001 From: Lucas Date: Fri, 3 Jul 2026 17:31:18 +0200 Subject: [PATCH 2/4] feat!: change name test for init.py --- src/start/init.py | 126 ++++++++++++++++++++++++++++++++++++++++++++++ test.py | 86 ------------------------------- 2 files changed, 126 insertions(+), 86 deletions(-) create mode 100644 src/start/init.py delete mode 100644 test.py diff --git a/src/start/init.py b/src/start/init.py new file mode 100644 index 0000000..f726914 --- /dev/null +++ b/src/start/init.py @@ -0,0 +1,126 @@ +#!/usr/bin/env python3 +import time +import random +from collections import deque +from rich.console import Console +from rich.layout import Layout +from rich.live import Live +from rich.text import Text +from rich.align import Align +from rich.panel import Panel +from pathlib import Path +import os +from dotenv import load_dotenv + +load_dotenv() + +console = Console() +GREEN = "bold spring_green2" +DIM_GREEN = "spring_green4" + +BOOT_LINES = [ + "[INIT] Check env is created", + "[OK ] Env check", + "[INIT] Check env variable", + "[OK ] Variable good", + "[INIT] Check spotify section", + "[OK ] Token is good", + "[INIT] Check other command", + "[OK ] Other command good", + "[INIT] Start cli...", +] + +SPACE_LINE = [ + " " +] + +WAITING_LINE = [ + "." + ".." + "..." +] + +START_LINE = [ + "Hello from ctOS" +] + +ERROR_LINE = "Error detected. First time to use ? Use ctOS --init" + +def make_layout() -> Layout: + layout = Layout() + layout.split_column( + Layout(name="main", ratio=2), + Layout(name="bottom", size=9), + ) + layout["bottom"].split_row( + Layout(name="bottom_left"), + ) + return layout + +def render_center(percent: int, width: int = 40) -> Align: + filled = int(width * percent / 100) + empty = width - filled + bar_str = "█" * filled + "░" * empty + text = Text(f"{bar_str} {percent:3d}%", style=GREEN, justify="center") + return Align.center(text, vertical="middle") + +def render_status(history: deque) -> Panel: + body = Text("\n".join(history), style=DIM_GREEN) + return Panel(body, border_style=DIM_GREEN) + +def check_file_env(): + p = Path(".env") + if p.exists(): + return 0 + else: + return 84 + +def check_token(): + p = Path("src/music/.spotify_token.json") + if p.exists(): + return 0 + else: + return 84 + +def check_variable(): + token_public = os.getenv("TOKEN_PUBLIC") + token_private = os.getenv("TOKEN_PRIVATE") + if not token_public or not token_private: + return 84 + else: + return 0 + +STEPS = [ + ("[INIT] Check env is created", None), + ("[OK ] Env check", check_file_env), + ("[INIT] Check env variable", None), + ("[OK ] Variable good", check_variable), + ("[INIT] Check spotify section", None), + ("[OK ] Token is good", check_token), + ("[INIT] Check other command", None), + ("[OK ] Other command good", None), + ("[INIT] Start cli...", None), +] + +def demo(): + layout = make_layout() + history = deque(maxlen=6) + + with Live(layout, console=console, refresh_per_second=20, screen=True): + for i, (label, check) in enumerate(STEPS): + history.append(label) + + if check is not None: + r = check() + if r == 84: + history.append(ERROR_LINE) + time.sleep(2) + return 84 + + percent = ((i + 1) * 100) // len(STEPS) + layout["main"].update(render_center(percent)) + layout["bottom_left"].update(render_status(history)) + time.sleep(1) + +if __name__ == "__main__": + demo() \ No newline at end of file diff --git a/test.py b/test.py deleted file mode 100644 index 55c804b..0000000 --- a/test.py +++ /dev/null @@ -1,86 +0,0 @@ -#!/usr/bin/env python3 -import time -import random -from collections import deque -from rich.console import Console -from rich.layout import Layout -from rich.live import Live -from rich.text import Text -from rich.align import Align -from rich.panel import Panel - -console = Console() -GREEN = "bold spring_green2" -DIM_GREEN = "spring_green4" - -BOOT_LINES = [ - "[INIT] Loading all module...", - "[NET ] Establishing uplink to backbone...", - "[OK ] All systems are onlines.", -] - -SPACE_LINE = [ - " " -] - -WAITING_LINE = [ - "." - ".." - "..." -] - -START_LINE = [ - "Hello from cpOS" -] - -def make_layout() -> Layout: - layout = Layout() - layout.split_column( - Layout(name="main", ratio=2), - Layout(name="bottom", size=9), - ) - layout["bottom"].split_row( - Layout(name="bottom_left"), - ) - return layout - -def render_center(percent: int, width: int = 40) -> Align: - filled = int(width * percent / 100) - empty = width - filled - bar_str = "█" * filled + "░" * empty - text = Text(f"{bar_str} {percent:3d}%", style=GREEN, justify="center") - return Align.center(text, vertical="middle") - -def render_status(history: deque) -> Panel: - body = Text("\n".join(history), style=DIM_GREEN) - return Panel(body, border_style=DIM_GREEN) - -def demo(): - layout = make_layout() - history = deque(maxlen=6) - messages = BOOT_LINES - start = START_LINE - wait = WAITING_LINE - nb_task = 0 - i = 0 - is_finish = False - - - with Live(layout, console=console, refresh_per_second=20, screen=True): - while is_finish is False: - i = i + 1 - percent = (i * 100 // 59) - layout["main"].update(render_center(percent)) - - if i % 5 == 0: - history.append(random.choice(messages) + f" {random.randint(0,99)}%") - nb_task = nb_task + 1 - layout["bottom_left"].update(render_status(history)) - - if (percent >= 100): - is_finish = True - time.sleep(0.08) - - -if __name__ == "__main__": - demo() \ No newline at end of file From fd500303c1e943595a4b7d014a900ae8fafbc671 Mon Sep 17 00:00:00 2001 From: Lucas Date: Fri, 3 Jul 2026 17:31:45 +0200 Subject: [PATCH 3/4] feat!: add init command --- src/music/init_token.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/music/init_token.py diff --git a/src/music/init_token.py b/src/music/init_token.py new file mode 100644 index 0000000..4afeb92 --- /dev/null +++ b/src/music/init_token.py @@ -0,0 +1,27 @@ +import os +from pathlib import Path +from src.music.get_token_tmp import get_token +import time + +PATH_TOKEN = "src/music/.spotify_token.json" + +def init(): + p = Path(".env") + if not p.exists(): + print("Pas de .env detecter. Veuillez en créer un") + return 84 + + token_public = os.getenv("TOKEN_PUBLIC") + token_private = os.getenv("TOKEN_PRIVATE") + if not token_public or not token_private: + print("Pas de token detecter. Veuillez vous referer a la doc pour pouvoir en obtenir") + time.sleep(2) + return 84 + + p = Path(PATH_TOKEN) + if not p.exists(): + print("Premier utilisation detecter. Redirection vers la connection spotify") + time.sleep(2) + get_token() + print("Tous est désormais initialisé. Veuillez faire ctOS --start") + time.sleep(2) \ No newline at end of file From ef7ae24f3163b600250beecc6df3bccfd8c7f1fb Mon Sep 17 00:00:00 2001 From: Lucas Date: Fri, 3 Jul 2026 17:32:27 +0200 Subject: [PATCH 4/4] fix: rm useless line and not use --- src/start/start.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/start/start.py b/src/start/start.py index 3bcf457..a51e02d 100644 --- a/src/start/start.py +++ b/src/start/start.py @@ -10,8 +10,6 @@ from rich.align import Align from rich.panel import Panel -from test import demo - console = Console() GREEN = "bold spring_green2" DIM_GREEN = "spring_green4" @@ -33,7 +31,7 @@ ] START_LINE = [ - "Hello from cpOS" + "Hello from ctOS" ] def make_layout() -> Layout: