-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
147 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from rich.style import Style | ||
from rich.table import Table | ||
from textual.app import ComposeResult | ||
from textual.containers import Container | ||
from textual.widgets import Static | ||
|
||
from service_locator import ServiceLocator | ||
|
||
|
||
class SystemCard(Container): | ||
DEFAULT_CSS = """ | ||
SystemCard { | ||
height: auto; | ||
width: 45; | ||
border: $primary-background round; | ||
} | ||
""" | ||
|
||
def __init__(self, **kwargs): | ||
super().__init__(**kwargs) | ||
self._system_panel = Static(id="system_panel") | ||
|
||
def compose(self) -> ComposeResult: | ||
yield self._system_panel | ||
|
||
def on_mount(self) -> None: | ||
table = Table( | ||
show_header=False, | ||
box=None, | ||
title="System status", | ||
title_style=Style(color="#bbc8e8", bold=True), | ||
) | ||
table.add_column() | ||
table.add_column(min_width=25, max_width=27) | ||
system_status = ServiceLocator.system_status() | ||
self._add_system_row(table, "Php", system_status.php_version()) | ||
self._add_system_row(table, "Composer", system_status.composer_version()) | ||
self._add_system_row(table, "Symfony-Cli", system_status.symfony_version()) | ||
self._add_system_row(table, "Castor", system_status.castor_version()) | ||
self._add_system_row(table, "Docker", system_status.docker_version()) | ||
self._add_system_row(table, "Ansible", system_status.ansible_version()) | ||
|
||
self._system_panel.update(table) | ||
|
||
@staticmethod | ||
def _add_system_row(table: Table, label: str, version: str|None) -> None: | ||
table.add_row( | ||
f"[label]{label}:", | ||
f"[blue]{version}" if version is not None else "[orange1]N/A", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,12 @@ | ||
from dependency_injector import containers, providers | ||
|
||
from models.app_context import AppContext | ||
from services import DockerClient, ComposerClient | ||
from services import DockerClient, ComposerClient, SystemStatus | ||
|
||
|
||
class ServiceContainer(containers.DeclarativeContainer): | ||
class ServiceLocator(containers.DeclarativeContainer): | ||
config = providers.Configuration() | ||
docker_client = providers.Singleton(DockerClient) | ||
context = providers.Singleton(AppContext) | ||
composer_client = providers.Singleton(ComposerClient, context=context) | ||
# project = providers.Factory(Project) | ||
|
||
# api_client = providers.Singleton( | ||
# ApiClient, | ||
# api_key=config.api_key, | ||
# timeout=config.timeout, | ||
# ) | ||
# | ||
# service = providers.Factory( | ||
# Service, | ||
# api_client=api_client, | ||
# ) | ||
system_status = providers.Singleton(SystemStatus) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from .docker_client import DockerClient | ||
from .composer_client import ComposerClient | ||
from .system_status import SystemStatus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import subprocess | ||
|
||
from .base_service import BaseService | ||
|
||
class SystemStatus(BaseService): | ||
def _capture_output(self, command: list[str]) -> str|None: | ||
try: | ||
result = subprocess.run(command, capture_output=True, text=True, check=True) | ||
return result.stdout | ||
except (subprocess.CalledProcessError, FileNotFoundError): | ||
return None | ||
|
||
def php_version(self) -> str|None: | ||
output = self._capture_output(['php', '-v']) | ||
if output is None: | ||
return None | ||
version_line = output.splitlines()[0] | ||
version = version_line.split()[1] | ||
return version | ||
def composer_version(self) -> str|None: | ||
output = self._capture_output(['composer', '--version']) | ||
if output is None: | ||
return None | ||
|
||
version_line = output.splitlines()[0] | ||
version = version_line.split()[2] | ||
return version | ||
|
||
def castor_version(self) -> str|None: | ||
output = self._capture_output(['castor', '--version']) | ||
if output is None: | ||
return None | ||
|
||
version_line = output.splitlines()[0] | ||
version = version_line.split()[1] | ||
return version[1:] | ||
|
||
def symfony_version(self) -> str|None: | ||
output = self._capture_output(['symfony', 'version', '--no-ansi']) | ||
if output is None: | ||
return None | ||
|
||
version_line = output.splitlines()[0] | ||
version = version_line.split()[3] | ||
return version | ||
|
||
def docker_version(self) -> str|None: | ||
output = self._capture_output(['docker', '-v']) | ||
if output is None: | ||
return None | ||
|
||
version_line = output.splitlines()[0] | ||
version = version_line.split()[2] | ||
return version[:-1] | ||
|
||
def ansible_version(self) -> str|None: | ||
output = self._capture_output(['ansible', '--version']) | ||
if output is None: | ||
return None | ||
|
||
version_line = output.splitlines()[0] | ||
version = version_line.split()[2] | ||
return version[:-1] |