105 lines
2.9 KiB
Python
105 lines
2.9 KiB
Python
from __future__ import annotations
|
|
|
|
"""Validate the BeeOS project tree.
|
|
|
|
Checks:
|
|
- Python syntax
|
|
- JSON syntax
|
|
- HiveStore source loading
|
|
- package manifest loading
|
|
- generated asset indexes
|
|
"""
|
|
|
|
import argparse
|
|
import json
|
|
import py_compile
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
|
|
def fail(message: str) -> None:
|
|
raise RuntimeError(message)
|
|
|
|
|
|
def check_python(project_root: Path) -> int:
|
|
count = 0
|
|
for py_file in project_root.rglob("*.py"):
|
|
if "__pycache__" in py_file.parts:
|
|
continue
|
|
py_compile.compile(str(py_file), doraise=True)
|
|
count += 1
|
|
return count
|
|
|
|
|
|
def check_json(project_root: Path) -> int:
|
|
count = 0
|
|
for json_file in project_root.rglob("*.json"):
|
|
json.loads(json_file.read_text(encoding="utf-8"))
|
|
count += 1
|
|
return count
|
|
|
|
|
|
def check_hivestore(project_root: Path) -> tuple[int, int]:
|
|
if str(project_root) not in sys.path:
|
|
sys.path.insert(0, str(project_root))
|
|
|
|
from beeos.core.hivestore import HiveStoreIndex
|
|
|
|
index = HiveStoreIndex(project_root / "beeos" / "data" / "hivestore_index.json")
|
|
index.load()
|
|
|
|
if not index.source_manager.sources:
|
|
fail("No HiveStore sources configured.")
|
|
|
|
if not index.listings:
|
|
fail("HiveStore loaded zero package listings.")
|
|
|
|
return len(index.source_manager.sources), len(index.listings)
|
|
|
|
|
|
def check_generated_assets(project_root: Path) -> dict:
|
|
icon_index = project_root / "beeos" / "generated" / "icons" / "icon_build_index.json"
|
|
theme_index = project_root / "beeos" / "generated" / "themes" / "theme_build_index.json"
|
|
|
|
result = {
|
|
"icon_index": icon_index.exists(),
|
|
"theme_index": theme_index.exists(),
|
|
"icon_count": 0,
|
|
"theme_count": 0,
|
|
}
|
|
|
|
if icon_index.exists():
|
|
data = json.loads(icon_index.read_text(encoding="utf-8"))
|
|
result["icon_count"] = int(data.get("icon_count", 0))
|
|
|
|
if theme_index.exists():
|
|
data = json.loads(theme_index.read_text(encoding="utf-8"))
|
|
result["theme_count"] = int(data.get("theme_count", 0))
|
|
|
|
return result
|
|
|
|
|
|
def main() -> None:
|
|
parser = argparse.ArgumentParser(description="Validate the BeeOS project.")
|
|
parser.add_argument("--project-root", default=".", help="BeeOS project root")
|
|
args = parser.parse_args()
|
|
|
|
project_root = Path(args.project_root).resolve()
|
|
|
|
python_count = check_python(project_root)
|
|
json_count = check_json(project_root)
|
|
source_count, listing_count = check_hivestore(project_root)
|
|
assets = check_generated_assets(project_root)
|
|
|
|
print("BeeOS validation passed.")
|
|
print(f"Python files: {python_count}")
|
|
print(f"JSON files: {json_count}")
|
|
print(f"HiveStore sources: {source_count}")
|
|
print(f"HiveStore listings: {listing_count}")
|
|
print(f"Generated icons: {assets['icon_count']}")
|
|
print(f"Generated themes: {assets['theme_count']}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|