976398d1f2
- Introduce 'astrbot bk' command with GPG signing, encryption, and digest support - Add import/export functionality using core backup modules - Refactor path management to use 'AstrbotPaths' singleton across CLI commands - Replace blocking subprocess calls with asyncio.create_subprocess_exec in backup command - Add comprehensive tests for uninstall and backup commands - Improve module resource handling for bundled dashboard assets
92 lines
3.4 KiB
Python
92 lines
3.4 KiB
Python
from importlib import resources
|
||
from pathlib import Path
|
||
|
||
import click
|
||
|
||
from astrbot.core.utils.astrbot_path import astrbot_paths
|
||
|
||
# Static assets bundled inside the installed wheel (built by hatch_build.py).
|
||
# _BUNDLED_DIST = Path(__file__).parent.parent.parent / "dashboard" / "dist"
|
||
_BUNDLED_DIST = resources.files("astrbot") / "dashboard" / "dist"
|
||
|
||
|
||
def check_astrbot_root(path: str | Path) -> bool:
|
||
"""Check if the path is an AstrBot root directory"""
|
||
if not isinstance(path, Path):
|
||
path = Path(path)
|
||
if not path.exists() or not path.is_dir():
|
||
return False
|
||
if not (path / ".astrbot").exists():
|
||
return False
|
||
return True
|
||
|
||
|
||
def get_astrbot_root() -> Path:
|
||
"""Get the AstrBot root directory path"""
|
||
return astrbot_paths.root
|
||
|
||
|
||
async def check_dashboard(astrbot_root: Path) -> None:
|
||
"""Check if the dashboard is installed"""
|
||
from astrbot.core.config.default import VERSION
|
||
from astrbot.core.utils.io import download_dashboard, get_dashboard_version
|
||
|
||
from .version_comparator import VersionComparator
|
||
|
||
# If the wheel ships bundled dashboard assets, no network download is needed.
|
||
if _BUNDLED_DIST.is_dir():
|
||
click.echo("Dashboard is bundled with the package – skipping download.")
|
||
return
|
||
|
||
try:
|
||
dashboard_version = await get_dashboard_version()
|
||
match dashboard_version:
|
||
case None:
|
||
click.echo("Dashboard is not installed")
|
||
if click.confirm(
|
||
"Install dashboard?",
|
||
default=True,
|
||
abort=True,
|
||
):
|
||
click.echo("Installing dashboard...")
|
||
try:
|
||
await download_dashboard(
|
||
path="data/dashboard.zip",
|
||
extract_path=str(astrbot_root / "data"),
|
||
version=f"v{VERSION}",
|
||
latest=False,
|
||
)
|
||
click.echo("Dashboard installed successfully")
|
||
except Exception as e:
|
||
click.echo(f"Failed to install dashboard: {e}")
|
||
|
||
case str():
|
||
if VersionComparator.compare_version(VERSION, dashboard_version) <= 0:
|
||
click.echo("Dashboard is already up to date")
|
||
return
|
||
try:
|
||
version = dashboard_version.split("v")[1]
|
||
click.echo(f"Dashboard version: {version}")
|
||
await download_dashboard(
|
||
path="data/dashboard.zip",
|
||
extract_path=str(astrbot_root / "data"),
|
||
version=f"v{VERSION}",
|
||
latest=False,
|
||
)
|
||
except Exception as e:
|
||
click.echo(f"Failed to download dashboard: {e}")
|
||
return
|
||
except FileNotFoundError:
|
||
click.echo("Initializing dashboard directory...")
|
||
try:
|
||
await download_dashboard(
|
||
path=str(astrbot_root / "data" / "dashboard.zip"),
|
||
extract_path=str(astrbot_root / "data"),
|
||
version=f"v{VERSION}",
|
||
latest=False,
|
||
)
|
||
click.echo("Dashboard initialized successfully")
|
||
except Exception as e:
|
||
click.echo(f"Failed to download dashboard: {e}")
|
||
return
|