spcd/spcd/cmd.py
2024-08-19 17:44:07 +02:00

54 lines
1.2 KiB
Python

"""Commands available for workflows."""
import os
from pathlib import Path
import env
from rwx import ps
from spcd.ci import project, projects
from spcd.util import browse
def spcd_browse_workspace() -> None:
"""Browse the current workspace for the project."""
browse(project.root)
def spcd_build_project() -> None:
"""Perform the actual building process."""
for extension in ["py", "sh"]:
path = Path(project.root) / f"build.{extension}"
if path.exists():
ps.run(path)
break
else:
pass
def spcd_check_project() -> None:
"""Check the project for anything wrong."""
ps.run("ruff", "check")
def spcd_synchronize(
target: str | None = None, source: str | None = None
) -> None:
"""Synchronize output towards a target."""
if not target:
user = "cd"
host = env.SPCD_PROJECT_PATH
root = (
Path(os.sep) / user / project.branch / projects.group / project.name
)
target = f"{user}@{host}:{root}"
if not source:
source = "out"
ps.run(
"rsync",
"--archive",
"--delete-before",
"--verbose",
f"{source}/",
f"{target}/",
)