diff --git a/devine/commands/env.py b/devine/commands/env.py index d098c5c8..20d64c8b 100644 --- a/devine/commands/env.py +++ b/devine/commands/env.py @@ -14,12 +14,51 @@ from devine.core.console import console from devine.core.constants import context_settings from devine.core.services import Services +from devine.core.utils.osenvironment import get_os_arch @click.group(short_help="Manage and configure the project environment.", context_settings=context_settings) def env() -> None: """Manage and configure the project environment.""" +@env.command() +def check() -> None: + """Checks environment for the required dependencies.""" + table = Table(title="Dependencies", expand=True) + table.add_column("Name", no_wrap=True) + table.add_column("Installed", justify="center") + table.add_column("Path", no_wrap=False, overflow="fold") + + # builds shaka-packager based on os, arch + packager_dep = get_os_arch("packager") + + dependencies = [ + {"name": "CCExtractor", "binary": "ccextractor"}, + {"name": "FFMpeg", "binary": "ffmpeg"}, + {"name": "MKVToolNix", "binary": "mkvmerge"}, + {"name": "Shaka-Packager", "binary": packager_dep}, + {"name": "Aria2(c)", "binary": "aria2c"} + ] + + for dep in dependencies: + path = shutil.which(dep["binary"]) + + if path: + installed = "[green]:heavy_check_mark:[/green]" + path_output = path.lower() + else: + installed = "[red]:x:[/red]" + path_output = "Not Found" + + # Add to the table + table.add_row(dep["name"], installed, path_output) + + # Replace spinner with the result + console.clear() + console.print(Padding( + table, + (1, 5) + )) @env.command() def info() -> None: @@ -39,7 +78,7 @@ def info() -> None: table = Table(title="Directories", expand=True) table.add_column("Name", no_wrap=True) - table.add_column("Path") + table.add_column("Path", no_wrap=False, overflow="fold") path_vars = { x: Path(os.getenv(x)) diff --git a/devine/core/utils/osenvironment.py b/devine/core/utils/osenvironment.py new file mode 100644 index 00000000..40b3eccc --- /dev/null +++ b/devine/core/utils/osenvironment.py @@ -0,0 +1,24 @@ +import platform + + +def get_os_arch(name: str) -> str: + """Builds a name-os-arch based on the input name, system, architecture.""" + os_name = platform.system().lower() + os_arch = platform.machine().lower() + + # Map platform.system() output to desired OS name + if os_name == "windows": + os_name = "win" + elif os_name == "darwin": + os_name = "osx" + else: + os_name = "linux" + + # Map platform.machine() output to desired architecture + if os_arch in ["x86_64", "amd64"]: + os_arch = "x64" + elif os_arch == "arm64": + os_arch = "arm64" + + # Construct the dependency name in the desired format using the input name + return f"{name}-{os_name}-{os_arch}"