102 lines
3.0 KiB
Python
102 lines
3.0 KiB
Python
from __future__ import annotations
|
|
|
|
import os
|
|
from pathlib import Path
|
|
from typing import Sequence
|
|
|
|
from acupedia_ops.bootstrap.api_cli import run_api_bootstrap
|
|
from acupedia_ops.local.workspace import LocalWorkspace
|
|
|
|
|
|
def _require(path: Path | None, description: str) -> Path:
|
|
if path is None:
|
|
raise RuntimeError(f"{description} is not configured")
|
|
if not path.exists():
|
|
raise FileNotFoundError(f"{description} not found: {path}")
|
|
return path
|
|
|
|
|
|
def build_local_bootstrap_args(
|
|
workspace: LocalWorkspace,
|
|
target: str,
|
|
*,
|
|
publish_content: bool = False,
|
|
) -> list[str]:
|
|
defaults = workspace.bootstrap
|
|
|
|
if target == "content":
|
|
config = _require(defaults.content_config, "Content config")
|
|
modules_root = _require(defaults.modules_root, "Content modules root")
|
|
args = [
|
|
"--config",
|
|
str(config),
|
|
"--modules-root",
|
|
str(modules_root),
|
|
]
|
|
if publish_content:
|
|
args.append("--publish-content")
|
|
return args
|
|
|
|
if target == "media":
|
|
manifest = _require(defaults.media_manifest, "Media manifest")
|
|
media_root = _require(defaults.media_root, "Media root")
|
|
return [
|
|
"--manifest",
|
|
str(manifest),
|
|
"--media-root",
|
|
str(media_root),
|
|
]
|
|
|
|
if target == "commerce":
|
|
if defaults.commerce_plans is None:
|
|
return []
|
|
plans = _require(defaults.commerce_plans, "Commerce plans")
|
|
return ["--plans", str(plans)]
|
|
|
|
if target == "all":
|
|
config = _require(defaults.content_config, "Content config")
|
|
modules_root = _require(defaults.modules_root, "Content modules root")
|
|
manifest = _require(defaults.media_manifest, "Media manifest")
|
|
media_root = _require(defaults.media_root, "Media root")
|
|
args = [
|
|
"--content-config",
|
|
str(config),
|
|
"--content-modules-root",
|
|
str(modules_root),
|
|
"--media-manifest",
|
|
str(manifest),
|
|
"--media-media-root",
|
|
str(media_root),
|
|
]
|
|
if defaults.commerce_plans is not None:
|
|
plans = _require(defaults.commerce_plans, "Commerce plans")
|
|
args.extend(["--commerce-plans", str(plans)])
|
|
if publish_content:
|
|
args.append("--content-publish-content")
|
|
return args
|
|
|
|
if target in {"auth", "validate"}:
|
|
return []
|
|
|
|
raise ValueError(f"Unsupported local bootstrap target: {target}")
|
|
|
|
|
|
def local_bootstrap(
|
|
workspace: LocalWorkspace,
|
|
*,
|
|
target: str | None = None,
|
|
publish_content: bool = False,
|
|
extra_args: Sequence[str] = (),
|
|
) -> None:
|
|
selected = target or workspace.bootstrap.default_target
|
|
generated_args = build_local_bootstrap_args(
|
|
workspace,
|
|
selected,
|
|
publish_content=publish_content,
|
|
)
|
|
run_api_bootstrap(
|
|
target=selected,
|
|
api_root=workspace.path("api"),
|
|
extra_args=[*generated_args, *extra_args],
|
|
)
|