From 47a21aa6d9fe553f0512a406d14a9a2b23df4397 Mon Sep 17 00:00:00 2001 From: Olivier Navas Date: Fri, 25 Oct 2024 18:24:33 +0200 Subject: [PATCH] =?UTF-8?q?D=C3=A9placement=20de=20la=20fonction=20status?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- linuxinstaller/PythonActions.py | 28 ++++++++++++++++++++++++++++ linuxinstaller/linuxinstaller.py | 26 +------------------------- 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/linuxinstaller/PythonActions.py b/linuxinstaller/PythonActions.py index 65e5838..bf0173b 100644 --- a/linuxinstaller/PythonActions.py +++ b/linuxinstaller/PythonActions.py @@ -1,5 +1,8 @@ import socket import subprocess +import GitActions +from rich.console import Console +from rich.table import Table def getHostName(): return socket.gethostname() @@ -11,3 +14,28 @@ def getDomain(): def setFQDN(fqdn): result = subprocess.run(['hostnamectl', 'hostname', fqdn], check=True) return result.returncode == 0 + + +### Cartouche de status + +def print_status(): + # Récupération des infos + hostname = getHostName() + domain = getDomain() + currentBranch = GitActions.getBranch() + + # Affichage du statut + console = Console() + console.print() + console.print("=== Menu de configuration Libretic ===", style="bold red") + console.print() + table = Table(show_header=True, header_style="bold dim") + table.add_column("Paramètre", style="bold magenta") + table.add_column("Valeur") + table.add_column("Statut", justify="center") + table.add_row("Environnement du poste", currentBranch, "[green]OK" if currentBranch == "main" else "[yellow]Attention") + table.add_row("Hostname", hostname, "[green]OK" if hostname != "unassigned-hostname" else "[red]KO") + console.print(table) + console.print() + + diff --git a/linuxinstaller/linuxinstaller.py b/linuxinstaller/linuxinstaller.py index cff83c4..068f5e2 100644 --- a/linuxinstaller/linuxinstaller.py +++ b/linuxinstaller/linuxinstaller.py @@ -1,7 +1,6 @@ from InquirerPy import inquirer from InquirerPy import prompt from rich.console import Console -from rich.table import Table import AnsibleActions import PythonActions import GitActions @@ -11,29 +10,6 @@ import syslog import os -### Cartouche de status - -def print_status(): - # Récupération des infos - hostname = PythonActions.getHostName() - domain = PythonActions.getDomain() - currentBranch = GitActions.getBranch() - - # Affichage du statut - console = Console() - console.print() - console.print("=== Menu de configuration Libretic ===", style="bold red") - console.print() - table = Table(show_header=True, header_style="bold dim") - table.add_column("Paramètre", style="bold magenta") - table.add_column("Valeur") - table.add_column("Statut", justify="center") - table.add_row("Environnement du poste", currentBranch, "[green]OK" if currentBranch == "main" else "[yellow]Attention") - table.add_row("Hostname", hostname, "[green]OK" if hostname != "unassigned-hostname" else "[red]KO") - console.print(table) - console.print() - - # Chargement du fichier de configuration def readConfig(configFile): try: @@ -172,7 +148,7 @@ def main(): while not cmdlineOptionPassed: - print_status() + PythonActions.print_status() console = Console() console.print("Choisir une des options suivantes", style="bold blue") action = inquirer.select(