spcd/spcd/cmd.py
2024-09-17 12:20:02 +02:00

58 lines
1.3 KiB
Python

"""Commands available for workflows."""
import os
from pathlib import Path
from rwx import ps
from spcd.ci import project, projects
from spcd.shell import env
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 = project.root / f"build.{extension}"
if path.exists():
ps.run(str(path))
break
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.
:param target: where to deploy to
:type target: str | None
:param source: where to deploy from
:type source: str | None
"""
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}/",
)