clarity.tools.tool_manager
1# coding=utf-8 2import os 3import sys 4import shutil 5from time import sleep 6from platform import system 7from clarity.core import ClarityTool, ClarityToolsCollection, Colors, expand_path, rm_rf, ensure_dir 8 9class UpdateTool(ClarityTool): 10 TITLE = "Update Clarity-Tool" 11 DESCRIPTION = "Mettre à jour Clarity-Tool depuis GitHub (git requis)" 12 13 def __init__(self): 14 super().__init__([('Update', self.update)], installable=False, runnable=False) 15 16 def update(self): 17 print(f"{Colors.CYAN}Mise à jour de Clarity-Tool…{Colors.RESET}\n") 18 sleep(0.5) 19 # clone dans un dossier temporaire puis swap si OK 20 tmp_dir = expand_path("./_clarity_update_tmp") 21 rm_rf(tmp_dir) 22 code = os.system("git --version >nul 2>&1" if os.name == 'nt' else "git --version >/dev/null 2>&1") 23 if code != 0: 24 print(f"{Colors.RED}Git n'est pas installé ou indisponible dans le PATH.{Colors.RESET}") 25 return 26 code = os.system(f"git clone https://github.com/alextoutcourt72/clarity-tool.git \"{tmp_dir}\"") 27 if code != 0: 28 print(f"{Colors.RED}Échec du clone. Vérifie ta connexion ou l'URL.{Colors.RESET}") 29 return 30 # Move over or instruct user; ici on propose juste 31 print(f"{Colors.GREEN}Mise à jour téléchargée dans {tmp_dir}.{Colors.RESET}") 32 print(f"{Colors.GRAY}Copie les fichiers voulus depuis ce dossier vers ton installation si nécessaire.{Colors.RESET}") 33 return 0 34 35class UninstallTool(ClarityTool): 36 TITLE = "Uninstall Clarity-Tool" 37 DESCRIPTION = "Désinstaller Clarity-Tool de ce système" 38 39 def __init__(self): 40 super().__init__([('Uninstall', self.uninstall)], installable=False, runnable=False) 41 42 def uninstall(self): 43 print(f"{Colors.YELLOW}Désinstallation de Clarity-Tool.{Colors.RESET}") 44 path = expand_path("~/.clarity-tool") if system() != "Windows" else expand_path(r"~\Clarity-Tool") 45 custom = input(f"Chemin d'installation détecté ({path}). Appuie sur Entrée pour confirmer ou saisis un autre chemin: ").strip() 46 if custom: 47 path = expand_path(custom) 48 49 confirm = input(f"Supprimer définitivement '{path}' ? (y/N) ").strip().lower() 50 if confirm != "y": 51 print("Désinstallation annulée.") 52 return 53 54 try: 55 rm_rf(path) 56 print(f"{Colors.GREEN}Clarity-Tool supprimé: {path}{Colors.RESET}") 57 except Exception as e: 58 print(f"{Colors.RED}Échec de suppression: {e}{Colors.RESET}") 59 return 1 60 return 0 61 62class ToolManager(ClarityToolsCollection): 63 TITLE = "Uninstall or Update | Clarity-Tool" 64 TOOLS = [UninstallTool(), UpdateTool()] 65 66if __name__ == "__main__": 67 ToolManager().show_options()
10class UpdateTool(ClarityTool): 11 TITLE = "Update Clarity-Tool" 12 DESCRIPTION = "Mettre à jour Clarity-Tool depuis GitHub (git requis)" 13 14 def __init__(self): 15 super().__init__([('Update', self.update)], installable=False, runnable=False) 16 17 def update(self): 18 print(f"{Colors.CYAN}Mise à jour de Clarity-Tool…{Colors.RESET}\n") 19 sleep(0.5) 20 # clone dans un dossier temporaire puis swap si OK 21 tmp_dir = expand_path("./_clarity_update_tmp") 22 rm_rf(tmp_dir) 23 code = os.system("git --version >nul 2>&1" if os.name == 'nt' else "git --version >/dev/null 2>&1") 24 if code != 0: 25 print(f"{Colors.RED}Git n'est pas installé ou indisponible dans le PATH.{Colors.RESET}") 26 return 27 code = os.system(f"git clone https://github.com/alextoutcourt72/clarity-tool.git \"{tmp_dir}\"") 28 if code != 0: 29 print(f"{Colors.RED}Échec du clone. Vérifie ta connexion ou l'URL.{Colors.RESET}") 30 return 31 # Move over or instruct user; ici on propose juste 32 print(f"{Colors.GREEN}Mise à jour téléchargée dans {tmp_dir}.{Colors.RESET}") 33 print(f"{Colors.GRAY}Copie les fichiers voulus depuis ce dossier vers ton installation si nécessaire.{Colors.RESET}") 34 return 0
def
update(self):
17 def update(self): 18 print(f"{Colors.CYAN}Mise à jour de Clarity-Tool…{Colors.RESET}\n") 19 sleep(0.5) 20 # clone dans un dossier temporaire puis swap si OK 21 tmp_dir = expand_path("./_clarity_update_tmp") 22 rm_rf(tmp_dir) 23 code = os.system("git --version >nul 2>&1" if os.name == 'nt' else "git --version >/dev/null 2>&1") 24 if code != 0: 25 print(f"{Colors.RED}Git n'est pas installé ou indisponible dans le PATH.{Colors.RESET}") 26 return 27 code = os.system(f"git clone https://github.com/alextoutcourt72/clarity-tool.git \"{tmp_dir}\"") 28 if code != 0: 29 print(f"{Colors.RED}Échec du clone. Vérifie ta connexion ou l'URL.{Colors.RESET}") 30 return 31 # Move over or instruct user; ici on propose juste 32 print(f"{Colors.GREEN}Mise à jour téléchargée dans {tmp_dir}.{Colors.RESET}") 33 print(f"{Colors.GRAY}Copie les fichiers voulus depuis ce dossier vers ton installation si nécessaire.{Colors.RESET}") 34 return 0
36class UninstallTool(ClarityTool): 37 TITLE = "Uninstall Clarity-Tool" 38 DESCRIPTION = "Désinstaller Clarity-Tool de ce système" 39 40 def __init__(self): 41 super().__init__([('Uninstall', self.uninstall)], installable=False, runnable=False) 42 43 def uninstall(self): 44 print(f"{Colors.YELLOW}Désinstallation de Clarity-Tool.{Colors.RESET}") 45 path = expand_path("~/.clarity-tool") if system() != "Windows" else expand_path(r"~\Clarity-Tool") 46 custom = input(f"Chemin d'installation détecté ({path}). Appuie sur Entrée pour confirmer ou saisis un autre chemin: ").strip() 47 if custom: 48 path = expand_path(custom) 49 50 confirm = input(f"Supprimer définitivement '{path}' ? (y/N) ").strip().lower() 51 if confirm != "y": 52 print("Désinstallation annulée.") 53 return 54 55 try: 56 rm_rf(path) 57 print(f"{Colors.GREEN}Clarity-Tool supprimé: {path}{Colors.RESET}") 58 except Exception as e: 59 print(f"{Colors.RED}Échec de suppression: {e}{Colors.RESET}") 60 return 1 61 return 0
def
uninstall(self):
43 def uninstall(self): 44 print(f"{Colors.YELLOW}Désinstallation de Clarity-Tool.{Colors.RESET}") 45 path = expand_path("~/.clarity-tool") if system() != "Windows" else expand_path(r"~\Clarity-Tool") 46 custom = input(f"Chemin d'installation détecté ({path}). Appuie sur Entrée pour confirmer ou saisis un autre chemin: ").strip() 47 if custom: 48 path = expand_path(custom) 49 50 confirm = input(f"Supprimer définitivement '{path}' ? (y/N) ").strip().lower() 51 if confirm != "y": 52 print("Désinstallation annulée.") 53 return 54 55 try: 56 rm_rf(path) 57 print(f"{Colors.GREEN}Clarity-Tool supprimé: {path}{Colors.RESET}") 58 except Exception as e: 59 print(f"{Colors.RED}Échec de suppression: {e}{Colors.RESET}") 60 return 1 61 return 0
63class ToolManager(ClarityToolsCollection): 64 TITLE = "Uninstall or Update | Clarity-Tool" 65 TOOLS = [UninstallTool(), UpdateTool()]
TOOLS =
[<UninstallTool object>, <UpdateTool object>]