Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Env Check Dependencies Command #126

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion devine/commands/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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))
Expand Down
24 changes: 24 additions & 0 deletions devine/core/utils/osenvironment.py
Original file line number Diff line number Diff line change
@@ -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}"