Skip to content

Commit

Permalink
Check command with rich support (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
Skazza94 committed Jan 30, 2024
1 parent 0a93c98 commit 8df8342
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions src/Kathara/cli/command/CheckCommand.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import argparse
import logging
import os
import platform
import sys
from typing import List

from rich.console import Console

from ..ui.utils import create_panel
from ... import utils
from ... import version
from ...foundation.cli.command.Command import Command
Expand Down Expand Up @@ -35,10 +37,12 @@ def __init__(self) -> None:
def run(self, current_path: str, argv: List[str]) -> None:
self.parse_args(argv)

print(f"*\tCurrent Manager is: {Kathara.get_instance().get_formatted_manager_name()}")
print(f"*\tManager version is: {Kathara.get_instance().get_release_version()}")
print("*\tPython version is: %s" % sys.version.replace("\n", "- "))
print(f"*\tKathara version is: {version.CURRENT_VERSION}")
console = Console()
console.print(create_panel("System Check", style="blue bold", justify="center"))
console.print(f"Current Manager is:\t\t[cyan bold]{Kathara.get_instance().get_formatted_manager_name()}")
console.print(f"Manager version is:\t\t[cyan bold]{Kathara.get_instance().get_release_version()}")
console.print("Python version is:\t\t[cyan bold]%s" % sys.version.replace("\n", "- "))
console.print(f"Kathara version is:\t\t[cyan bold]{version.CURRENT_VERSION}")

def linux_platform_info():
info = os.uname()
Expand All @@ -47,18 +51,21 @@ def linux_platform_info():
platform_info = utils.exec_by_platform(
linux_platform_info, lambda: platform.platform(), lambda: platform.platform()
)
print(f"*\tOperating System version is: {str(platform_info)}")
console.print(f"Operating System version is:\t[cyan bold]{str(platform_info)}")

print(f"*\tTrying to run container with `{Setting.get_instance().image}` image...")
Setting.get_instance().open_terminals = False
with console.status(
f"Trying to run container with `{Setting.get_instance().image}` image...",
spinner="dots"
) as status:
Setting.get_instance().open_terminals = False

lab = Lab("kathara_test")
lab.add_option('hosthome_mount', False)
lab = Lab("kathara_test")
lab.add_option('hosthome_mount', False)

machine = lab.get_or_new_machine("hello_world")
try:
Kathara.get_instance().deploy_machine(machine)
print("*\tContainer run successfully.")
Kathara.get_instance().undeploy_machine(machine)
except Exception as e:
logging.exception(f"\t! Running container failed: {str(e)}")
machine = lab.get_or_new_machine("hello_world")
try:
Kathara.get_instance().deploy_machine(machine)
Kathara.get_instance().undeploy_machine(machine)
console.print("[bold green]\u2713 Container run successfully.")
except Exception as e:
console.print(f"[bold red]\u00d7 Running container failed: {str(e)}")

0 comments on commit 8df8342

Please sign in to comment.